Objects of this class are usually created by the new_plotitem method of a ClawPlotAxes object.
The examples shown below are fragments of a typical setplot function which assume plotaxes is an instance of ClawPlotAxes.
The following attributes can be set by the user:
Type of plot desired, one of the following:
Directory to find data to be plotted. If None, then data comes from the outdir attribute of the parent ClawPlotData item.
If an integer, then this specifies which component of q to plot (with the Python convention that plot_var=0 corresponds to the first component).
If a function, then this function is applied to q on each grid to compute the variable var that is plotted. The signature is
The current_data object holds data from the current frame that can be used to compute the variable to be plotted.
A string or function that is to be executed after plotting this item. If a string, this string is executed using exec. If a function, it should be defined to have a single argument current_data.
A string or function that is to be executed after plotting this item on each grid. (There may be more than 1 grid in an AMR calculation.) If a string, this string is executed using exec. If a function, it should be defined to have a single argument “data”, [documentation to appear!]
def aftergrid(current_data): cd = current_data print "On grid number %s, xlower = %s, ylower = %s" \ % (cd.gridno, cd.xlower, cd.ylower)
would print out the grid number and lower left corner for each grid in a 2d computation after the grid is plotted.
If True, the grid mapping specified by the mapc2p attribute of the underlying ClawPlotData object should be applied to the grid before plotting.
If False, plotting of this object is suppressed.
The other attributes required depend on the plot_type, as summarized below:
Anything that is valid as a fmt group in the matplotlib plot command. For example:
Any matplotlib color, for example red can be specified as ‘r’ or ‘red’ or ‘[1,0,0]’ or ‘#ff0000’.
No extra attributes.
This gives a filled polygon between two curves using the matplotlib fill_between command.
as described above defines one curve,
defines the second curve for the fill_between command. Default is the zero function.
defines the where attribute of the fill_between command.
plotitem = plotaxes.new_plotitem(plot_type='1d_fill_between') plotitem.plot_var = 0 # means use q[:,0]
would produce a filled curve between y=q[:,0] and y=0.
plotitem = plotaxes.new_plotitem(plot_type='1d_fill_between') plotitem.plot_var = 0 # means use q[:,0] plotitem.plot_var2 = 1
would produce a filled curve between y=q[:,0] and y=q[:,1].
Example: In a 2d computation where the solution q[:,:,0] should be radially symmetric about (x,y)=(0,0), the following will result in a scatter plot of the cell values q[i,j,0] vs. the radius r(i,j):
def q0_vs_radius(current_data): # convert 2d (x,y,q) into (r,q) for scatter plot from numpy import sqrt x = current_data.x y = current_data.y r = sqrt(x**2 + y**2) q0 = current_data.var # the variable specified by plot_var # q0 = current_data.q[:,:,0] # would also work return r,q0 plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') plotitem.plot_var = 0 # use q[:,:,0] plotitem.plotstyle = 'o' # symbol not line is best for scatter plot plotitem.map_2d_to_1d = q0_vs_radius # the function defined above
See current_data for a description of the current_data argument.
If True, draw the grid lines on the plot. The attribute ‘amr_gridlines_show’ should be used for AMR computations to specify that gridlines should be shown on some levels and not others. See AMR Attributes.
If True, draw the edges of grids, mostly useful in AMR computations.
If a numpy array, the contour levels. If None, then the next three attributes are used to set the levels.
Number of contour levels
Minimum contour level
Maximum contour level
Colors of contour lines. Can be a single color such as ‘b’ or ‘#0000ff’, or a colormap.
As with other attributes (see AMR Attributes below), instead of contour_colors you can specify amr_contour_colors to be a list of colors (or colormaps) to use on each AMR level, e.g.:
amr_contour_colors = ['k','b','r']
to use black lines on Level 1, blue on Level 2, and red for all subsequent levels. This is useful since with the matplotlib contour plotter you will see both fine and course grid lines on top of one another in refined regions (Matplotlib lacks the required hidden line removal to blank out the lines from coarser grids easily. See also the next attributes.)
Show the contour lines only if this attribute is true. This is most commonly used in the form of the next attribute,
Determines whether to show the contour lines on each AMR level. Useful if you only want to view the lines on the finest grids.
Other keyword arguments for the contour command.
In general you should specify pcolor_cmin and pcolor_cmax to specify the range of q values over which the colormap applies. If they are not specified they will be chosen automatically and may vary from frame to frame. Also, if AMR is used, they may vary from grid to grid, yielding very confusing plots.
If True, a colorbar is added to the plot.
Many attributes listed above also have a second related attribute with the same name pre-pended with amr_. If this attribute is set, it should be a list whose elements are of the type specified by the original name, and the elements of the list will be used for different AMR refinement levels.
For example, the following commands:
plotitem = plotaxes.new_plotitem(plot_type='2d_contour') plotitem.contour_color = 'r'
will result in all contour lines being red on all levels of AMR. On the other hand:
plotitem = plotaxes.new_plotitem(plot_type='2d_contour') plotitem.amr_contour_color = ['k', 'b']
will result in contour lines on grids at level 1 being black and on grids of level 2 or higher being blue.
Note that if the list is shorter than the number of levels, the last element is used repeatedly.
If both attributes contour_color and amr_contour_color are set, only amr_contour_color is used.
A common use is to show grid lines only on coarse levels, not on finer levels, e.g.:
plotitem.amr_gridlines_show = [1,1,0]
will result in gridlines being shown only on levels 1 and 2, not on finer levels.