question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve layout of plots with DateTimeIndex

See original GitHub issue

Tell 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

image

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:

image

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:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
agustinaarroyuelocommented, Aug 21, 2020

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()]

2reactions
aloctavodiacommented, Aug 21, 2020

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found