Issue
I'm trying to plot two different graphs in different jupyter cells. They are given by:
import matplotlib.pyplot as plt
%matplotlib notebook
# Plotting background functions
nr_int = len(p)
plt.title("Background functions")
plt.grid()
plt.plot(r, m, label = "m")
plt.plot(r, bare, label = "naked")
plt.plot(r[:nr_int], p, label = "p")
plt.plot(r[:nr_int], rho, label = "rho")
plt.xlim(0, 2* radius)
plt.legend()
and
# Plotting the initial conditions
plt.title("Initial Conditions")
plt.grid()
plt.plot(r, F, label = "F")
plt.plot(r, S, label = "S")
plt.plot(r, H, label = "H")
plt.plot(r, Hamiltevol[0], label = "Hamiltonian constraint")
plt.xlim(3.87, 4.8)
plt.legend()
When I rotate the first cell, the graph is generated correctly. However, when I run the next cell, the output is <matplotlib.legend.Legend at 0x26d13362d60>
and the plot appears in the output of the top cell, that is, the graphs are superimposed. How can I avoid this?
Solution
Whenever you need a new plot, run plt.figure()
before your plot commands, for example before plt.title
.
Answered By - Davide_sd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.