In Jupyter I want to first plot via plt.scatter
and then via plt.plot
but I want to show both on the same plot/figure.
I.e. I want the curve from plt.plot
to appear visually
on the same plot as the scatter plot.
Is that possible and how?
In Jupyter I want to first plot via plt.scatter
and then via plt.plot
but I want to show both on the same plot/figure.
I.e. I want the curve from plt.plot
to appear visually
on the same plot as the scatter plot.
Is that possible and how?
Here is a very small example:
f, ax = plt.subplots(1, 1, figsize=(5, 5))
ax.plot(x, y1)
ax.plot(x, y2)
You can replace one of the plots with a scatter plot, add others, .. In this case, ax is an axes instance however, if you specify other parameters for subplots, e.g. plt.subplots(2, 1), ax will be an iterable (numpy array) of axes instances. Thus you will need to access the ax on which you want to plot:
ax[1].plot() or if 2d ax[1, 1].plot()
Finally, the method ax.plot()
takes basically the same argument than plt.plot()
. However the syntax to set the title
, the xlim
, the ylim
, the xlabel
, the ylabel
, is slightly different.
Example in jupyter: