For usage see Using setplot.py to specify the desired plots and Plotting examples in 1d.
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.
See also
The following attributes can be set by the user:
Type of plot desired, one of the following:
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.
For example:
def afteritem(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!]
For example:
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.
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:
No extra attributes.
This gives a filled polygon between two curves using the matplotlib fill_between command.
defines the where attribute of the fill_between command.
Example:
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.
Example:
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.
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.)
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.