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:
Asked
Active
Viewed 146 times
1
-
Please provide enough code so others can better understand or reproduce the problem. – Community Sep 15 '21 at 02:35
1 Answers
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:

mozway
- 194,879
- 13
- 39
- 75