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:

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.
P.S. to fix this I had to peek into the plots in a very clumsy way, which might be another argument for returning a DataArray of axes, instead of a numpy array of them:
with disaster_model:
axes_arr = az.plot_trace(trace)
plt.draw() # this forces population of the xticklabels so that the get_text() works later.
for ax in axes_arr.flatten():
if ax.get_title() == 'switchpoint': # find the right axes
labels = [label.get_text() for label in ax.get_xticklabels()] # collect the existing labels.
ax.set_xticklabels(labels, rotation=45, ha='right') # rotation here
break
plt.draw()
This also shows it's harder to fix after the fact, than have ArviZ do it right to begin with!
This used to work
ax = az.plot_trace(trace);
[ticks.set_rotation(45) for ticks in ax[0, 0].get_xticklabels()]
but now az.plot_trace return something else, right @agustinaarroyuelo ?
This problem could happen with long labels not necessarily DateTimeIndex. So we should work on a general solution at the matplotlib level, or revert what az.plot_trace returns.
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?
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()]
Hi! Can i take this up ?
I'm not sure if we should check datetime stuff. Or would it be ok to just call pandas datetime autoformat.
We really should have an easy way to change the defaults if user wants it.
#1361 will allow this to work again.
ax = az.plot_trace(trace)
[ticks.set_rotation(45) for ticks in ax.figure.axes[0].get_xticklabels()]
I think this should be enough, as allow full control on the user side. Unless someone offers a general default solution (not only for dates).
Hi @abhisht51! Are you searching for matplotlib related issues? Or more general plotting issues? ArviZ has both matplotlib and bokeh backends. If you prefer we can also talk in Gitter.
Most helpful comment
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()]