Improve layout of plots with DateTimeIndex
See original GitHub issueTell us about it
Plots with dates on their x axis can be typeset poorly. Here is an example from https://docs.pymc.io/notebooks/getting_started.html

The x coordinate here is a DateTimeIndex
:
{'date': DatetimeIndex(['2008-05-02', '2008-05-05', '2008-05-06', '2008-05-07',
'2008-05-08', '2008-05-09', '2008-05-12', '2008-05-13',
'2008-05-14', '2008-05-15',
...
'2019-11-01', '2019-11-04', '2019-11-05', '2019-11-06',
'2019-11-07', '2019-11-08', '2019-11-11', '2019-11-12',
'2019-11-13', '2019-11-14'],
dtype='datetime64[ns]', name='Date', length=2906, freq=None)}
Looking at the web, I see that there are techniques for better formatting such axes: https://www.delftstack.com/howto/matplotlib/how-to-rotate-x-axis-tick-label-text-in-matplotlib/#fig-autofmt-xdate-rotation-to-rotate-xticks-label-text
Revised using a rotation argument for the xticklabels:

Thoughts on implementation
We look at the label of the x axis, and if it is a DateTimeIndex
, we automatically use one of these techniques.
Note: this advice applies only to the matplotlib back-end – I don’t know enough about bokeh to know if there is a corresponding technique there.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Pandas plotting: How to format datetimeindex? - Stack Overflow
plot (), I have decided to create a new dataframe and plot from it. Save this answer.
Read more >Time series and date axes in Python - Plotly
Over 21 examples of Time Series and Date Axes including changing color, size, log axes, and more in Python.
Read more >What's New — pandas 0.19.2 documentation
Improved performance of Period construction and time series plotting (GH12903, GH11831). Improved performance of .str.encode() and .str.decode() methods ( ...
Read more >Tutorial: Time Series Analysis with Pandas - Dataquest
Creating a time series DataFrame. To work with time series data in pandas, we use a DatetimeIndex as the index for our DataFrame...
Read more >How to plot multi-color line if X-axis is datetime index of Pandas?
To plot multicolor line if X-axis is datetime index of Pandas, we can take the following s ... ... rcParams["figure.autolayout"] = True d ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi! I am taking a look at this right now. Meanwhile, this should work:
ax = az.plot_trace(trace_cat)
[ticks.set_rotation(45) for ticks in ax.figure.axes[0].get_xticklabels()]
Yeah, we should fix
az.plot_trace
, currently is only returning the last axes instead of all of them. Making further tweaking of the plot not possible. @agustinaarroyuelo Could you check this?