我需要繪製數據的條形圖,標籤太長而不適合在x軸上顯示標記。我希望在圖例中包含標籤,但無法從圖例中移除顏色(包括顏色使圖例雜亂無章)。下面是一些示例代碼:沒有顏色的圖例的條形圖
import matplotlib.pyplot as plt
data_dic={1:'1:Text 1',2:'2:Text 2',3:'3:Text 3',4:'4:Text 4'}
ax1 = plt.subplot(111)
xval = [1,2,3,4]
yval = [ 22., 13., 21., 6.]
for j in range(len(xval)):
ax1.bar(xval[j], yval[j], width=0.8, bottom=0.0, align='center', color='k', label=data_dic[xval[j]])
ax1.set_xticks(xval)
ax1.legend()
plt.show()
謝謝!
大 - 簡單而有效的。謝謝! – shadowprice