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?

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

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.