python中两个不同数据帧的散点绘图数据

2024-04-23 23:06:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个不同的数据帧格式如下。在

dfclean
Out[1]: 
      obj
0     682
1     101
2      33

dfmalicious
Out[2]: 
                obj
        0        17
        1        43
        2         8
        3         9
        4       211

我的用例是绘制一个散点图,清楚地显示来自两个数据帧的obj值。为此,我使用python。我用了几个例子来复制我的数据,但我用了两个数据框。非常感谢任何帮助。在

How to plot two DataFrame on same graph for comparison


Tags: to数据objdataframeploton格式绘制
1条回答
网友
1楼 · 发布于 2024-04-23 23:06:38

要在单个轴上绘制多个列组,请重复指定目标plot方法ax

选项1]

In [2391]: ax = dfclean.reset_index().plot(kind='scatter', x='index', y='obj',
                                           color='Red', label='G1')

In [2392]: dfmalicious.reset_index().plot(kind='scatter', x='index', y='obj',
                                          color='Blue', label='G2', ax=ax)
Out[2392]: <matplotlib.axes._subplots.AxesSubplot at 0x2284e7b8>

enter image description here

选项2]

^{pr2}$

相关问题 更多 >