开发者

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

开发者 https://www.devze.com 2023-03-11 17:06 出处:网络
matplotlib\'s axis-formatting options tend to fall flat when it comes to plott开发者_如何学Going and effectively labeling dense time-series data.

matplotlib's axis-formatting options tend to fall flat when it comes to plott开发者_如何学Going and effectively labeling dense time-series data.

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 (i.e., under the x-axis position for July 2, or thereabouts).

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? 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消