larray-project / larray

N-dimensional labelled arrays in Python
https://larray.readthedocs.io/
GNU General Public License v3.0
8 stars 6 forks source link

Plots using an integer axis produces float labels #1076

Closed gdementen closed 1 year ago

gdementen commented 1 year ago

For example,

arr = ndtest('year=2010..2012')
arr.plot()

produces a plot from 2010.0 to 2012.0 in steps of 0.25, which looks really silly. Remarkably, the plot produced via the editor GUI (via Ctrl-P) does not suffer from that problem, so its code could probably be used for inspiration.

gdementen commented 1 year ago

This problem comes from Pandas, which inherits it from matplotlib:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.bar([2010, 2011, 2012], [1, 3, 2])
plt.show()

Figure_1

The problem is only present when there are less than 5 ticks/values:

fig, ax = plt.subplots()
ax.bar([2010, 2011, 2012, 2013, 2014], [1, 3, 2, 4, 2])
plt.show()

Figure_2