【问题标题】:Fill_between error python - giving me error: ordinal must be >= 1Fill_between error python - 给我错误:序数必须> = 1
【发布时间】:2020-09-16 20:54:31
【问题描述】:

我有以下代码:

ax = plt.gca()
datamax.plot(kind='line',x='Date',y='Data_Value',color='red',ax=ax)
datamin.plot(kind='line',x='Date',y='Data_Value', color='blue',ax=ax)
plt.ylabel("Temperature (degrees C)",color='navy')
plt.xlabel("Date",color='navy',labelpad=15)
plt.title('Record high and low temperatures by day (2005-2014)', alpha=1.0,color='brown',y=1.08)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.35),
          fancybox=False,labels=['Record high','Record low'])
plt.xticks(rotation=30)
plt.fill_between(datamax['Date'],datamax['Data_Value'],datamin['Data_Value'],where = None,color='yellow',alpha=0.25)
plt.show()

但是,我不断收到错误消息:

序数必须 >= 1

有人可以帮我一把吗?

我不明白为什么“fill_between”功能不起作用。

【问题讨论】:

标签: python pandas matplotlib plot data-visualization


【解决方案1】:

此代码有效:

  plt.fill_between(range(len(datamax['Date'])), datamax['Data_Value'], datamin['Data_Value'],color='yellow',alpha=0.8)

基本上,我使用 pandas 绘制线图,同时使用 标准 matplotlib 绘制 fill_between。

因此,使用range(len(datamax['Date'])) 而不是datamax['Date'] 克服了这个兼容性问题。

【讨论】:

    猜你喜欢
    • 2021-08-31
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多