如何使用点绘制 pandas 数据框的两列 [英] How to plot two columns of a pandas data frame using points
问题描述
我有一个 Pandas 数据框,想绘制一列中的值与另一列中的值.幸运的是,有一个与数据框相关的 plot
方法似乎可以满足我的需要:
I have a pandas dataframe 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.
推荐答案
调用 df.plot
:
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')
style
参数也可以是 dict
或 list
,例如:
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'])
matplotlib 的文档中列出了所有接受的样式格式.pyplot.plot
.
这篇关于如何使用点绘制 pandas 数据框的两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!