Reputation: 41
I want to display a a series of graphs using a loop on one plot in a Jupyter cell, and then in another cell to display another plot. I plot this curves on the first plot using a loop:
def plotTrajectory(launchAngle):
[yRange, xRange] = setTrajectory(launchAngle)
plt.plot(yRange, xRange, label=launchAngle)
plt.ylabel('Vertical distance (m)')
plt.xlabel('Horiontal distance (m)')
plt.legend(bbox_to_anchor=(0.79, 1), title='Launch angle', loc='upper left', borderaxespad=0)
for i in launchAngles:
plotTrajectory(i)
and then try to plot another curve in a separate cell:
plt.plot(angleRange90, heights, label='Height')
plt.show()
and both appear on the same plot. Do I need plt.close() or plt.clf()? I'm sure this is simple and is a misunderstanding I have about how matplotlib works, but I can find nothing online regarding this specific case.
Upvotes: 1
Views: 70
Reputation: 802
Use plt.figure
:
def plotTrajectory(launchAngle):
[yRange, xRange] = setTrajectory(launchAngle)
plt.plot(yRange, xRange, label=launchAngle)
plt.ylabel('Vertical distance (m)')
plt.xlabel('Horiontal distance (m)')
plt.legend(bbox_to_anchor=(0.79, 1), title='Launch angle', loc='upper left', borderaxespad=0)
for i in launchAngles:
plotTrajectory(i)
plt.figure()
plt.plot(angleRange90, heights, label='Height')
plt.show()
Upvotes: 2