将 x 和 y 标签添加到 pandas 图中 [英] Add x and y labels to a pandas plot

查看:31
本文介绍了将 x 和 y 标签添加到 pandas 图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下代码使用 Pandas 绘制一些非常简单的内容:

Suppose I have the following code that plots something very simple using pandas:

import pandas as pd
values = [[1, 2], [2, 5]]
df2 = pd.DataFrame(values, columns=['Type A', 'Type B'], 
                   index=['Index 1', 'Index 2'])
df2.plot(lw=2, colormap='jet', marker='.', markersize=10, 
         title='Video streaming dropout by category')

如何轻松设置 x 和 y 标签,同时保留使用特定颜色图的能力?我注意到 Pandas DataFrames 的 plot() 包装器没有采用任何特定于此的参数.

How do I easily set x and y-labels while preserving my ability to use specific colormaps? I noticed that the plot() wrapper for pandas DataFrames doesn't take any parameters specific for that.

推荐答案

在 Pandas version 1.10 中你可以使用参数 xlabelylabel方法plot:

In Pandas version 1.10 you can use parameters xlabel and ylabel in the method plot:

df.plot(xlabel='X Label', ylabel='Y Label', title='Plot Title')

这篇关于将 x 和 y 标签添加到 pandas 图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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