2016-12-03 34 views
2

我試圖做一個簡單的條形圖: 高度是在數據幀的列值的頻率使從大熊貓數據框中列barplot

我已經運行到這個錯誤: ValueError異常:不兼容大小:論點「高度」長度必須爲1或標

代碼:

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt 
import pylab as pl 
matplotlib.style.use('ggplot') 
flags = [200, 201, 211, 237, 239, 250, 254, 255] 
frequencies = [158, 87, 5, 4] 
length = len(flags) 
plt.bar(length, frequencies.values, align='center') 
plt.show() 
+0

當你說「高度爲值的頻率」我聽到「直方圖」。如果你確實需要一個直方圖,熊貓有一個內置的方法來創建這些:'df ['foo']。hist()' – dagrha

回答

2

嘛,據我可以的matplotlib.pyplot.bar的文檔中看到,參數leftheight必須是相同的長度:

>>> plt.bar(range(len(frequencies)), frequencies, align='center') 
>>> plt.show() 

enter image description here

+0

謝謝,這就是我認爲可能是問題,但我不確定 – KatieRose1029