python - 使用 Matplotlib 从具有多列的 CSV 文件中绘制图形
问题描述
我正在尝试boxplot
从这样设置的 csv 文件中创建一个 x 标签为公司(第 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()
解决方案
推荐阅读
- angular - 如何使用 zxing js 以角度扫描 GTIN/GS1-IR 条码?
- c# - 在 c# 中使用嵌套拉取文档时,如何反序列化字段中的字符串?
- selenium - browser.sendAlertText 在 WebDriver.io 中不起作用
- javascript - 用于嵌套对象数组的 Typescript 接口
- c++ - 特征模板不适用于固定大小的矩阵
- flutter - 与提供者合作时不应该使用有状态的小部件吗?
- sql - 在文件名中以动态日期格式从 excel 文件中选择 openrowset
- java - 如何使 JavaCompiler -classpath 有效?(Linux 上的 .java)
- php - 在 PHP 中多次获取文件权限似乎不起作用
- graphql - 应用程序错误:发生客户端异常(有关详细信息,请参阅浏览器控制台)