此问题已在此处有答案:
fill_between with matplotlib and a where condition of two lists(1个答案)
Matplotlib fill_between edge effect with where
argument(1个答案)
Fill between x and baseline x position in Matplotlib(1个答案)
How to avoid gaps with matplotlib.fill_between and where(1个答案)
关闭1年前。
我正在绘制一条黑体曲线,并想在曲线下填充3到5微米的区域。但是,我不确定如何在这里使用fill_between
或fill_betweenx
plt
命令
import numpy as np
import matplotlib.pyplot as plt
from astropy import units as u
from astropy.modeling import models
from astropy.modeling.models import BlackBody
from astropy.visualization import quantity_support
bb = BlackBody(temperature=308.15*u.K)
wav = np.arange(1.0, 50.0) * u.micron
flux = bb(wav)
with quantity_support():
plt.figure()
plt.plot(wav, flux, lw=4.0)
plt.fill_between(wav,flux, min(flux), color = 'red')
plt.show()
这将在整个曲线下绘制填充,但仅需要填充3- 5微米的部分。x1c 0d1x
1条答案
按热度按时间qpgpyjmq1#
举例说明:
你可以改变5的值,并与它玩,你会很快理解。第一个参数是Y位置,第二个是X位置。
fill_betweenx也是一样的,但它会以相反的方式填充。
edit:如注解中所述,最好使用plt.fill_between(x,x,where =(x>0)&(x<0.2))。两种方法都有效,第二种方法更显式。