Python Matplotlib叠加散点图 [英] Python matplotlib superimpose scatter plots

查看:1246
本文介绍了Python Matplotlib叠加散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python matplotlib.我想叠加散点图.我知道如何用命令叠加连续线图:

I am using Python matplotlib. i want to superimpose scatter plots. I know how to superimpose continuous line plots with commands:

>>> plt.plot(seriesX)
>>> plt.plot(Xresampl)
>>> plt.show()

但是它似乎与散布的工作方式不同.或者,可以将plot()与进一步指定线型的参数一起使用.如何进行? 谢谢

But it does not seem to work the same way with scatter. Or maybe using plot() with a further argument specifying line style. How to proceed? thanks

推荐答案

您只需调用scatter函数两次,matplotlib将为您叠加两个图.您可能要指定一种颜色,因为所有散点图的默认值为蓝色.这也许就是为什么您只看到一个情节的原因.

You simply call the scatter function twice, matplotlib will superimpose the two plots for you. You might want to specify a color, as the default for all scatter plots is blue. This is perhaps why you were only seeing one plot.

import numpy as np
import pylab as plt

X = np.linspace(0,5,100)
Y1 = X + 2*np.random.random(X.shape)
Y2 = X**2 + np.random.random(X.shape)

plt.scatter(X,Y1,color='k')
plt.scatter(X,Y2,color='g')
plt.show()

这篇关于Python Matplotlib叠加散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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