1
我嘗試了一個條形圖,在我的CSV文件及其工作中添加一個值標籤,但是我遇到了一個問題,爲什麼條形圖的高度不相等?條形圖(高度)不等於
CSV文件: CPU_5_SEC; CPU_1_MIN; CPU_5_MIN; 27; 17; 16;
代碼:
import numpy as np
import matplotlib.pyplot as plt
N = 3
men_std=(0,1,2)
data = np.loadtxt('show-process-cpu.csv',dtype=bytes, delimiter=';', usecols=(0,1,2))
utilization= data[1]
label = np.loadtxt('show-process-cpu.csv',dtype=bytes, delimiter=';', usecols=(0,1,2)).astype(str)
my_xticks = label[0]
ind = np.arange(N)
width = 0.40
rects = plt.bar(ind, utilization, width ,men_std,color='r',)
plt.title("Cpu Utilization\n ('%') ")
plt.xticks(ind,my_xticks)
def autolabel(rects):
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width()/2,height,
'%d' % int(height),
ha='center', va='bottom')
autolabel(rects)
plt.show()
你有沒有刪除您的評論我的回答?我被通知了,但現在它消失了。請讓我知道它是否有效,如果是,請接受答案。 –
對不起,回覆遲了:),我試了,它的工作,謝謝:) –
np!我很欣賞它,但是在我們這裏,我們主要感謝正確/最好的答案[通過接受它](https://meta.stackexchange.com/a/5235),它會獎勵海報並告訴其他人這個問題已經解決。 –