The following code :
fig, ax = plt.subplots(figsize=(10, 5))
np.random.seed(1)
df = pd.DataFrame(
{
"x": np.random.randint(0, 4, size=(1000)),
"y": np.random.randint(0, 4, size=1000),
}
)
pd.crosstab(df["x"], df["y"], normalize="columns").mul(100).T.plot.barh(
stacked=True, ax=ax
)
ax.xaxis.set_major_locator(mpl.ticker.MultipleLocator(base=5))
Will output:
If the line
ax.xaxis.set_major_locator(mpl.ticker.MultipleLocator(base=5))
Is removed, the limit is as expected (100) :
How can MultipleLocator
be used in this case, without pushing the axis over the limit of 100 ?
CodePudding user response:
As r-beginners already pointed out in the comment, you can use