Python matplotlib 中填充颜色
matplotlib中填充颜色主要是两个函数,一个是fill,一个是fill_between,这里讲一下详细的关键字,
这里关键字主要有facecolor填充色, where填充条件, alpha透明度,interpolate求交叉边界
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0.0, 4, 0.05)
y1 = np.sin(np.pi * x)
y2 = np.sin(2 * np.pi * x)
fig, axe = plt.subplots(1, 1, figsize=(10,8))
# axe.plot(x,y1, color ='C1')
# axe.plot(x,y2, color='C2')
axe.plot(x,y1,x,y2, color='black')
如果想加入填充,那么,可以使用fill函数:
‘’’
axe.fill(x, y1, alpha=0.5, label='y1')
axe.fill(x, y2, alpha=0.5, label='y2')
不过这样会发现,就是在填充区域会出现一些白色的没填充的区域,这是由于我们在设置x的时候其分段不是足够小,
因此,截断的位置并不是正好两曲线相交的位置;
可以通过改更小的x间距;可以发现x间距改小,图像结果就有所改善。