Issue
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 ?
Solution
As r-beginners already pointed out in the comment, you can use matplotlib.axes.Axes.set_xlim
in order to set x axis limits:
ax.set_xlim(0, 100)
Answered By - Zephyr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.