1

I would like to plot dates on the x-axis using a logarithmic scale, such as in the example below, but I couldn't manage to get the correct spacing:

plot

mozway
  • 194,879
  • 13
  • 39
  • 75
mavetek
  • 13
  • 2

1 Answers1

0

The scale is a logarithmic scale. The trick here is to consider the years as categories, not numbers. I used strings here for this effect.

df = pd.DataFrame({'year': map(str, range(2010, 2045)), # years as strings
                   'value': 1 # dummy data here
                   })
ax = df.plot(x='year', y='value', marker='.')
ax.set_xscale('log')
ax.set_xticks(range(1,35+1), rotation='vertical')  # categories start from 1
ax.set_xticklabels(df['year'])

output:

matplotlib logarithmic scale years

mozway
  • 194,879
  • 13
  • 39
  • 75