0

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.

Scale from 0 to 800

Scale from 0 to 800 but shorter x-axis

0

1 Answer 1

1

You can achieve that by explicitely reducing the figure width with figsize compared to the height:

enter image description here

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 intention
  • ax.set_xticks([0, 100]) prevents interims ticks in case you increase the figsize width
    • if that's not intended just remove or adapt it
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.