简体   繁体   English

matplotlib:在时间序列中的期间数据下居中期间标签 plot

[英]matplotlib: Centering period labels under the period's data in a time-series plot

matplotlib's axis-formatting options tend to fall flat when it comes to plotting and effectively labeling dense time-series data.在绘制和有效标记密集的时间序列数据时,matplotlib 的轴格式选项往往会下降。

One problem is that tick labels are tied to ticks, so if you set axis ticks at an appropriate frequency, there are usually too many labels.一个问题是刻度标签与刻度相关联,因此如果您以适当的频率设置轴刻度,通常会有太多标签。 This also means that if you are plotting, say, daily data over a period of several years, there is no good way to label the x-axis with each year in its natural position: centered under the year's data (ie, under the x-axis position for July 2, or thereabouts).这也意味着,如果您正在绘制几年内的每日数据,则没有好的方法可以将 x 轴与每年的 x 轴对齐-axis position 为 7 月 2 日或之后)。

The trick described in this example —set major ticks where you want them, then use invisible minor ticks to place the labels elsewhere—works, but it limits you to one visible set of axis ticks (since each axis is limited to one set of major and one set of minor ticks). 这个例子中描述的技巧——在你想要的地方设置主要刻度,然后使用不可见的次要刻度将标签放置在其他地方——有效,但它限制了你一组可见的轴刻度(因为每个轴都被限制为一组主要刻度)和一组次要刻度)。 You can't show, say, major ticks at the start of each year and minor ticks at the start of each month without giving up the ability to put year labels centered appropriately between the major (yearly) ticks, as you would find in publication-quality plots.例如,您不能在每年年初显示主要刻度,在每个月初显示次要刻度,而不会放弃将年份标签放在主要(每年)刻度之间适当居中的能力,正如您在出版物中发现的那样- 质量地块。

Is there a work-around that doesn't involve drawing everything fully manually?是否有不涉及完全手动绘制所有内容的解决方法?

Have you looked at the tsplot capability in scikits.timeseries ?您是否查看过 scikits.timeseries 中的tsplot功能? It hasn't been maintained much recently, but it works pretty well.它最近没有得到太多维护,但它工作得很好。 I'll be porting that code into pandas at some point in the relative near future.在不久的将来,我会将该代码移植到 pandas 中。

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

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