I have defined the scale of the x-axis by using ax.set_xlim([0, 800]) but i want to shorten the length. How can i achieve the result of the second image.
1 Answer
You can achieve that by explicitely reducing the figure width with figsize compared to the height:
Code:
import matplotlib.pyplot as plt
y=['one', 'two', 'three', 'four', 'five']
x=[18,36,61,65,83]
fig, ax = plt.subplots(figsize=(1.5, 6))
ax.barh(y, x, color = 'olive')
ax.set_xlim([0, 100])
ax.set_xticks([0, 100])
fig.tight_layout()
plt.show()
Notes:
- align with
figsize=(width, height)in inches (default), see link above on more options ax.set_xlim([0, 100])may be optional depending on your data / plot intentionax.set_xticks([0, 100])prevents interims ticks in case you increase the figsize width- if that's not intended just remove or adapt it


