我在两个线图之间的区域着色时遇到了一个问题,因为它们都有不同的日期值(x轴)
代码如下:
plt.figure(figsize=(30,20))
fig, ax = plt.subplots(1)
plt.plot(highs['Date'], highs['Data_Value'], label = "Record High")
plt.plot(lows['Date'], lows['Data_Value'], label = "Record Low")
plt.scatter(tmin2015['Date'].tolist(), tmin2015['Data_Value'], marker='o', c='green', label="2015 record low")
x = plt.gca().xaxis
plt.xlabel("Year", fontsize=16)
plt.ylabel("Temperature in \N{DEGREE SIGN}C", fontsize=16)
plt.title("Extreme Temperature Recorded Every Year")
for item in x.get_ticklabels():
item.set_rotation(45)
plt.legend(loc='best')
# ax.fill_between(highs['Date'],lows['Data_Value'], highs['Data_Value'])
plt.show()
^{} 假设两个系列都有公共的x值。如果起始值和结束值相同,则可以插值as implemented here。但是,在您的示例中并非如此。
您可以改为创建路径对象并将其添加为填充面片:
样本输出:
与@MrT提到的“插值法”类似:
输出:
相关问题 更多 >
编程相关推荐