Using pandas.TimeSeries_DateFormatter in bar plot?
See original GitHub issuexref #5774
When time series is set as index, line plot uses the TimeSeries_DateFormatter for recognizable date formatting. However, bar plot use the FixedFormatter which outputs the datetime as it is. Can bar plot also use the DateFormatter?
In [1]: from pandas import *
In [2]: from numpy.random import *
In [3]: ts = Series(randn(100), index=date_range('1/1/2000', periods=100))
In [4]: df = DataFrame(randn(100, 4), index=ts.index, columns=['A', 'B', 'C', 'D'])
In [5]: df = df.cumsum()
In [7]: a = df.plot(kind='bar')
In [9]: a.get_xaxis().get_major_formatter()
Out[9]: <matplotlib.ticker.FixedFormatter instance at 0x108700f38>
In [11]: a = df.plot()
In [12]: a.get_xaxis().get_major_formatter()
Out[12]: <pandas.tseries.converter.TimeSeries_DateFormatter instance at 0x10877ccf8>
Issue Analytics
- State:
- Created 11 years ago
- Reactions:6
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Pandas bar plot changes date format - Stack Overflow
The pandas.tseries.converter.TimeSeries_DateFormatter that Pandas uses to format the dates in the "good" plot works well with line plots ...
Read more >Pandas & Matplotlib: personalize the date format in a bar chart
He wanted to change the format of the dates on the x-axis in a simple bar chart with data read from a csv...
Read more >Customize Dates on Time Series Plots in Python Using ...
Using the DateFormatter module from matplotlib, you can specify the format that you want to use for the date using the syntax: "%X...
Read more >Plotting with Pandas - Dates and Bar Plots | by Dalya Gartzman
Using Pandas Python package to make nice plots with dates and other shenaniganz.
Read more >Time series plot with Matplotlib - Python Graph Gallery
subplots(figsize=(8, 6)) half_year_locator = mdates.MonthLocator(interval=6) year_month_formatter = mdates.DateFormatter("% ...
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 FreeTop 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
Top GitHub Comments
I found a workaround, by applying this at the end:
In this case,
d
is theDataFrame
I’m plotting, andd.index
is theDatetimeIndex
.I’m not a huge fan of the workaround and hit this quite frequently still. It also doesn’t produce x-axis labels which are as good a
data.plot()
does, because the latter does Year labels on a separate row than Month labels, and I don’t know how to achieve the same effect. I’d love for bar chars to be able to display time series data in the same way that line plots do, sometimes it is a less misleading way to present the data.