我正在尝试通过如下所示的csv文件创建一个boxplot
,其x标签为Firm(第5列),y标签为总体评分(第1列):
4,Missing,Missing,No opinion of CEO,ey,3.5,,3,4,3,2008,Current
Employee,auditor,miami,Missing,unknown,audit
5,Recommends,Missing,Approves of CEO,ey,5,,5,5,5,2008,Current
Employee,tax,tampa,Missing,unknown,tax
5,Recommends,Missing,Approves of CEO,ey,5,,5,4,5,2008,Current
Employee,audit staff,tampa,Missing,associate,audit
由此,我想提取总体评级栏和公司栏,以将其绘制在箱线图上。这是我到目前为止尝试过的无效代码:
import matplotlib.pyplot as plt
import csv
x=[]
y=[]
with open('Ratings.csv', 'r') as csvfile:
bplot1 = axes[0].boxplot(all_data,vert=True,patch_artist=True)
bplot2 = axes[1].boxplot(all_data,vert=True,patch_artist=True)
colors = ['pink', 'lightblue', 'lightgreen']
for bplot in (bplot1, bplot2):
for patch, color in zip(bplot['boxes'], colors):
patch.set_facecolor(color)
plt.plot(x,y, marker='o')
plt.title('Overall Rating Based on Firm')
plt.xlabel('Firm')
plt.ylabel('Overall Rating')
plt.show()