Reputation: 1219
I have the following:
df.groupby(['A', 'B'])['time'].mean().unstack().plot()
This gives me a line graph like this one:
The circles in the plot indicate data points. The values on x-axis are the values of A which are discrete (100, 200 and 300). That is, I only have data points on the 100th, 200th and 300th point on the x-axis. Pandas/Matplotlib adds the intermediate values on the x-axis (125, 150, 175, 225, 250 and 275) that I don't want.
How can I plot and tell Pandas not to add the extra values on the x-axis?
Upvotes: 0
Views: 897
Reputation: 740
You're looking for tick locators
import matplotlib.ticker as ticker
df = pd.DataFrame({'y':[1, 1.75, 3]}, index=[100, 200, 300])
ax = df.plot(legend=False)
ax.xaxis.set_major_locator(ticker.MultipleLocator(100))
Upvotes: 2