Class plot_base

class o2sclpy.plot_base

This class currently has two goals: (i) some simplifications for making plots using matplotlib and (ii) provide an interface for easily plotting o2scl objects with matplotlib.

addcbar(left, bottom, width, height, image='last', cmap='', **kwargs)

Documentation for o2graph command addcbar:

Add a color bar.

Command-line arguments: <left> <bottom> <width> <height> [kwargs]

Add a new colorbar or a colorbar from the most recently created image at the location specified by left, bottom, width and height. This command has a keyword image which specifies the image which the colorbar should refer to. If the image keyword is ‘last’, then the last density plot (e.g. from command den-plot) or two-dimensional histogram plot (e.g. from command hist2d-plot) is used. If the image keyword is ‘new’, then a colormap must be specified using the ‘cmap’ keyword and the color map is used to create the colorbar.

arrow(x1, y1, x2, y2, arrowprops, **kwargs)

Documentation for o2graph command arrow:

Plot an arrow.

Command-line arguments: x1 y1 x2 y2 <arrow properties> [kwargs]

Plot an arrow from \((x_1,y_1)\) to \((x_2,y_2)\). The arrow command uses axes.annotate() to generate an arrow with an empty string as the first argument to annotate(). The o2graph argument <arrow properties> is the python dictionary for the ‘arrowprops’ argument to annotate(). The arrowstyle and connectionstyle attributes should be listed along with other arrowprops attributes. Examples for arrowprops are:

* arrowstyle=->,connectionstyle=arc3 \
* arrowstyle=-|>,connectionstyle=arc,fc=red,ec=blue \
* arrowstyle=-|>,connectionstyle=arc,head_length=4.0,
  head_width=1.0 \
* arrowstyle=->,connectionstyle=arc3,head_length=4.0,
  head_width=1.0,rad=-0.1 \
* arrowstyle=fancy,connectionstyle=arc3,head_length=4.0,
  head_width=1.0,rad=-0.1 \

Summary for arrowstyle argument (angleB is renamed to as_angleB):

