I'm having a slightly frustrating situation with pandas/matplotlib (not sure which one's at fault here). If I create a simple random series and plot it as a line chart, the formatting is pretty clean:
test1 = pd.Series(index = pd.date_range(start='2000-06-30', end='2018-06-30', freq='3M'),
data = np.random.rand(73))
test1.plot(kind='line')
Most satisfactory. If I change the format to bar, though, the x-axis formatting goes to hell in a handbasket:
Matplotlib seems to feel obliged to label every single bar. Is there a logical reason for this or an easy fix?
Thanks in advance.
Matplotlib is trying to use each time as its own bar, and is trying to label each bar appropriately. To change this behaviour, you should change the xticks
or the xticklabels
. For example, one quick way to just remove the labels entirely is to do something like
subplot = test1.plot(kind='bar')
ax = subplot.axes
#ax.set_xticks([]) # Alternatively, you can manually adjust the ticks
ax.set_xticklabels([]) # or their labels
f = ax.get_figure()
f.show()
which will produce
You can reduce the number of ticks to something like using every n
th tick and its label in the same way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With