python中使用plot画图,图不显示
2017-06-06 00:47
274 查看
对以下数据画图结果图不显示,修改过程如下
df3 = {'chinese':109, 'American':88, 'German': 66, 'Korea':23, 'Japan':5, 'England':118} df4 = pd.DataFrame(df3) df4.plot(kind='barh', rot=0)
运行结果:ValueError: If using all scalar values, you must pass an index
原因:缺少索引
修改后:
#方式1: df4 = pd.DataFrame.from_dict(df3,orient='index').T df4.plot(kind='barh', rot=0) print df4 #结果: Korea England chinese German American Japan 0 23 118 109 66 88 5
#方式2: df5 = pd.DataFrame({"key": df3.keys(), "value": df3.values()}) print df5 #结果为: key value 0 Korea 23 1 England 118 2 chinese 109 3 German 66 4 American 88 5 Japan 5
# 作图语句: df4.plot() df5.plot(kind='barh', rot=0) #运行以上语句图片不显示 #增加以下句子后出现图片 import matplotlib.pyplot as plt plt.show()
df4的图结果
df5的图结果
相关文章推荐
- Python 3下使用Matplotlib工具画图,中文显示乱码的问题解决(修改配置文件)
- Mac 使用python3的matplot画图不显示问题
- 解决python中使用plot画图,图不显示的问题
- python画图包seaborn和matplotlib中文字体显示(针对windows系统,,使用ipython notebook)
- python matplotlib画图安装和使用
- python3使用matplotlib画图支持中文
- Python 3下Matplotlib画图中文显示乱码的解决方法
- python opencv 使用 Matplotlib显示图像
- python3 使用matplotlib画图出现中文乱码的情况
- Python 使用matplotlib画图添加标注、及移动坐标轴位置
- 特征选择与评分的可视化显示 - 在Python中使用Matplotlib绘制“横着的”条形图
- python画图matplotlib的Legend(显示图中的标签)
- python的matplotlib画图时无法显示中文的解决方法
- python 使用matplotlib绘图中文显示成框框解决办法
- python使用matplotlib画图出现中文乱码
- Python 使用matplotlib画图添加标注、及移动坐标轴位置
- Python matplotlib画图的中文显示问题
- python matplotlib.plot画图显示中文乱码的问题
- python中matplotlib使用双y轴的时候,只能显示第二个曲线标志怎么办?
- OpenCV for Python [2]使用Matplotlib显示图片