任何人都知道是否有可能在matplotlib中包裝xtick標籤?現在我已經得到了下面的代碼(種凌亂 - 它被黑客攻擊了一會兒):是否有可能在python中包裝matplotlib中的xticks文本?
def plotResults(request, question_id):
responses = ResponseOption.objects.filter(question__id=question_id).order_by('order').annotate(response_num=Count('response'))
counts = []
labels = []
for response in responses:
counts.append(response.response_num)
labels.append(smart_truncate('$'+response.text+'$'))
N = len(labels)
labels = tuple(labels)
counts = tuple(counts)
ind = na.array(range(N))+0.5
width = .35
fig = Figure(facecolor='white',edgecolor='white')
ax = fig.add_subplot(1,1,1)
rects1 = ax.bar(ind, counts,linewidth=0)
ax.set_ylabel('$Count$')
ax.set_title('$Response Historgram$')
ax.set_xticks(ind+width)
ax.set_xticklabels(labels)
print mpl.matplotlib_fname()
canvas = FigureCanvas(fig)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
生成此情節:
正如你所看到的xticks被粘結。關於如何包裝它們的任何想法,或者使它們可讀的瓶頸?再次感謝!
PS:這是一個Django項目的一部分。我將該情節作爲png圖片返回 - 通常在各種視圖中通過img標記調用它們。
'rotation ='vertical'' could be the answer:http://stackoverflow.com/questions/1221108/barchart-with-vertical-labels-in-python-matplotlib – unutbu 2010-08-12 02:40:35
@〜unutbu:''rotation' can be任何角度,請參閱:http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.set_xlabel – Amro 2010-08-12 02:44:17
@Amro,謝謝。 'xticks(rotation = 45)'看起來可能更好...... – unutbu 2010-08-12 02:48:33