1

Is it possible to take:

hello world 12345

as an x-tick label (already being displayed vertically) and turn it into this:

hello world
12345

which is an x-tick label with (rotated) two columns?

asked Feb 22, 2011 at 17:47

1 Answer 1

8

You could format the text using the textwrap module from the standard library:

import matplotlib.pyplot as plt
import numpy as np
import textwrap
mu, sigma=100, 15
N=4
x=mu + sigma*np.random.randn(N)
plt.bar(range(N), x, align='center')
labels=[
 'hello world 12345',
 'another long one',
 'what happened to pithy',
 'yada yada',
 ]
labels=[textwrap.fill(text,15) for text in labels]
plt.xticks(range(N), labels)
plt.show()

enter image description here

answered Feb 22, 2011 at 17:57

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.