4

I am using Jupyter Notebooks as a teaching tool. I would like to build up a plot over several cells, adding new elements with each cell. It does not have to be the same plot. I don't see how to do this using the matplotlib "plot" family of functions. Is this possible and can someone post an example? Thanks

I am running my notebooks through Anaconda on a Mac.

Here is one cell that builds up individual lines in the plot (calling the field_line function to actually do the calculation.

def full_fl_3D(xfoot,yfoot,zfoot,c):
    fline = field_line(xfoot,yfoot,zfoot,-1.0) # calculate negative directed field line
    dipole = ax.plot(fline[0],fline[1],fline[2],c)
    fline = field_line(xfoot,yfoot,zfoot,1.0)  # calcualte positive directed field line
    dipole = ax.plot(fline[0],fline[1],fline[2],c)

This code generates the plot. I will want to add further to this without have to build the whole thing again.

%matplotlib notebook
fig = plt.figure(figsize=(8,8))
ax = plt.axes(projection='3d')
ax.set_xlim(-rmax, rmax);ax.set_ylim(-rmax, rmax);ax.set_zlim(-rmax, rmax) #set plot limits
spos = sphere(1)
ax.plot_surface(spos[0], spos[1], spos[2], color='b',alpha = 0.1)
# plot field lines starting 
nmax = 4
for i in range(2,8,2):
    xfoot = float(i)
    # plot the day - night plane
    c="c"
    full_fl_3D(xfoot,0,0,c);full_fl_3D(-xfoot,0,0,c)
    # plot the dawn-dusk plane
    c="y"
    full_fl_3D(0,xfoot,0,c); full_fl_3D(0,-xfoot,0,c);
swatchai
  • 17,400
  • 3
  • 39
  • 58
  • 1
    It requires a bit of a not-completely-standard Jupyter mode, by repeating the figure element stand-alone by itself. At least, that is one solution. See [this Q&A](https://stackoverflow.com/questions/45760693/how-to-overlay-plots-from-different-cells) for several options, with pointers to related Q&As. – 9769953 May 20 '19 at 12:19
  • 1
    Possible duplicate of [How do I show the same matplotlib figure several times in a single IPython notebook?](https://stackoverflow.com/questions/36265987/how-do-i-show-the-same-matplotlib-figure-several-times-in-a-single-ipython-noteb) – 9769953 May 20 '19 at 12:20

0 Answers0