解决python中使用plot画图,图不显示的问题
作者:Data_Ada 时间:2021-09-27 16:00:07
对以下数据画图结果图不显示,修改过程如下
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的图结果
来源:https://blog.csdn.net/Data_Ada/article/details/72873352
标签:Python,plot
0
投稿
猜你喜欢
css样式表使用技巧小结
2008-01-11 20:44:00
python数学建模(SciPy+ Numpy+Pandas)
2021-02-17 11:05:14
python OpenCV学习笔记实现二维直方图
2021-08-17 11:23:49
PHP 用数组降低程序的时间复杂度
2023-10-08 11:38:03
python中heapq堆排算法的实现
2022-10-13 23:11:40
django框架事务处理小结【ORM 事务及raw sql,customize sql 事务处理】
2022-02-27 23:20:03
windows下cx_Freeze生成Python可执行程序的详细步骤
2022-12-06 05:27:57
Python科学计算包numpy用法实例详解
2021-11-12 15:07:20
mysql主从服务器配置特殊问题
2011-01-04 19:56:00
python网络应用开发知识点浅析
2021-07-15 00:09:48
几个图片按比例缩放的代码
2008-02-13 08:51:00
asp检测文件编码方法
2007-10-03 14:27:00
python 基于opencv实现图像增强
2023-03-20 21:04:32
Python入门教程(十三)Python元组
2023-10-28 08:42:24
python机器学习之随机森林(七)
2023-10-20 00:25:13
用python实现监控视频人数统计
2022-04-03 16:01:31
PHP中$GLOBALS['HTTP_RAW_POST_DATA']和$_POST的区别分析
2023-11-22 22:00:16
Python中scatter散点图及颜色整理大全
2022-10-06 02:17:51
基于FlashPaper实现JSP在线阅读代码示例
2023-06-14 21:02:31
利用Python生成随机验证码详解
2021-10-04 19:55:50