【问题标题】:How to expand your x axis of datetimeIndex with matplotlib Python如何使用 matplotlib Python 扩展 datetimeIndex 的 x 轴
【发布时间】:2020-07-24 11:43:21
【问题描述】:

我有两个dataframes。我知道两者的时间范围并不完全相等。一个是电晕对我的操作的影响。并且效果在疫情爆发后开始显现。

下面是我的代码snippet

plt.figure(figsize=(10,10))
ax = covid19_df[covid19_df.countriesAndTerritories == "Germany"]["cases"].plot(label="Reported Cases")
ax1 = covid19_df[covid19_df.countriesAndTerritories == "Germany"]["deaths"].plot(label="Deaths")
df["NO OF CAPTURED FARMERS"].plot(label= "Number of farmers")
plt.ylabel("Number of cases", fontsize=15, labelpad=20)
plt.xlabel("Dates", fontsize=15, labelpad=20)
plt.legend()
sns.despine()

这是当前的情节:

不知道为什么蓝线不显示

【问题讨论】:

    标签: python dataframe matplotlib data-visualization


    【解决方案1】:

    您应该可以使用:https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.set_xlim.html

    ax.set_xlim(你的开始日期时间,你的结束日期时间)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      • 1970-01-01
      • 2022-06-22
      • 2020-10-20
      • 2021-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多