2011-02-22 2 views

Répondre

7

Vous pouvez formater le texte à l'aide du module textwrap de la bibliothèque standard:

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

+0

Je vais l'essayer. Merci :). – thenickname

+0

+1 pour une réponse lapidaire. – mtrw