我正在尝试根据百分比绘制直方图,但不断出现以下错误:
ValueError: incompatible sizes: argument 'height' must be length 6 or scalar
与这行有关,但是我不确定height参数有什么问题。
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
xaxis=['epic1', 'epic2', 'epic3', 'epic4', 'epic5', 'epic6']
n=len(xaxis)
names = ('epic1', 'epic2', 'epic3', 'epic4', 'epic5', 'epic6')
data = {'done': [57,53,49,65,78,56,89],
'progress': [23,12,34,11,34,12,12],
'todo' :[11,5,6,7,8,4,6]}
df = pd.DataFrame(data)
df['total'] = df['done'] + df['progress'] + df['todo']
df['done_per'] = df['done'] / df['total'] * 100
df['progress_per'] = df['progress'] / df['total'] * 100
df['todo_per'] = df['todo'] / df['total'] * 100
barWidth = 0.25
# Create green Bars
plt.bar(xaxis, done_per, color='#b5ffb9', edgecolor='green', width=barWidth)
# Create orange Bars
plt.bar(xaxis, progress_per, bottom=done_per, color='#f9bc86',
edgecolor='orange', width=barWidth)
# Create blue Bars
plt.bar(xaxis, todo_per, bottom=[i+j for i,j in zip(done_per, progress_per)],
color='blue', edgecolor='blue', width=barWidth)
plt.xticks(xaxis, names)
plt.xlabel("epics")
plt.show()
X_per
(轴)中有7个项目,xaxis
中有6个项目。
如果您要7个项目,将'epic7'
添加到xaxis
中即可完成工作。 xaxis.append('epic7')
我认为您在代码中错过了几行:
done_per = df['done_per']
progress_per = df['progress_per']
todo_per = df['todo_per']