PlotBasem¶
-
class
decida.PlotBasem.
PlotBasem
(parent=None, use_matplotlib=True)¶ Bases:
decida.ItclObjectx.ItclObjectx
synopsis:
2-dimensional plot base class.
PlotBasem is a base class for 2-D plotting classes. It provides a central canvas for displaying the plot, controls for changing aspects of the plot, point display boxes, and mouse commands for zooming, annotating, and determining line-parameters.
PlotBasem provides its own vector (Hershey) fonts, which can be rotated, slanted, and sized. The tk canvas does provide a font set, but with some limitations.
PlotBasem is inherited by XYplotm, Histogramx, Contourx, and Smithchartx.
configuration options:
verbose (bool, default=False)
enable/disable verbose modetitle (str, default=””)
main titlextitle (str, default=””)
x-axis titleytitle (str, default=””)
y-axis titleplot_height (str, default=”10i” for MacOS, else “6i”)
Height of plot window (Tk inch or pixel specification)plot_width (str, default=”10i” for MacOS, else “6i”)
Width of plot window (Tk inch or pixel specification)plot_background (str, default=”GhostWhite”)
Background color of plot windowlegend_background (str, default=”AntiqueWhite2”)
Background color of legend- colors (list of str, default=[
- “blue”, “red”, “green”, “orange”, “cyan”, “brown”, “black”, “blue violet”, “cadet blue”, “dark cyan”, “dark goldenrod”, “dark green”, “dark magenta”, “dark olive green”, “dark orange”, “dark red”, “dark slate blue”, “dark slate gray”, “dodger blue”, “forest green”, “steel blue”, “sienna”])
list of colors for curves. Used to populate color menu, and to specify curve colors in scripted “command” option in derived classes.
- symbols (list of str, default = [
- “none”, “dot”, “square”, “diamond”, “triangle”, “itriangle”, “dash”, “pipe”, “plus”, “cross”, “spade”, “heart”, “diam”, “club”, “shamrock”, “fleurdelis”, “circle”, “star”])
list of symbols for curves. Used to populate symbol menu, and to specify curve symbols in scripted “command” option in derived classes.
ssizes (list of float, default = [0.01])
list of symbol sizes for curves. Used to specify curve symbol sizes in scripted “command” option in derived classes.wlines (list of int, default = [1])
list of line widths for curves. Used to specify curve line widths in scripted “command” option in derived classes.traces (list, default = [“increasing”])
list of traces for curves. each trace can be one of: “increasing”, “decreasing”, or “both”. Used to specify curve trace directions in scripted “command” option in derived classes.xaxis (str, default=”lin”)
linear or logarithmic axis: “lin” or “log”yaxis (str, default=”lin”)
linear or logarithmic axis: “lin” or “log”xmin (float, default=0.0)
xaxis minimumxmax (float, default=0.0)
xaxis maximumymin (float, default=0.0)
yaxis minimumymax (float, default=0.0)
yaxis maximumgrid (bool, default=True)
if true, show grid on plotlegend (bool, default=True)
if true, show legend on plotpostscript (bool, default=False)
if true, generate a PostScript file.postscript_file (str, default=”plot.ps”)
name of PostScript file to plot towait (bool, default=False)
wait in main-loop until window is destroyed.destroy (bool, default=False)
destroy main window after it has been displayed. useful for displaying, generating PostScript, then destroying window.protected methods:
- _plot_curves
- _settings_cmd
public methods:
- public methods from ItclObjectx
-
add_curve
(datobj, xcol, ycol, start=False, autoscale_x=False, autoscale_y=True, strict=False, dname=None, lstate=True, sstate=True, color=None, symbol=None, ssize=None, wline=None, trace=None)¶ add a curve.
arguments:
datobj (Data object handle)
data object supplying points to add to curve.xcol (str)
x column name.ycol (str)
x column name.start (bool, default=False)
modify x, y titles if this is the first and only curve.autoscale_x (bool, default=False)
widen x-axis to fit all curves. if strict, narrow x-axis to minimum and maximum of all curves.autoscale_y (bool, default=True)
widen y-axis to fit all curves. if strict, narrow y-axis to minimum and maximum of all curves.strict (bool, default=False)
if false, rescale and redraw only if current plot limits are smaller than minimum and maximum of all curvesdname (str, default=None)
specify data name. if not specified, dname = data_1.lstate (bool, default=True)
specify line-state.sstate (bool, default=true)
specify symbol-state.color (str, default=None)
specify curve color. if not specified, chooses next color in color list.symbol (str, default=None)
specify curve symbol. if not specified, chooses next symbol in symbol list. if symbol list wasn’t configured, then symbol=none.ssize (float, default=None)
specify curve symbol size. if not specified, chooses next symbol size in symbol size list.wline (float, default=None)
specify curve line width. if not specified, chooses next line width in line width list.trace (str, default=None)
specify curve trace. if not specified, chooses next trace in trace listresults:
- Registers a new curve with a curve id in the format:
- <data_name>_:_<ycol>_vs_<xcol> If data_name is undefined, it is set to “data_1”
- Plot is re-drawn with the new curve.
- New curve is selected as the current curve.
-
autoscale
(autoscale_x=False, autoscale_y=True, strict=False, redraw=False)¶ find limits and autoscale plot.
arguments:
autoscale_x (bool, default=False)
widen x-axis to fit all curves. if strict, narrow x-axis to minimum and maximum of all curvesautoscale_y (bool, default=True)
widen y-axis to fit all curves. if strict, narrow y-axis to minimum and maximum of all curvesstrict (bool, default=False)
if false, rescale and redraw only if current plot limits are smaller than minimum and maximum of all curvesredraw (bool, default=False)
if true, do redraw for any case of limit comparisonsresults:
- The plot is re-drawn with the new limits.
-
begin_stretch
(mode, func, u, v)¶ mouse down call-back.
arguments:
mode (str)
mode string: one of
- “zoom” : zoom in to window
- “delete” : delete labels within window
- “report” : report line-parameters
- “label” : annotate plot
func (function)
function to call on end_stretchu, v (int)
canvas coordinatesresults:
- Registers the stretch function, mode, and beginning coordinates.
- Updates the coordinate display.
-
continue_stretch
(u, v)¶ mouse movement after mouse down call-back.
arguments:
u, v (int)
canvas coordinatesresults:
- Redraws rectangle or line, depending on the stretch operation.
- Updates the coordinate display.
-
current_curve
(curve=None)¶ return the current curve.
results:
- Returns the current curve id.
-
curve_attributes
(curve)¶ return curve attributes.
arguments:
curve (str)
The curve id is in the format (see add_curve): <data_name>_:_<ycol>_vs_<xcol> If data_name is undefined, it is set to “data_1”results:
Returns a list of curve attributes in the Dictionary V:
- V[“dname”] = data name (str)
- V[“xname”] = x-column name (str)
- V[“yname”] = y-column name (str)
- V[“color”] = curve color (str)
- V[“symbol”] = curve symbol (str)
- V[“ssize”] = curve symbol size (int)
- V[“wline”] = curve line-width (int)
- V[“trace”] = trace direction (str) (“increasing”, “decreasing”, or “both”)
- V[“lstate”] = line display state (bool)
- V[“sstate”] = symbol display state (bool)
-
curves
()¶ return list of curves.
results:
- Returns the list of curve id’s in the plot.
-
delete_curve
(curve, redraw=True)¶ delete a curve.
arguments:
curve (str)
label of curve to delete. curve labels appear in the curve menu. the label is in the format <data_name>_:_<ycol>_vs_<xcol> where data_name is the name of the data object and xcol and ycol are the x and y column names in the curve.redraw (bool, default=True)
if True, redraw plot after deleting curveresults:
- The specified curve is de-registered.
- If redraw is True, redraw the Plot.
-
end_stretch
(u, v)¶ mouse up call-back.
arguments:
u, v (int)
canvas coordinatesresults:
- Calls the registered stretch function with the two canvas endpoints defined by begin_stretch and end_stretch.
- Updates the coordinate display.
-
limits
()¶ return plot limits.
results:
- returns a list of the current plotting limits: [xmin, xmax, ymin, ymax]
-
plot_annotate
(shape, text, x1, y1, x2, y2, tag)¶ add a line (or an arrowed line) to a curve with a label.
arguments:
shape (str)
shape to draw on the plot. One of:
- NONE : no shape.
- LINE : line segment between two enpoints.
- RECTANGLE : rectangle using two endpoints.
- FILLED-RECTANGLE : filled rectangle using two endpoints.
- ARROW-TO : arrow from 1st point with arrow on 2nd.
- ARROW-FROM : arrow from 2nd point with arrow on 1st.
- ARROW-BOTH : arrow to both points.
text (str)
text to draw on the plot.x1, y1, x2, y2 (float)
x and y coordinates cooresponding to the window where the plot is to be annotated.tag (str)
tk canvas tag to assign to the annotation.results:
- Display a dialog for the user to select text or shapes to annotate the plot.
-
plot_annotate_dialog
(x1, y1, x2, y2)¶ add a line (or an arrowed line) to a curve with a label.
arguments:
x1, y1, x2, y2 (float)
x and y coordinates cooresponding to the window where the plot is to be annotated.results:
- Display a dialog for the user to select text or shapes to annotate the plot.
-
plot_st_uv
(s, t)¶ convert scaled coordinates (0, 1, 0, 1) to canvas coordinates.
arguments:
s, t (float)
x, y coordinates in scaled domain. In the scaled domain, every point on the canvas is mapped to the window smin, smax = 0.0, 1.0 and tmin, tmax = 0.0, 1.0results:
- return canvas coordinates u, v
-
plot_st_xy
(s, t)¶ convert scaled coordinates (0, 1, 0, 1) to x, y coordinates
arguments:
s, t (float)
x, y coordinates in scaled domain. In the scaled domain, every point on the canvas is mapped to the window smin, smax = 0.0, 1.0 and tmin, tmax = 0.0, 1.0results:
- return x, y coordinates x, y
-
plot_symb
(sp, tp, hp, symbol, tags=None)¶ plot a symbol.
arguments:
sp, tp (float)
plot location in scaled coordinates. In the scaled domain, every point on the canvas is mapped to the window smin, smax = 0.0, 1.0 and tmin, tmax = 0.0, 1.0hp (float)
size of the symbol to be drawn in scaled units.symbol (str)
the name of the symbol to be drawn. One of:
- spade : (Hershey) spade
- heart : (Hershey) heart
- diam : (Hershey) diamond
- club : (Hershey) club
- shamrock : (Hershey) shamrock
- fleurdelis : (Hershey) Fleur-de-lis
- circle : (Hershey) circle
- star : (Hershey) star
- dot : dot
- square : square
- diamond : diamond
- triangle : triangle
- itriangle : inverted triangle
- dash : dash
- pipe : pipe
- plus : plus
- cross : cross
tags (str)
tk canvas tags to apply to the symbol.
-
plot_texv
(sp, tp, hp, stringp, **kwargs)¶ plot a text string.
arguments:
sp, tp (float)
plot location in scaled coordinates. In the scaled domain, every point on the canvas is mapped to the window smin, smax = 0.0, 1.0 and tmin, tmax = 0.0, 1.0hp (float)
size of the text to be drawn in scaled units.stringp (str)
the string to label.
If control_mode is True, the following control sequences are respected:
single-character control sequences:
- & greek characters follow
- $ script characters follow
- ^ super-script
- ~ subscript
- @ increase character size
- # decrease character size
- % toggle overstrike mode
- back-space
- ! begin two-letter control sequence
two-letter control sequences:
- !0 font family 0
- !1 font family 1
- !2 font family 2
- !3 font family 3
- != toggle constant spacing mode
- !- toggle connected mode
- !| stretch by 1.2
- !~ shrink by 1.2
- !. ignore any following control sequences
**kwargs (dict)
options.options:
tags (str, default=”STRING”)
tk canvas tags to apply to the symbol.rotate (float, default=0.0)
The rotation angle in degrees of the string label.slant (float, default=0.0)
The slant angle in degrees of the string label.anchor (str, default=”c”)
The alignment of text with respect to sp, tp. One of:
“c” : x:centered y: centered
“n” : x:centered y: north of sp, tp
“s” : x:centered y: south of sp, tp
“e” : x:east of sp, tp y: centered
“w” : x:west of sp, tp y: centered
“ne” : x:east of sp, tp y: north of sp, tp
“nw” : x:west of sp, tp y: north of sp, tp
“se” : x:east of sp, tp y: south of sp, tp
“sw” : x:west of sp, tp y: south of sp, tp
control_mode (bool, default=True)
if True, respect control sequences, listed in stringp option descriptionsingle_char (int, default=-1)
specify one character in the Hershey font set to be printed, an integer between 0 and 1535.
-
plot_top
()¶ return plot top window (frame or toplevel).
results:
- Returns the handle to the current plot top window.
-
plot_transform_entry
(entry)¶ return the transform dictionary entry.
arguments:
entry (str)
the transform entry to return. One of:
- uv_max_limits: maximum canvas limits
- st_max_limits: maximum scaled limits
- xy_max_limits: maximum x,y limits
- uv_limits: current canvas limits
- st_limits: current scaled limits
- xy_limits: current x,y limits
- uv_st: transform canvas to scale point
- uv_xy: transform canvas to x,y point
- st_uv: transform scaled to canvas point
- st_xy: transform scaled to x,y point
- xy_st: transform x,y to scaled point
- xy_uv: transform x,y to canvas point
-
plot_uv_st
(u, v)¶ convert canvas coordinates to scaled coordinates (0, 1, 0, 1)
arguments:
u, v (int)
x, y (pixel) coordinates in canvas domain.results:
- return scaled coordinates s, t
-
plot_uv_xy
(u, v)¶ convert canvas coordinates to x, y coordinates.
arguments:
u, v (int)
canvas (pixel) coordinates.results:
- return x, y coordinates
-
plot_window
()¶ return plot window (canvas).
results:
- Returns the handle to the current plot window.
-
plot_xy_st
(x, y)¶ convert x, y coordinates to scaled coordinates (0, 1, 0, 1)
arguments:
x, y (float)
x, y coordinates.results:
- return scaled coordinates s, t
-
plot_xy_uv
(x, y)¶ convert x, y coordinates to canvas coordinates.
arguments:
x, y (float)
x, y coordinates.results:
- return canvas coordinates u, v