天天看點

python中xticks函數中rotation_旋轉xticks會導緻記号部分隐藏在matplotlib中

我正在建立一個在x軸上有名字,在y軸上有時間值(分鐘)的繪圖['cooking']18:15:27 ,['study']18:09:19,['travel']18:21:34` etc ..

其中y值為5,1,1等。我将xlabel設為“categories”,ylabel設為“durations in minutes”。

由于xtick是一些長度的字元串,我決定将它們旋轉90以避免重疊。現在,ticks部分隐藏,xlabel已消失。

python中xticks函數中rotation_旋轉xticks會導緻記号部分隐藏在matplotlib中

有什麼辦法可以讓整個情節适應一切嗎。。?

謝謝

标記

這是代碼片段import matplotlib.pyplot as plt

...

figure = plt.figure()

barwidth = 0.25

ystep = 10

plt.grid(True)

plt.xlabel('categories')

plt.ylabel('durations in minutes')

plt.title('durations for categories-created at :'+now)

plt.bar(xdata, ydata, width=barwidth,align='center')

plt.xticks(xdata,catnames,rotation=90)

plt.yticks(range(0,maxduration+ystep,ystep))

plt.xlim([min(xdata) - 0.5, max(xdata) + 0.5])

plt.ylim(0,max(ydata)+ystep)

figure.savefig("myplot.png",format="png")