Search code examples
pythonmatplotlibipythonvisualizationscientific-computing

"Replot" a matplotlib inline plot in a IPython notebook


if I work on a matplotlib inline plot in an ipython notebook like this:

figure = plt.figure()
ax = figure.gca(projection="3d")
graph = np.empty([len(thetaYield),3])
for g, tY in zip(graph, thetaYield):
    sample =  HWtoPS(xiYield, rhoYield, tY)
    g[...] = sample[:]
ax.plot(graph[:,0],graph[:,1], graph[:,2])
plt.show()

the plot is drawn inline in my notebook as it intended.

Now I want to add to add some data to this plot:

principalStress, vectors = eig(sigma)
ax.scatter(principalStress[0], principalStress[1], principalStress[2])
plt.show()

no error, but also no plot is drawn.

I expected to get an "updated" version of my plot with the additional data.

How can this be done?


Solution

  • A: This can be done at a cost of changed matplotlib Renderer

    Currently, this cannot be done for the IPython "inline" graphs, however, if you opt to change a Renderer part of the matplotlib framework, to another one, the limitation of a singleton call of the .show() method does not hurt and you can ex post modify the object's content and it gets re-processed by the Renderer.

    Simply:

    add a directive ( IPython magic) %matplotlib qt

    &

    use additional matplotlib calls as you expect 'em to modify/update the figure object

    ( I love using this both during prototyping phases & for interactive 3D-viewing of complex data visualisations (which I heavily miss in notebook's "inline"s) ) 3D-view by matplotlib BTW: do you have about any methodology, which would allow to store a matplotlib 3D-view plot, as a complete, state-full container, that can be sent to some other user for her/his "load" and UI-interactive review? Would be great to hear about any such working :o)