Name    Attributes \
-       None \
->      head_length=0.4,head_width=0.2 \
-[      widthB=1.0,lengthB=0.2,as_angleB=None \
|-      widthA=1.0,widthB=1.0 \
-|      head_length=0.4,head_width=0.2 \
<-      head_length=0.4,head_width=0.2 \
<|      head_length=0.4,head_width=0.2 \
fancy   head_length=0.4,head_width=0.4,tail_width=0.4 \
simple  head_length=0.5,head_width=0.5,tail_width=0.2 \
wedge   tail_width=0.3,shrink_factor=0.5 \

(note that fancy, simple or wedge require arc3 or angle3 connection styles)

Summary for connectionstyle argument (angleB is renamed to cs_angleB):

Name    Attributes \
* angle   angleA=90,cs_angleB=0,rad=0.0 \
* angle3  angleA=90,cs_angleB=0 \
* arc     angleA=0,cs_angleB=0,armA=None,armB=None,rad=0.0 \
* arc3    rad=0.0 \
* bar     armA=0.0,armB=0.0,fraction=0.3,angle=None \

See https://matplotlib.org/2.0.2/users/annotations.html for more. For example:

o2graph -xlimits 0 1 -ylimits 0 1.2 \
-arrow 0.2 0.2 0.8 0.2 \
arrowstyle='->',connectionstyle=arc3 \
-arrow 0.2 0.4 0.8 0.4 \
arrowstyle='-|>',connectionstyle=arc,fc=red,ec=blue \
-arrow 0.2 0.6 0.8 0.6 \
arrowstyle='-|>',connectionstyle=arc,head_length=4.0,head_width=1.0 \
-arrow 0.2 0.8 0.8 0.8 \
arrowstyle='->',connectionstyle=arc3,head_length=4.0,head_width=1.0,rad=-0.1 \
-arrow 0.2 1.0 0.8 1.0 arrowstyle=fancy,connectionstyle=arc3,head_length=4.0,head_width=1.0,rad=-0.1 \
-show
ax_left_panel = 0

Left panel axis for the editor

ax_right_panel = 0

Right panel axis for the editor

axes = 0

Current axis object

axes_dict = {}

Dictionary of axis objects (used by subplots() and selax() to manage multiple axis objects)

bottom_margin = 0.12

Bottom plot margin (default 0.12)

canvas()

Documentation for o2graph command canvas:

Create a plotting canvas.

Command-line arguments: (No arguments.)

Create an empty plotting canvas. For example ‘o2graph -canvas -show’. Typically, ‘o2graph’ creates the canvas automatically when the first object is plotted so explicitly using this command is unnecessary.

This function creates a default figure using default_plot() and axis object using the xtitle and ytitle for the axis titles and xlo, xhi, ylo, and yhi for the axis limits.

canvas_flag = False

If True, then the figure and axes objects have been created (default False)

cmap(cmap_name, col_list=[])

Documentation for o2graph command cmap:

Create a continuous colormap or list colormaps.

Command-line arguments: <cmap name> <color 1> <color 2> [color3]... or <cmap name> "sharp" <color 1> <color 2> [color3 color4]... or list or plot [filename]

In the first form, this command creates a new color map named <cmap name> which consists of equal-sized gradients between the specified list of at least two colors. In the second form, when the keyword sharp is given, the color map consists of gradients between each pair of colors with a sharp transition between successive pairs.

Matplotlib colors, (r,g,b) colors, [r,g,b,a] colors, and xkcd colors are all allowed. For example:

o2graph -cmap c forestgreen "[0.5,0.5,0.7,0.5]" \
"xkcd:light red" -create table3d x grid:0,40,1 y grid:0,40,1 \
z "x+y" -den-plot z cmap=c -show

or:

o2graph -cmap c sharp "(0.5,0.5,0.7)" "xkcd:light red" \
green "(0,0,0)" -create table3d x grid:0,40,1 y grid:0,40,1 \
z "x+y" -den-plot z cmap=c -show

In the third form, the cmap command lists all of the available colormaps. Finally, in the fourth form, the cmap command plots all available colormaps, optionally storing this plot in a file, e.g.:

o2graph -cmap plot cmap_plot.png

To get more information on the available colors, see:

o2graph -colors list 
colbar = False

If True, then include a color bar for density plots (default False)

colors(args=[])

Documentation for o2graph command colors:

Show color information.

Command-line arguments: list or plot [filename] or near <color> [filename] or xkcd.

The colors command outputs or plots information about matplotlib colors.

If the “list” argument is given, then the 8 base colors and their RGB definitions are output and then 148 CSS4 colors (which include the 8 base colors) are output along with their associated hexadecimal values.

If the “plot” argument is given, then the 148 CSS4 colors are plotted in a matplotlib figure. If an additional filename argument is specified, the figure is written to the specified file.

If the “near” argument is given, then the 80 colors closest to <color> are plotted in a matplotlib figure. If an additional filename argument is specified, then the figure is written to the specified file. To determine which colors are “nearest”, the sum of the absolute values of the differences in the RGB values are used.

Finally, if the “xkcd” argument is given, then all 949 xkcd colors are listed along with their HTML hexadecimal RBG values.

Color arguments in o2graph supports the (r,g,b) format, the [r,g,b,a] format, the HTML format, the grayscale single-value format, and the XKCD colors. For (r,g,b) colors, parentheses must be used, and the r, g, and b numbers should be from 0.0 to 1.0. For [r,g,b,a] colors, square brackets must be used and the r, g, b, and a numbers should be from 0.0 to 1.0. The HTML format is #RRGGBB where RR, GG, and BB are two-digit hexadecimal values.

den_plot(args, **kwargs)

Create a density plot from a matrix, a slice of a table3d object, or a hist_2d object.

The argument list args can be of the form [numpy matrix] or [table3d,slice name] or [hist_2d].

The documentation for the o2graph den-plot command is in the docstring for o2sclpy.o2graph_plotter.den_plot_o2graph().

If a cmyt colormap is used, then the cmyt Python package is required.

den_plot_rgb(table3d, slice_r, slice_g, slice_b, make_png='', renorm=False, **kwargs)

Density plot from a table3d object using three slices to specify the red, green, and blue values.

If make_png is non-empty, then a .png is created, with no axes, and stored in a file given the specified name. In the case a .png file is to be created and renorm is True, then the data is renormalized to ensure the minimum is 0 and the maximum is 255. Otherwise, the data is set to 0 if it is less than 0 and set to 255 when it is greater than 255.

The documentation for the o2graph den-plot-rgb command is in the docstring for o2sclpy.o2graph_plotter.den_plot_rgb_o2graph().

If the make_png keyword argument is specified, then Pillow Python package is required.

editor = False

If true, open the GUI editor (experimental)

ellipse(x, y, w, h, angle=0, **kwargs)

Documentation for o2graph command ellipse:

Plot an ellipse.

Command-line arguments: <x> <y> <w> <h> [angle] [kwargs]

Plot an ellipse centered at (x,y) with width w and height h, optionally rotated by the specified angle. By default, the ellipse has no border, but the linewidth (‘lw’) and edgecolor kwargs can be used to specify one if desired. Some useful kwargs are alpha, color, edgecolor (ec), facecolor (fc), fill, hatch, linestyle (ls), linewidth (lw). For example:

o2graph -ellipse 0.5 0.5 0.8 0.2 45 \
fc='#ccccff',ec=black,lw=2,hatch='|||',ls=':' -show
error_point(xval, yval, err1=None, err2=None, err3=None, err4=None, **kwargs)

Documentation for o2graph command error-point:

Plot a single point with errorbars.

Command-line arguments: <x> <y> [<x err> <yerr>] or [<x lo> <x hi> <y lo> <y hi>]

Some useful kwargs for the error-point command are:

keyword    description                       default value \
ecolor     error bar color                   None \
capsize    cap size in points                None \
barsabove  plot error bars on top of point   False \
lolims     y value is lower limit            False \
uplims     y value is upper limit            False \
xlolims    x value is lower limit            False \
xuplims    x value is upper limit            False \
errorevery draw error bars on subset of data 1 \
capthick   thickness of error bar cap        None

See also errorbar for for plotting columns from a table object

fig = 0

Figure object

fig_dict = ''

A dictionary which refers to the figure and axis defaults

font = 16

Font size text objects and axis titles (default 16)

get(name)

Output the value of parameter named name. The documentation for the o2graph command get is given in O₂scl.

inset(left, bottom, width, height, **kwargs)

Documentation for o2graph command inset:

Add a new set of axes

Command-line arguments: <left> <bottom> <width> <height> [kwargs]

This command creates a new set of axes, adds the new axes to the list of axes, and sets the new axes as the current. The values <left>, <bottom>, <width>, and <height> refer to a normalized coordinate system where the lower-left hand corner of the figure is (0,0) and the upper-right hand corner is (1,1). The axes object is named ‘inset0’ for the first inset, then ‘inset1’, and so on. For example:

o2graph -inset 0.5 0.2 0.4 0.4 -selax main \
-line 100 100 900 900 -selax inset0 \
-line 0.1 0.9 0.9 0.1 -show
last_image = 0

The last image object created (used for addcbar())

left_margin = 0.14

Left plot margin (default 0.14)

line(x1, y1, x2, y2, **kwargs)

Documentation for o2graph command line:

Plot a line from \((x_1,y_1)\) to \((x_2,y_2)\)

Command-line arguments: <x1> <y1> <x2> <y2> [kwargs]

Plot a line from (x1,y1) to (xy,y2). Some useful kwargs are color (c), dashes, linestyle (ls), linewidth (lw), marker, markeredgecolor (mec), markeredgewidth (mew), markerfacecolor (mfc), markerfacecoloralt (mfcalt), markersize (ms). For example:

o2graph -line 0.05 0.05 0.95 0.95 \
lw=2,marker='+',ms=10,c=xkcd:'light purple' -show
link2 = 0

Link to the O2scl library DLL

logx = False

If True, then use a logarithmic x axis (default False)

logy = False

If True, then use a logarithmic y axis (default False)

logz = False

If True, then use a logarithmic z axis (default False)

make_png(table3d, slice_r, slice_g, slice_b, fname, **kwargs)

Create png from a table3d object using three slices to specify the red, green, and blue values.

The documentation for the o2graph make-png command is in the docstring for o2sclpy.o2graph_plotter.make_png_o2graph().

This command requires the Pillow Python package.

modax(**kwargs)

Documentation for o2graph command modax:

Modify current axes properties.

Command-line arguments: [kwargs]

The axis properties which can be modified are:

Property         Values       Description \
alpha            float>0      alpha value for region inside axes \
labelsize        float>0      font size for labels \
x_loc            b,t,tb       placement of x-axis (bottom, top, or both) \
x_major_loc      float>0      linear increment for x-axis major ticks \
x_minor_loc      float>0      linear increment for x-axis minor ticks \
x_minor_tick_dir in,out,inout direction of x-axis minor ticks \
x_minor_tick_len float>0      length of x-axis minor ticks \
x_minor_tick_wid float>0      width of x-axis minor ticks \
x_tick_dir       in,out,inout direction of x-axis major ticks \
x_tick_len       float>0      length of x-axis major ticks \
x_tick_wid       float>0      width of x-axis major ticks \
x_visible        T/F          set x-axis visible or invisible \
y_loc            l,r,lr       placement of y-axis (left, right, or both) \
y_major_loc      float>0      linear increment for x-axis major ticks \
y_minor_loc      float>0      linear increment for x-axis minor ticks \
y_minor_tick_dir in,out,inout direction of y-axis minor ticks \
y_minor_tick_len float>0      length of y-axis minor ticks \
y_minor_tick_wid float>0      width of y-axis minor ticks \
y_tick_dir       in,out,inout direction of y-axis major ticks \
y_tick_len       float>0      length of y-axis major ticks \
y_tick_wid       float>0      width of y-axis major ticks \
y_visible        T/F          set y-axis visible or invisible \
new_cmaps()

Add a few new colormaps. This function is called by plot_base::__init__().

This function adds the colormaps ‘jet2’ ‘pastel2’, ‘reds2’, ‘greens2’, and ‘blues2’.

plot(args, **kwargs)

Plot a two-dimensional set of data

The argument list args can be of the form [table,column name 1, column name 2] or [table_units,column name 1,column name 2] or [shared_ptr_table_units, column name 1, column name 2] or [hist] or [vec_vec_double, column index 1] or [vec_vec_double, column index1, column index 2]. Otherwise, args[0] and args[1] are interpreted as arrays to be directly sent to the matplotlib.pyplot.plot() function.

The documentation for the o2graph plot command is in the docstring for o2sclpy.o2graph_plotter.plot_o2graph().

point(xval, yval, **kwargs)

Documentation for o2graph command point:

Plot a single point.

Command-line arguments: <x> <y> <kwargs>

Plot a single point. Some useful kwargs are color, marker, markeredgecolor (mec), markeredgewidth (mew), and markersize (ms). Note that the ‘marker’ keyword argument to specify the marker type must be specified. For example:

o2graph -xlimits 0 1 -ylimits 0 1 -point 0.5 0.5 \
marker='o',ms=10,c='xkcd:sea green',mec=blue,mew=2 -show

or:

o2graph -xlimits 0 1 -ylimits 0 1 -point 0.5 0.5 \
marker='$\int_0^{\infty}x^2~dx$',ms=300,c=green,mec=red -show

To list the marker types, use:

o2graph -help markers

or:

o2graph -help markers-plot
rect(x1, y1, x2, y2, angle=0, **kwargs)

Documentation for o2graph command rect:

Plot a rectangle.

Command-line arguments: <x1> <y1> <x2> <y2> [angle] [kwargs]

Plot a rectange from (x1,y1) to (xy,y2) with rotation angle <angle>. By default, the rectangle has no border, but the linewidth (‘lw’) and edgecolor kwargs can be used to specify one if desired. Some useful kwargs are alpha, color, edgecolor (ec), facecolor (fc), fill, hatch (‘/’, ‘', ‘|’, ‘-’, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’), linestyle (ls), linewidth (lw). In order to specify keyword arguments, an angle must be also specified.

For example:

o2graph -xlimits 0 0.8 -ylimits 0 0.6 \
-text 0.55 0.35 "blah" -rect 0.2 0.2 0.5 0.5 \
-rect 0.3 0.3 0.7 0.4 0 \
fc=green,alpha=0.5,ls=-.,ec='xkcd:burnt orange',lw=2,hatch='///' \
-show
right_margin = 0.04

Right plot margin (default 0.04)

rt_ticks = False

If true, include ticks on right side and top (default False)

save(filename)

Save plot to file named filename, using the extension to set the file type. If the verbose parameter is greater than zero, then this function prints the filename to the screen.

selax(name='')

Documentation for o2graph command selax:

Select an axis from the current list of axes

Command-line arguments: [name]

Select which axis to use for subsequent plotting commands. If [name] is not specified, then the names of all current axes objects are listed.

set(name, value)

Set the value of parameter named name to value value. The documentation for the o2graph command set is given in O₂scl.

show()

Documentation for o2graph command show:

Show the current plot.

(No arguments.)

Show the current plot on the screen and begin the graphical user interface. When the editor is not enabled this just runs matplotlib.pyplot.show().

subplots(nr, nc=1, **kwargs)

Documentation for o2graph command subplot:

Create subplots.

Command-line arguments: <nrows> <ncols> [kwargs]

Create a grid of <nrows> by <ncols> subplots. The kwargs currently supported are ‘sharex=True|False’, and ‘sharey=True|False’. Subplots are named ‘subplot0’, ‘subplot1’, … with the indexes moving to the right before proceeding to the next row.

This command allows o2graph to track the figure and axis objects so the user can easily refer to them.

text(tx, ty, textstr, **kwargs)

Documentation for o2graph command text:

Plot text in the data coordinates.

Command-line arguments: <x> <y> <text> [kwargs]

The text command plots text in the data coordinates defined by the current axes with the font size determined by the value of the parameter font. LaTeX is used for text rendering by default, but this setting can be changed using, e.g. ‘-set usetex 0’. Some useful kwargs are fontfamily (‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, ‘monospace’), fontstyle (‘normal’, ‘italic’, ‘oblique’), fontsize, color, backgroundcolor, rotation, horizontalalignment (ha), and verticalalignment (va). Note that you must disable LaTeX rendering to change fontfamily or fontstyle.

If <x> or <y> are strings, then they are passed through the eval() function and converted to floating-point numbers. A figure and axes are created using o2sclpy.plot_base.canvas(), if necessary.

textbox(tx, ty, strt, boxprops='', **kwargs)

Documentation for o2graph command textbox:

Plot a box with text.

Command-line arguments: <x1> <y1> <text> [bbox properties] [kwargs]

Plot text <text> and a box at location <x1> <y1>. For example:

textbox 0.5 0.5 "$ f(x) $" "alpha=0.8,facecolor=white"

This command uses the standard axis text function, but adds a bounding box with the specified properties. Typical bbox properties are boxstyle (Circle, DArrow, LArrow, RArrow, Round, Round4, Roundtooth, Sawtooth, Square), alpha, color, edgecolor (ec), facecolor (fc), fill, hatch ({‘/’, ‘’, ‘|’, ‘-’, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’}), linestyle (ls), and linewidth (lw). The keyword arguments are for the text properties, and follow those of the text command.

ticks_in = False

If true, move the ticks inside (default False)

top_margin = 0.04

Top plot margin (default 0.04)

ttext(tx, ty, textstr, **kwargs)

Documentation for o2graph command ttext:

Plot text in window coordinates [(0,0) to (1,1)].

Command-line arguments: <x> <y> <text> [kwargs]

The ttext command plots text in the window coordinates [typically (0,0) to (1,1)] with the font size determined by the value of the parameter font. LaTeX is used for text rendering by default, but this setting can be changed using, e.g. ‘-set usetex 0’. Some useful kwargs are fontfamily, fontstyle, fontsize, color, backgroundcolor, rotation, horizontalalignment (ha), and verticalalignment (va). Specifying fontsize overrides the font parameter. Note that you must disable LaTeX rendering to change fontfamily or fontstyle.

If <x> or <y> are strings, then they are passed through the eval() function and converted to floating-point numbers. A figure and axes are created using o2sclpy.plot_base.canvas(), if necessary.

usetex = True

If true, then use LaTeX for text objects (default True)

verbose = 1

Verbosity parameter (default 1)

xhi = 0

Upper limit for x axis (default 0)

xlimits(xlo, xhi)

Documentation for o2graph command xlimits:

Set the x-axis limits

Command-line arguments: <x low> <x high>

The xlimits command sets xlo and xhi to the specified limits and sets xset to True. If a plotting canvas is currently open, then the x-limits on the current axis are modified. Future plots are also plot with the specified x-limits. If <low> and <high> are identical then xset is set to False and the x limits are automatically set by matplotlib.

xlo = 0

Lower limit for x axis (default 0)

xset = False

If True, then the x axis limits have been set (default False)

xtitle(textstr)

Add a title for the x-axis

yhi = 0

Upper limit for y axis (default 0)

ylimits(ylo, yhi)

Documentation for o2graph command ylimits:

Set the y-axis limits

Command-line arguments: <y low> <y high>

The ylimits command sets ylo and yhi to the specified limits and sets yset to True. If a plotting canvas is currently open, then the y-limits on the current axis are modified. Future plots are also plot with the specified y-limits. If <low> and <high> are identical then yset is set to False and the y limits are automatically set by matplotlib.

ylo = 0

Lower limit for y axis (default 0)

yset = False

If True, then the y axis limits have been set (default False)

ytitle(textstr)

Add a title for the y-axis

zhi = 0

Upper limit for z axis (default 0)

zlimits(zlo, zhi)

Documentation for o2graph command zlimits:

Set the z-axis limits

Command-line arguments: <z low> <z high>

The zlimits command sets zlo and zhi to the specified limits and sets zset to True. If <low> and <high> are identical then zset is set to False.

zlo = 0

Lower limit for z axis (default 0)

zset = False

If True, then the z axis limits have been set (default False)