如何用点绘制两列大 pandas 数据框? [英] How to plot two columns of a pandas data frame using points?

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

问题描述

我有一个熊猫数据框,并希望绘制一列的值与另一列的值。幸运的是,与我需要的数据框相关联的 plot 方法

  df.plot(x ='col_name_1',y ='col_name_2')

不幸的是,它在绘图风格之间(这里后面的 kind 参数)没有点。我可以使用线或条,甚至密度,但不能使用点。有一个工作可以帮助解决这个问题。

解决方案

您可以指定 style 在调用 df.plot

  df.plot(x ='col_name_1',y ='col_name_2',style ='o')

样式参数也可以是 dict 列表,例如:

  import numpy as np 
import pandas as pd

d = {'one':np.random.rand(10),
'two':np.random.rand(10)}

df = pd.DataFrame (d)

df.plot(style = ['o','rx'])

所有接受的样式格式都列在 matplotlib.pyplot.plot




I have a pandas data frame and would like to plot values from one column versus the values from another column. Fortunately, there is plot method associated with the data-frames that seems to do what I need:

df.plot(x='col_name_1', y='col_name_2')

Unfortunately, it looks like among the plot styles (listed here after the kind parameter) there are not points. I can use lines or bars or even density but not points. Is there a work around that can help to solve this problem.

解决方案

You can specify the style of the plotted line when calling df.plot:

df.plot(x='col_name_1', y='col_name_2', style='o')

The style argument can also be a dict or list, e.g.:

import numpy as np
import pandas as pd

d = {'one' : np.random.rand(10),
     'two' : np.random.rand(10)}

df = pd.DataFrame(d)

df.plot(style=['o','rx'])

All the accepted style formats are listed in the documentation of matplotlib.pyplot.plot.

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

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