Note that there are some explanatory texts on larger screens.

plurals
  1. POContinuous 3D plotting (i.e. figure update) using python-matplotlib?
    primarykey
    data
    text
    <p>I have a simulation which calculates surface data for each iteration of the simulation. I would like to continuously plot that data as a surface plot to the same window (updating the plot in each iteration) in order to see how it evolves and to check the algorithm.</p> <p>My Idea was to create a class that would initialize the window/plot and then redraw to that window from inside the simulation loop. Here is the class I came up with:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import LinearLocator, FixedLocator, FormatStrFormatter import matplotlib matplotlib.interactive( False ) class plot3dClass( object ): def __init__( self, systemSideLength, lowerCutoffLength ): self.systemSideLength = systemSideLength self.lowerCutoffLength = lowerCutoffLength self.fig = plt.figure() self.ax = self.fig.add_subplot( 111, projection='3d' ) self.ax.set_zlim3d( -10e-9, 10e9 ) X = np.arange( 0, self.systemSideLength, self.lowerCutoffLength ) Y = X self.X, self.Y = np.meshgrid(X, Y) self.ax.w_zaxis.set_major_locator( LinearLocator( 10 ) ) self.ax.w_zaxis.set_major_formatter( FormatStrFormatter( '%.03f' ) ) heightR = np.zeros( self.X.shape ) self.surf = self.ax.plot_surface( self.X, self.Y, heightR, rstride=1, cstride=1, cmap=cm.jet, linewidth=0, antialiased=False ) #~ self.fig.colorbar( self.surf, shrink=0.5, aspect=5 ) plt.show() def drawNow( self, heightR ): self.surf = self.ax.plot_surface( self.X, self.Y, heightR, rstride=1, cstride=1, cmap=cm.jet, linewidth=0, antialiased=False ) plt.draw() # redraw the canvas time.sleep(1) </code></pre> <p>The problem I have with this code, is that the code stops at the 'plt.show()' and only continues, when I close the plot-window. Also I am not sure if the calls of 'self.ax.plot_surface( ... )' and 'plt.draw()' would update the figure as I would like it.</p> <p>So is this class the right direction?</p> <p>If yes: What modifications are needed?</p> <p>If not: Could somebody please give me advice how to achieve what I want?</p> <p>I realize that this problem might seem trivial to others, but I (honestly) did spend the whole day yesterday on Google and trying and I'm at a loss...</p> <p>Any help would greatly appreciated, so that I can get back to my actual work.</p> <p>Tanks alot in advance.</p> <p>As a reference:</p> <p>I also found the following code which does, what I want, but it is in 2D, so it does not help me directly:</p> <pre><code>from pylab import * import time ion() tstart = time.time() # for profiling x = arange(0,2*pi,0.01) # x-array line, = plot(x,sin(x)) for i in arange(1,200): line.set_ydata(sin(x+i/10.0)) # update the data draw() # redraw the canvas print 'FPS:' , 200/(time.time()-tstart) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload