假设 y1和y2两数据强相关,如何直观展现其数据情况?
要能展现其相关性、数值、趋势变化等
import matplotlib.pyplot as plt
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
y1 = [2., 2.1, 2.5, 2.6, 2.4, np.nan, 2.6, 2.7, 2.8, 2.9]
y2 = [1., 1.1, 1.5, 1.6, 1.4, np.nan, 1.6, 1.7, 1.8, 1.9]
xx = np.arange(0,9,0.1)
plt.plot(x,y1,'-o',color='gray')
plt.plot(x,y2, '-*',color='y')
for i in x:
plt.fill_between(x,y1=y1,y2=y2,where=(x>=i-0.5)&(x<=i+0.5),color='r',linewidth=10,alpha=0.4,step='mid')
# plt.show()
效果图如下:
适用范围:血压、商品售价与销售量等有较强关联的数据