Plotting multiple columns in a pandas line graph

让人想犯罪 __ 提交于 2020-12-12 01:28:44

问题


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)


回答1:


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:

  • set the index to the "X" column (in your case Month),
  • run plot,
  • terminate the command with a semicolon, to block a text message concerning the picture object.

The code to do it is:

DomReg1418.set_index('Month').plot();

For the test, I entered X and 3 Count columns, for first 6 months and executed the above command, getting the following result:



来源:https://stackoverflow.com/questions/58998027/plotting-multiple-columns-in-a-pandas-line-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!