简体   繁体   English

Xaxis标签与数据点不匹配-Pandas / Matplotlib

[英]Xaxis Labels not matching Data Points - Pandas/Matplotlib

I have a TimeSeries in Pandas that I want to plot. 我想绘制一个熊猫中的TimeSeries。 I have 336 records in the TimeSeries. 我在TimeSeries中有336条记录。 I only want to show the date/time (index of the TimeSeries) on the x-axis once per every 20 or so data points. 我只想每20个左右的数据点在x轴上显示一次日期/时间(TimeSeries的索引)。

Here is how I am trying to do this: 这是我尝试执行的操作:

stats.plot()
ax.set_xticklabels(stats.index, rotation=45 ) 
ax.xaxis.set_major_locator(MultipleLocator(20))
ax.xaxis.set_minor_locator(NullLocator())
ax.yaxis.set_major_locator(MultipleLocator(.075))
draw() 

?My x-axis show the correct number of labels (18), but these are the first 18 in the series, they are not correctly corresponding to the datapoints in the plot. 我的x轴显示正确数量的标签(18),但它们是序列中的前18个,它们与图中的数据点不正确对应。

The problem is you are using set_xticklabels which sets the value of the tick labels independent of the data . 问题是您正在使用set_xticklabels ,它设置刻度标记的值与数据无关 The ticks are labeled sequentially from the list you pass in. 刻度线从您传递的列表中顺序标记。

From this I can't really tell what you are trying to do, but the behavior you are seeing is the 'correct' behavior for the library (it's doing exactly what you told it to, but that isn't what you want it to do). 由此我不能真正说出您要做什么,但是您看到的行为是该库的“正确”行为(它确实按照您的指示进行,但这并不是您想要的 。做)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM