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
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
lang-py