在 pandas 折线图中绘制多个列 [英] Plotting multiple columns in a pandas line graph

查看:73
本文介绍了在 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 折线图中绘制多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