如何在折线图的Y轴上绘制多个 pandas 列 [英] How to plot multiple pandas columns on the y-axis of line graph

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

问题描述

我有一个数据框 total_year ,其中包含三列( year action comedy ).

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

总年

我想在x轴上绘制 year 列,然后 action &y轴上都是喜剧.

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

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

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

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

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()默认情况下使用索引来绘制 X 轴,所有其他数字列将用作 Y 值.

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

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

So setting year column as index will do the trick:

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

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

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