如何绘制多个 pandas 列 [英] How to plot multiple pandas columns

查看:41
本文介绍了如何绘制多个 pandas 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据框 total_year,其中包含三列(yearactioncomedy).>

total_year

我想在 x 轴上绘制 year 列,以及 action &喜剧 y 轴.

如何在y轴上绘制两列( action comedy )?

我的代码仅在 y 轴上绘制一列.

total_year[-15:].plot(x='year', y='action', figsize=(10,5), grid=True)

解决方案

Pandas.DataFrame.plot() 默认使用索引绘制 X 轴,所有其他 numeric 列将用作 Y 值.

因此将 year 列设置为索引将达到目的:

  total_year.set_index('year').plot(figsize =(10,5),grid = True)

I have dataframe total_year, which contains three columns (year, action, comedy) .

total_year

I want to plot the year column on the x-axis, and action & comedy both on the y-axis.

How can I plot two columns (action and comedy) on y-axis?

My code plots only one column on y-axis.

total_year[-15:].plot(x='year', y='action', figsize=(10,5), grid=True)

解决方案

Pandas.DataFrame.plot() per default uses index for plotting X axis, all other numeric columns will be used as Y values.

So setting year column as index will do the trick:

total_year.set_index('year').plot(figsize=(10,5), grid=True)

这篇关于如何绘制多个 pandas 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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