BaseBackend
- class sherpa.plot.backends.BaseBackend[source] [edit on github]
Bases:
objectA dummy backend for plotting.
This backend implements only minimal functionality (some formatting of strings as HTML or LaTeX which are usually used as axis labels), but no real plotting capabilities. It is here to ensure that the
sherpa.plotmodule can be imported, even if no plotting backend is installed.In this sense, this backend can be understood as the “base” for backends. The string-formatting is implemented here so that other backends don’t have to duplicate that; they can call the functions here.
No plotting is implemented in this backend, but all functions are documented by what they should do, so that this backend can serve as a template to implement actual plotting interfaces.
- Attributes:
nameAn easy-to-read string name
Methods
as_html(data, fields)Create HTML representation of a plot
Provide empty plot window
colorlist(n)Generate the list of n colors for use in multi-line plots.
contour(x0, x1, y, *[, levels, title, ...])Draw 2D contour data.
Currently, there are no configurable settings
get_latex_for_string(txt)Convert LaTeX formula
histo(xlo, xhi, y, *[, yerr, title, xlabel, ...])Draw histogram data.
hline(y, *[, xmin, xmax, title, xlabel, ...])Draw a horizontal line
image(x0, x1, y, *[, aspect, title, xlabel, ...])Draw 2D image data.
initialize_plot(dataset, ids)Create the plot window or figure for the given dataset.
plot(x, y, *[, xerr, yerr, title, xlabel, ...])Draw x, y data.
select_plot(dataset, ids)Select the plot window or figure for the given dataset.
set_jointplot(row, col, nrows, ncols[, ...])Move to the plot, creating them if necessary.
set_subplot(row, col, nrows, ncols[, clearaxes])Select a plot space in a grid of plots or create new grid
set_title(title)Change the display title.
vline(x, *[, ymin, ymax, title, xlabel, ...])Draw a vertical line
as_html_cdf
as_html_contour1d
as_html_contour2d
as_html_data
as_html_datacontour
as_html_fit
as_html_fitcontour
as_html_histogram
as_html_lr
as_html_model
as_html_modelcontour
as_html_pdf
get_cdf_plot_defaults
get_component_histo_defaults
get_component_plot_defaults
get_confid_contour_defaults
get_confid_plot_defaults
get_confid_point_defaults
get_contour_defaults
get_data_contour_defaults
get_data_plot_defaults
get_fit_contour_defaults
get_fit_plot_defaults
get_histo_defaults
get_html
get_model_contour_defaults
get_model_histo_defaults
get_model_plot_defaults
get_plot_defaults
get_point_defaults
get_ratio_contour_defaults
get_ratio_plot_defaults
get_resid_contour_defaults
get_resid_histo_defaults
get_resid_plot_defaults
get_rmf_plot_defaults
get_scatter_plot_defaults
Attributes Summary
An easy-to-read string name
Dict of keyword arguments that need to be translated for this backend.
Methods Summary
as_html(data, fields)Create HTML representation of a plot
as_html_cdf(plot)as_html_contour1d(plot)as_html_contour2d(plot)as_html_data(plot)as_html_datacontour(plot)as_html_fit(plot)as_html_fitcontour(plot)as_html_histogram(plot)as_html_lr(plot)as_html_model(plot)as_html_modelcontour(plot)as_html_pdf(plot)Provide empty plot window
colorlist(n)Generate the list of n colors for use in multi-line plots.
contour(x0, x1, y, *[, levels, title, ...])Draw 2D contour data.
get_html(attr)Currently, there are no configurable settings
get_latex_for_string(txt)Convert LaTeX formula
histo(xlo, xhi, y, *[, yerr, title, xlabel, ...])Draw histogram data.
hline(y, *[, xmin, xmax, title, xlabel, ...])Draw a horizontal line
image(x0, x1, y, *[, aspect, title, xlabel, ...])Draw 2D image data.
initialize_plot(dataset, ids)Create the plot window or figure for the given dataset.
plot(x, y, *[, xerr, yerr, title, xlabel, ...])Draw x, y data.
select_plot(dataset, ids)Select the plot window or figure for the given dataset.
set_jointplot(row, col, nrows, ncols[, ...])Move to the plot, creating them if necessary.
set_subplot(row, col, nrows, ncols[, clearaxes])Select a plot space in a grid of plots or create new grid
set_title(title)Change the display title.
vline(x, *[, ymin, ymax, title, xlabel, ...])Draw a vertical line
Attributes Documentation
- name
An easy-to-read string name
- translate_dict = {}
Dict of keyword arguments that need to be translated for this backend.
The keys in this dict are keyword arguments (e.g.
'markerfacecolor') and the values are one of the following:A dict where the keys are the backend-independent values and the values are the values expressed for this backend. For values not listed in the dict, no translation is done.
A callable. The callable translation function is called with any argument given and allows the backend arbitrary translations. It should, at the very least, accept all backend independent values for this parameter without error.
Example:
>>> translate_dict = {'markerfacecolor': {'k': (0., 0., 0.)}, ... 'alpha': lambda a: 255 * a}
This translates the color ‘k’ to tuple of RGB values and alpha values to a number between 0 and 255.
Methods Documentation
- as_html(data, fields)[source] [edit on github]
Create HTML representation of a plot
- Parameters:
- data
Plotinstance The plot object to display.
- fieldssequence
ofstrings The fields of data to use.
- data
- as_html_cdf(plot)[source] [edit on github]
- as_html_contour1d(plot)[source] [edit on github]
- as_html_contour2d(plot)[source] [edit on github]
- as_html_data(plot)[source] [edit on github]
- as_html_datacontour(plot)[source] [edit on github]
- as_html_fit(plot)[source] [edit on github]
- as_html_fitcontour(plot)[source] [edit on github]
- as_html_histogram(plot)[source] [edit on github]
- as_html_lr(plot)[source] [edit on github]
- as_html_model(plot)[source] [edit on github]
- as_html_modelcontour(plot)[source] [edit on github]
- as_html_pdf(plot)[source] [edit on github]
- clear_window()[source] [edit on github]
Provide empty plot window
Depending on the backend, this may provide a new, empty window or clear the existing, current window.
- colorlist(n)[source] [edit on github]
Generate the list of n colors for use in multi-line plots.
Generally, the color will be ordered in some way and do not repeat or do so only after a large number of colors. Different backends might generate different lists of colors.
- contour(x0, x1, y, *, levels=None, title=None, xlabel=None, ylabel=None, overcontour=False, clearwindow=True, xlog=False, ylog=False, label=None, colors=None, linestyles='solid', linewidths=None, alpha=None, **kwargs)[source] [edit on github]
Draw 2D contour data.
Warning
This backend is a non-functional dummy. The documentation is provided as a template only.
- Parameters:
- x0array_like
independent axis in the first dimenation (on regular grid, flattened)
- x1array_like
independent axis in the second dimenation (on regular grid, flattened)
- yarray_like
dependent axis (i.e. image values) (on regular grid, flattened)
- levelsarray_like, default=None
Levels at which to draw the contours
- title
str, default=None Plot title (can contain LaTeX formulas). Only used if a new plot is created.
- xlabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- ylabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- overcontourbool, default=False
If
True, the contour is added to an existing plot, if not a new plot is created.- clearwindowbool, default=True
If
Truethe entire figure area is cleared to make space for a new plot.- xlogbool, default=False
Should the x axis be logarithmic (default: linear)? Only used if a new plot is created.
- ylogbool, default=False
Should the y axis be logarithmic (default: linear)? Only used if a new plot is created.
- label
str, default=None Label this dataset for use in a legend
- colorsdefault=None
- linestylesdefault=solid
- linewidthsdefault=None
- alpha
float, default=None Number between 0 and 1, setting the transparency.
- kwargs
dict,optional All other keyword parameters are passed to the plotting library.
- get_cdf_plot_defaults()[source] [edit on github]
- get_component_histo_defaults() [edit on github]
- get_component_plot_defaults() [edit on github]
- get_confid_contour_defaults() [edit on github]
- get_confid_plot_defaults()[source] [edit on github]
- get_confid_point_defaults()[source] [edit on github]
- get_contour_defaults()[source] [edit on github]
- get_data_contour_defaults() [edit on github]
- get_data_plot_defaults()[source] [edit on github]
- get_fit_contour_defaults()[source] [edit on github]
- get_fit_plot_defaults()[source] [edit on github]
- get_histo_defaults()[source] [edit on github]
- get_html(attr)[source] [edit on github]
- get_image_defaults()[source] [edit on github]
Currently, there are no configurable settings
- get_latex_for_string(txt)[source] [edit on github]
Convert LaTeX formula
- get_model_contour_defaults() [edit on github]
- get_model_histo_defaults()[source] [edit on github]
- get_model_plot_defaults()[source] [edit on github]
- get_plot_defaults()[source] [edit on github]
- get_point_defaults()[source] [edit on github]
- get_ratio_contour_defaults() [edit on github]
- get_ratio_plot_defaults()[source] [edit on github]
- get_resid_contour_defaults() [edit on github]
- get_resid_histo_defaults()[source] [edit on github]
- get_resid_plot_defaults()[source] [edit on github]
- get_rmf_plot_defaults()[source] [edit on github]
- get_scatter_plot_defaults()[source] [edit on github]
- get_split_plot_defaults()[source] [edit on github]
- histo(xlo, xhi, y, *, yerr=None, title=None, xlabel=None, ylabel=None, overplot=False, clearwindow=True, xlog=False, ylog=False, label=None, xerrorbars=False, yerrorbars=False, color=None, linestyle='solid', linewidth=None, marker='None', alpha=None, markerfacecolor=None, markersize=None, ecolor=None, capsize=None, **kwargs)[source] [edit on github]
Draw histogram data.
The histogram is drawn as horizontal lines connecting the start and end points of each bin, with vertical lines connecting consecutive bins. Non-consecutive bins are drawn with a (NaN, NaN) between them so no line is drawn connecting them.
Points are drawn at the middle of the bin, along with any error values.
Warning
This backend is a non-functional dummy. The documentation is provided as a template only.
- Parameters:
- xloarray_like or scalar
number lower bin boundary values
- xhiarray_like or scalar
number upper bin boundary values
- yarray_like or scalar
number y values, same dimension as xlo.
- yerr
floator array_like, default=None - The errorbar sizes can be:
scalar: Symmetric +/- values for all data points.
shape(N,): Symmetric +/-values for each data point.
shape(2, N): Separate - and + values for each bar. First row contains the lower errors, the second row contains the upper errors.
None: No errorbar.
Note that all error arrays should have positive values.
- title
str, default=None Plot title (can contain LaTeX formulas). Only used if a new plot is created.
- xlabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- ylabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- overplotbool, default=False
If
True, the plot is added to an existing plot, if not a new plot is created.- clearwindowbool, default=True
If
Truethe entire figure area is cleared to make space for a new plot.- xlogbool, default=False
Should the x axis be logarithmic (default: linear)? Only used if a new plot is created.
- ylogbool, default=False
Should the y axis be logarithmic (default: linear)? Only used if a new plot is created.
- label
str, default=None Label this dataset for use in a legend
- xerrorbarsbool, default=False
Should x error bars be shown? If this is set to
Trueerrorbars are shown, but only if the size of the errorbars is provided in thexerrparameters. The purpose of having a separate switchxerrorbarsis that the prepare method of a plot can create the errors and pass them to this method, but the user can still decide to change the style of the plot and choose if error bars should be displayed.- yerrorbarsbool, default=False
Should y error bars be shown? If this is set to
Trueerrorbars are shown, but only if the size of the errorbars is provided in theyerrparameters. The purpose of having a separate switchyerrorbarsis that the prepare method of a plot can create the errors and pass them to this method, but the user can still decide to change the style of the plot and choose if error bars should be displayed.- color
str, default=None The following colors are accepted by all backends:
'b'(blue),'r'(red),'g'(green),'k'(black),'w'(white),'c'(cyan),'y'(yellow),'m'(magenta) but they may not translate to the exact same RGB values in each backend, e.g.'b'could be a different shade of blue depending on the backend. Some backends might accept additional values.- linestyle
str, default=solid The following values are accepted by all backends:
'noline','None'(as string, same as'noline'),'solid','dot','dash','dashdot','-'(solid line),':'(dotted),'--'(dashed),'-.'(dot-dashed),''(empty string, no line shown),None(default - usually solid line). Some backends may accept additional values.- linewidth
float, default=None Thickness of the line.
- marker
str, default=None The following values are accepted by all backends: “None” (as a string, no marker shown), “.” (dot), “o” (circle), “+”, “s” (square), “” (empty string, no marker shown),
None(no marker shown).Some backends may accept additional values.
- alpha
float, default=None Number between 0 and 1, setting the transparency.
- markerfacecolor
str, default=None see
color- markersize
float, default=None Size of a marker. The scale may also depend on the backend.
Noneuses the backend-specific default.- ecolor
str, default=None Color of the error bars.
- capsize
float, default=None Size of the cap drawn at the end of the error bars.
- kwargs
dict,optional All other keyword parameters are passed to the plotting library.
- xloarray_like or scalar
- hline(y, *, xmin=0, xmax=1, title=None, xlabel=None, ylabel=None, overplot=False, clearwindow=True, linecolor=None, linestyle=None, linewidth=None, **kwargs)[source] [edit on github]
Draw a horizontal line
Warning
This backend is a non-functional dummy. The documentation is provided as a template only.
- Parameters:
- y
float x position of the vertical line in data units
- xmin
float, default=0 Beginning of the horizontal line in axes coordinates, i.e. from 0 (left) to 1 (right).
- xmax
float, default=1 End of the vertical line in axes coordinates, i.e. from 0 (left) to 1 (right).
- title
str, default=None Plot title (can contain LaTeX formulas). Only used if a new plot is created.
- xlabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- ylabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- overplotbool, default=False
If
True, the plot is added to an existing plot, if not a new plot is created.- clearwindowbool, default=True
If
Truethe entire figure area is cleared to make space for a new plot.- linecolor
str, default=None The following colors are accepted by all backends:
'b'(blue),'r'(red),'g'(green),'k'(black),'w'(white),'c'(cyan),'y'(yellow),'m'(magenta) but they may not translate to the exact same RGB values in each backend, e.g.'b'could be a different shade of blue depending on the backend. Some backend might accept additional values.- linestyle
str, default=None The following values are accepted by all backends:
'noline','None'(as string, same as'noline'),'solid','dot','dash','dashdot','-'(solid line),':'(dotted),'--'(dashed),'-.'(dot-dashed),''(empty string, no line shown),None(default - usually solid line). Some backends may accept additional values.- linewidth
float, default=None Thickness of the line.
- kwargs
dict,optional All other keyword parameters are passed to the plotting library.
- y
- image(x0, x1, y, *, aspect=1, title=None, xlabel=None, ylabel=None, clearwindow=True, **kwargs)[source] [edit on github]
Draw 2D image data.
Warning
This function is a non-functional dummy. The documentation is provided as a template only.
- Parameters:
- x0array_like
independent axis in the first dimenation
- x1array_like
independent axis in the second dimenation
- yarray_like
dependent axis (i.e. image values) in 2D with shape (len(x0), len(x1))
- aspect
strorfloat, default=1 Aspect ratio of the plot. Strings “equal” or “auto” are accepted.
- title
str, default=None Plot title (can contain LaTeX formulas). Only used if a new plot is created.
- xlabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- ylabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- clearwindowbool, default=True
If
Truethe entire figure area is cleared to make space for a new plot.- kwargs
dict,optional All other keyword parameters are passed to the plotting library.
- initialize_plot(dataset, ids)[source] [edit on github]
Create the plot window or figure for the given dataset.
Warning
This function is a non-functional dummy. The documentation is provided as a template only.
- Parameters:
- dataset
strorint The dataset.
- idsarray_like
The identifier array from the DataStack object.
- dataset
See also
- plot(x, y, *, xerr=None, yerr=None, title=None, xlabel=None, ylabel=None, xlog=False, ylog=False, overplot=False, clearwindow=True, label=None, xerrorbars=False, yerrorbars=False, color=None, linestyle='solid', linewidth=None, marker='None', alpha=None, markerfacecolor=None, markersize=None, **kwargs)[source] [edit on github]
Draw x, y data.
- This method combines a number of different ways to draw x/y data:
a line connecting the points
scatter plot of symbols
errorbars
All three of them can be used together (symbols with errorbars connected by a line), but it is also possible to use only one or two of them. By default, a line is shown (
linestyle='solid'), but marker and error bars are not (marker='None'andxerrorbars=Falseas well asyerrorbars=False).Warning
This backend is a non-functional dummy. The documentation is provided as a template only.
Changed in version 4.16.1: The
xerrsetting now matches theyerrsetting and represents the distance from the center to the edge, rather than twice this value.- Parameters:
- xarray_like or scalar
number x values
- yarray_like or scalar
number y values, same dimension as
x.- xerr
floator array_like, default=None - The errorbar sizes can be:
scalar: Symmetric +/- values for all data points.
shape(N,): Symmetric +/-values for each data point.
shape(2, N): Separate - and + values for each bar. First row contains the lower errors, the second row contains the upper errors.
None: No errorbar.
Note that all error arrays should have positive values.
- yerr
floator array_like, default=None - The errorbar sizes can be:
scalar: Symmetric +/- values for all data points.
shape(N,): Symmetric +/-values for each data point.
shape(2, N): Separate - and + values for each bar. First row contains the lower errors, the second row contains the upper errors.
None: No errorbar.
Note that all error arrays should have positive values.
- title
str, default=None Plot title (can contain LaTeX formulas). Only used if a new plot is created.
- xlabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- ylabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- xlogbool, default=False
Should the x axis be logarithmic (default: linear)? Only used if a new plot is created.
- ylogbool, default=False
Should the y axis be logarithmic (default: linear)? Only used if a new plot is created.
- overplotbool, default=False
If
True, the plot is added to an existing plot, if not a new plot is created.- clearwindowbool, default=True
If
Truethe entire figure area is cleared to make space for a new plot.- label
str, default=None Label this dataset for use in a legend
- xerrorbarsbool, default=False
Should x error bars be shown? If this is set to
Trueerrorbars are shown, but only if the size of the errorbars is provided in thexerrparameters. The purpose of having a separate switchxerrorbarsis that the prepare method of a plot can create the errors and pass them to this method, but the user can still decide to change the style of the plot and choose if error bars should be displayed.- yerrorbarsbool, default=False
Should y error bars be shown? If this is set to
Trueerrorbars are shown, but only if the size of the errorbars is provided in theyerrparameters. The purpose of having a separate switchyerrorbarsis that the prepare method of a plot can create the errors and pass them to this method, but the user can still decide to change the style of the plot and choose if error bars should be displayed.- color
str, default=None The following colors are accepted by all backends:
'b'(blue),'r'(red),'g'(green),'k'(black),'w'(white),'c'(cyan),'y'(yellow),'m'(magenta) but they may not translate to the exact same RGB values in each backend, e.g.'b'could be a different shade of blue depending on the backend. Some backends might accept additional values.- linestyle
str, default=solid The following values are accepted by all backends:
'noline','None'(as string, same as'noline'),'solid','dot','dash','dashdot','-'(solid line),':'(dotted),'--'(dashed),'-.'(dot-dashed),''(empty string, no line shown),None(default - usually solid line). Some backends may accept additional values.- linewidth
float, default=None Thickness of the line.
- marker
str, default=None The following values are accepted by all backends: “None” (as a string, no marker shown), “.” (dot), “o” (circle), “+”, “s” (square), “” (empty string, no marker shown),
None(no marker shown).Some backends may accept additional values.
- alpha
float, default=None Number between 0 and 1, setting the transparency.
- markerfacecolor
str, default=None see
color- markersize
float, default=None Size of a marker. The scale may also depend on the backend.
Noneuses the backend-specific default.- kwargs
dict,optional All other keyword parameters are passed to the plotting library.
- xarray_like or scalar
- select_plot(dataset, ids)[source] [edit on github]
Select the plot window or figure for the given dataset.
The plot for this dataset is assumed to have been created.
Warning
This function is a non-functional dummy. The documentation is provided as a template only.
- Parameters:
- dataset
strorint The dataset.
- idsarray_like
The identifier array from the DataStack object.
- dataset
See also
- set_jointplot(row, col, nrows, ncols, create=True, top=0, ratio=2)[source] [edit on github]
Move to the plot, creating them if necessary.
Warning
This backend is a non-functional dummy. The documentation is provided as a template only.
- Parameters:
- row
int The row number, starting from 0.
- col
int The column number, starting from 0.
- nrows
int The number of rows.
- ncols
int The number of columns.
- createbool,
optional If True then create the plots
- top
int The row that is set to the ratio height, numbered from 0.
- ratio
float The ratio of the height of row number top to the other rows.
- row
- set_subplot(row, col, nrows, ncols, clearaxes=True, **kwargs)[source] [edit on github]
Select a plot space in a grid of plots or create new grid
This method adds a new subplot in a grid of plots.
Warning
This backend is a non-functional dummy. The documentation is provided as a template only.
- Parameters:
Notes
This method is intended for grids of plots with the same number of plots in each row and each column. In some backends, more complex layouts (e.g. one wide plot on row 1 and two smaller plots in row 2) might be possible.
- set_title(title: str) None[source] [edit on github]
Change the display title.
- Parameters:
- title
str The title text to use.
- title
- vline(x, *, ymin=0, ymax=1, title=None, xlabel=None, ylabel=None, overplot=False, clearwindow=True, linecolor=None, linestyle=None, linewidth=None, **kwargs)[source] [edit on github]
Draw a vertical line
Warning
This backend is a non-functional dummy. The documentation is provided as a template only.
- Parameters:
- x
float x position of the vertical line in data units
- ymin
float, default=0 Beginning of the vertical line in axes coordinates, i.e. from 0 (bottom) to 1 (top).
- ymax
float, default=1 End of the vertical line in axes coordinates, i.e. from 0 (bottom) to 1 (top).
- title
str, default=None Plot title (can contain LaTeX formulas). Only used if a new plot is created.
- xlabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- ylabel
str, default=None Axis label (can contain LaTeX formulas). Only used if a new plot is created.
- overplotbool, default=False
If
True, the plot is added to an existing plot, if not a new plot is created.- clearwindowbool, default=True
If
Truethe entire figure area is cleared to make space for a new plot.- linecolor
str, default=None The following colors are accepted by all backends:
'b'(blue),'r'(red),'g'(green),'k'(black),'w'(white),'c'(cyan),'y'(yellow),'m'(magenta) but they may not translate to the exact same RGB values in each backend, e.g.'b'could be a different shade of blue depending on the backend. Some backend might accept additional values.- linestyle
str, default=None The following values are accepted by all backends:
'noline','None'(as string, same as'noline'),'solid','dot','dash','dashdot','-'(solid line),':'(dotted),'--'(dashed),'-.'(dot-dashed),''(empty string, no line shown),None(default - usually solid line). Some backends may accept additional values.- linewidth
float, default=None Thickness of the line.
- kwargs
dict,optional All other keyword parameters are passed to the plotting library.
- x