'Python matplotlib superimpose scatter plots
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()
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
Solution 1:[1]
If you wish to continue using plot you can use the axis object returned by subplots:
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)
fig, ax = plt.subplots()
ax.plot(X,Y1,'o')
ax.plot(X,Y2,'x')
plt.show()
Solution 2:[2]
Here's an other way:
X = np.linspace(0,5,100)
Y1 = X + 2*np.random.random(X.shape)
Y2 = X**2 + np.random.random(X.shape)
plt.plot(Y1, label = "Y1")
plt.plot(Y2, label = "Y2")
plt.tight_layout()
plt.xlabel("X")
plt.ylabel("Y")
plt.legend()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gadi Oron |
| Solution 2 | Erick Audet |
