Plotting multiple columns in a pandas line graph(在 pandas 折线图中绘制多列)
问题描述
我正在尝试在折线图中绘制多个列,其中月"作为 X 轴,每个计数"作为新行.我希望它有 5 行,'Count-18..Count-14'.我尝试绘制 1 行作为测试,但是当我运行以下代码时,我得到以下输出但没有图表.有什么想法吗?
I am trying to plot a multiple columns in a line graph with 'Month' as the X axis and each 'Count' as a new line. I want it to have 5 lines, 'Count-18..Count-14'. I tried plotting 1 line as a test but when I run the following code I get the following output with no graph. Any ideas?
ax = plt.gca()
DomReg1418.plot(kind='line',x='Month',y='Count-18',ax=ax)
推荐答案
当你有一个 DataFrame 有一列用作 X 轴和其他作为绘制线条的来源,您应该:
When you have a DataFrame with one column to be used as X axis and other as a source of lines to draw, you should:
- 将索引设置为X"列(在您的情况下为 Month),
- 运行绘图,
- 用分号结束命令,以阻止文本消息关于图片对象.
代码如下:
DomReg1418.set_index('Month').plot();
对于测试,我在前 6 个月输入了 X 和 3 个 Count 列并执行上述命令,得到如下结果:
For the test, I entered X and 3 Count columns, for first 6 months and executed the above command, getting the following result:
这篇关于在 pandas 折线图中绘制多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 pandas 折线图中绘制多列


基础教程推荐
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 筛选NumPy数组 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01