我正在使用 pandas .plot() 绘制时间序列,并希望看到每个月都显示为 x-tick.
这是数据集结构
这是 .plot() 的结果
我试图使用其他帖子和 matplotlib
I am plotting time series using pandas .plot() and want to see every month shown as an x-tick.
Here is the dataset structure
Here is the result of the .plot()
I was trying to use examples from other posts and matplotlib documentation and do something like
ax.xaxis.set_major_locator(
dates.MonthLocator(revenue_pivot.index, bymonthday=1,interval=1))
But that removed all the ticks :(
I also tried to pass xticks = df.index, but it has not changed anything.
What would be the rigth way to show more ticks on x-axis?
No need to pass any args to MonthLocator. Make sure to use x_compat in the df.plot() call per @Rotkiv's answer.
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
import matplotlib.dates as mdates
df = pd.DataFrame(np.random.rand(100,2), index=pd.date_range('1-1-2018', periods=100))
ax = df.plot(x_compat=True)
ax.xaxis.set_major_locator(mdates.MonthLocator())
plt.show()
set_major_locator这篇关于pandas .plot() x 轴刻度频率——如何显示更多刻度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
根据跨越边界的数量,突出显示超过或低于阈值Highlight matplotlib points that go over or under a threshold in colors based on the amount the boundaries are crossed(根据跨越边界的数量,突出
不能使用 matplotlib.use('Agg'),图形总是显示Can#39;t use matplotlib.use(#39;Agg#39;), graphs always show on the screen(不能使用 matplotlib.use(Agg),图形总是显示在屏幕上)
Pandas 错误 - 遇到无效值Pandas error - invalid value encountered(Pandas 错误 - 遇到无效值)
Anaconda 运行时错误:Python 未作为框架安装?Anaconda Runtime Error: Python is not installed as a framework?(Anaconda 运行时错误:Python 未作为框架安装?)
在 Windows 上使用 Python 3.5 Anaconda 的底图Basemap with Python 3.5 Anaconda on Windows(在 Windows 上使用 Python 3.5 Anaconda 的底图)
Spyder 5.1.5 运行自定义函数后创建新内核Spyder 5.1.5 creates a new kernel after running a custom function(Spyder 5.1.5 运行自定义函数后创建新内核)