Module for fitting a linear model to the data
This module defines the LinRegPlotter
and the
DensityRegPlotter
plotter classes that can be used
to fit a linear model to the data and visualize it.
Classes:
|
Draw a confidence interval |
|
A plotter that visualizes the density of points together with a linear regression |
|
|
|
Force the fit to go through a given point |
|
Draw an ideal line of the fit |
|
The colors of the ideal lines |
|
Initial parameters for the |
|
A plotter to visualize the fit on the data |
|
Switch x- and y-axes |
|
Choose the linear fitting method |
|
Choose the linear fitting method |
|
Set the number of bootstrap resamples for the confidence interval |
|
Parameter bounds for the function parameters |
|
Specify the range for the fit to use for the x-dimension |
|
Specify how wide the range for the plot should be |
|
Specify the range for the fit to use for the y-dimension |
Functions:
|
Simple bootstrap algorithm used to estimate the confidence interval |
|
Return a quantile range from an array of values. |
- class psy_reg.plotters.Ci(key, plotter=None, index_in_list=None, additional_children=[], additional_dependencies=[], **kwargs)
Bases:
Formatoption
Draw a confidence interval
Size of the confidence interval for the regression estimate. This will be drawn using translucent bands around the regression line. The confidence interval is estimated using a bootstrap; for large datasets, it may be advisable to avoid that computation by setting this parameter to None.
Possible types
- None
Do not draw and calculate a confidence interval
- float
A quantile between 0 and 100
Attributes:
list of str.
fit Formatoption instance in the plotter
fix Formatoption instance in the plotter
str
.str
.nboot Formatoption instance in the plotter
int
.transpose Formatoption instance in the plotter
Methods:
initialize_plot
(*args, **kwargs)Method that is called when the plot is made the first time
update
(value)Method that is call to update the formatoption on the axes
- dependencies = ['transpose', 'fit', 'nboot', 'fix']
list of str. List of formatoptions that force an update of this formatoption if they are updated.
- property fit
fit Formatoption instance in the plotter
- property fix
fix Formatoption instance in the plotter
- initialize_plot(*args, **kwargs)
Method that is called when the plot is made the first time
- Parameters:
value – The value to use for the initialization
- name = 'Draw a confidence interval'
str
. A bit more verbose name than the formatoption key to be included in the gui. If None, the key is used in the gui
- property nboot
nboot Formatoption instance in the plotter
- priority = 30
int
. Priority value of the the formatoption determining when the formatoption is updated.10: at the end (for labels, etc.)
20: before the plotting (e.g. for colormaps, etc.)
30: before loading the data (e.g. for lonlatbox)
- property transpose
transpose Formatoption instance in the plotter
- update(value)
Method that is call to update the formatoption on the axes
- Parameters:
value – Value to update
- class psy_reg.plotters.DensityRegPlotter(data=None, ax=None, auto_update=None, project=None, draw=False, make_plot=True, clear=False, enable_post=False, **kwargs)
Bases:
ScalarCombinedBase
,DensityPlotter
,LinRegPlotter
A plotter that visualizes the density of points together with a linear regression
Attributes:
Specify the bins of the 2D-Histogramm
Specify the position of the colorbars
Draw a confidence interval
Show the colorbar label
Set the color coding
Visualize the error range
Set the alpha value for the error range
Choose the linear fitting method
Force the fit to go through a given point
The colors of the ideal lines
Draw an ideal line of the fit
Set the font properties of both, x- and y-label
Set the size of both, x- and y-label
Set the font size of both, x- and y-label
Draw a legend
Set the labels of the arrays in the legend
Specify how wide the range for the plot should be
Choose the line style of the plot
Set the number of bootstrap resamples for the confidence interval
Specify the normalization of the histogram
Initial parameters for the
scipy.optimize.curve_fit()
functionParameter bounds for the function parameters
Choose how to visualize a 2-dimensional scalar data field
Apply your own postprocessing script
Determine when to run the
post
formatoptionSet the precision of the data
Change the ticksize of the ticklabels
Change the fontweight of the ticks
Show the title
Switch x- and y-axes
Set the x-axis label
Set the x-axis limits
Specify the range of the histogram for the x-dimension
Rotate the x-axis ticks
Modify the x-axis ticklabels
Specify the x-axis tick parameters
Modify the x-axis ticks
Set the y-axis label
Set the y-axis limits
Specify the range of the histogram for the x-dimension
Rotate the y-axis ticks
Modify the y-axis ticklabels
Specify the y-axis tick parameters
Modify the y-axis ticks
- bins
Specify the bins of the 2D-Histogramm
This formatoption can be used to specify, how many bins to use. In other words, it determines the grid size of the resulting histogram or kde plot. If however you also set the
precision
formatoption keyword then the minimum of precision and the bins specified here will be used.Possible types
- cbar
Specify the position of the colorbars
Possible types
- bool
True: defaults to ‘b’ False: Don’t draw any colorbar
- str
The string can be a combination of one of the following strings: {‘fr’, ‘fb’, ‘fl’, ‘ft’, ‘b’, ‘r’, ‘sv’, ‘sh’}
‘b’, ‘r’ stand for bottom and right of the axes
‘fr’, ‘fb’, ‘fl’, ‘ft’ stand for bottom, right, left and top of the figure
‘sv’ and ‘sh’ stand for a vertical or horizontal colorbar in a separate figure
- list
A containing one of the above positions
Examples
Draw a colorbar at the bottom and left of the axes:
>>> plotter.update(cbar='bl')
- ci
Draw a confidence interval
Size of the confidence interval for the regression estimate. This will be drawn using translucent bands around the regression line. The confidence interval is estimated using a bootstrap; for large datasets, it may be advisable to avoid that computation by setting this parameter to None.
Possible types
- None
Do not draw and calculate a confidence interval
- float
A quantile between 0 and 100
- clabel
Show the colorbar label
Set the label of the colorbar. You can insert any meta key from the
xarray.DataArray.attrs
via a string like'%(key)s'
. Furthermore there are some special cases:Strings like
'%Y'
,'%b'
, etc. will be replaced using thedatetime.datetime.strftime()
method as long as the data has a time coordinate and this can be converted to adatetime
object.'%(x)s'
,'%(y)s'
,'%(z)s'
,'%(t)s'
will be replaced by the value of the x-, y-, z- or time coordinate (as long as this coordinate is one-dimensional in the data)any attribute of one of the above coordinates is inserted via
axis + key
(e.g. the name of the x-coordinate can be inserted via'%(xname)s'
).Labels defined in the
psyplot.rcParams
'texts.labels'
key are also replaced when enclosed by ‘{}’. The standard labels aretinfo:
%H:%M
dtinfo:
%B %d, %Y. %H:%M
dinfo:
%B %d, %Y
desc:
%(long_name)s [%(units)s]
sdesc:
%(name)s [%(units)s]
Possible types
- str
The title for the
set_label()
method.
See also
clabelsize
,clabelweight
,clabelprops
- color
Set the color coding
This formatoptions sets the color of the lines, bars, etc.
Possible types
- None
to use the axes color_cycle
- iterable
(e.g. list) to specify the colors manually
str
Strings may be any valid colormap name suitable for the
matplotlib.cm.get_cmap()
function or one of the color lists defined in the ‘colors.cmaps’ key of thepsyplot.rcParams
dictionary (including their reversed color maps given via the ‘_r’ extension).- matplotlib.colors.ColorMap
to automatically choose the colors according to the number of lines, etc. from the given colormap
- density
- error
Visualize the error range
This formatoption visualizes the error range. For this, you must provide a two-dimensional data array as input. The first dimension might be either of length
2 to provide the deviation from minimum and maximum error range from the data
3 to provide the minimum and maximum error range explicitly
Possible types
- None
No errors are visualized
- ‘fill’
The area between min- and max-error is filled with the same color as the line and the alpha is determined by the
fillalpha
attribute
Examples
Assume you have the standard deviation stored in the
'std'
-variable and the data in the'data'
variable. Then you can visualize the standard deviation simply via:>>> psy.plot.lineplot(input_ds, name=[['data', 'std']])
On the other hand, assume you want to visualize the area between the 25th and 75th percentile (stored in the variables
'p25'
and'p75'
):>>> psy.plot.lineplot(input_ds, name=[['data', 'p25', 'p75']])
See also
- erroralpha
Set the alpha value for the error range
This formatoption can be used to set the alpha value (opacity) for the
error
formatoptionPossible types
- float
A float between 0 and 1
See also
- fit
Choose the linear fitting method
This formatoption consists makes a linear fit of the data
Possible types
- ‘fit’ or ‘linear’
make a linear fit
- ‘robust’
make a robust linear fit
- ‘poly<deg>’
Make a polynomial fit of the order
'<deg>'
- function
A callable function that takes an x-array and a y-array as input and can be used for the
scipy.optimize.curve_fit()
function- any object with a fit and predict method
A model that with a fit signature such as
model.fit(x, y).predict(x)
- None
make no fit
Notes
You can access the intercept, slope and rsquared by the correponding attribute. E.g.:
>>> plotter.update( ... legendlabels="%(intercept)s + %(slope)s * x, " ... "$R^2$=%(rsquared)s" ... )
See also
- fix
Force the fit to go through a given point
Possible types
- None
do not force the fit at all
- float f
make a linear fit forced through
(x, y) = (0, f)
- tuple (x’, y’)
make a linear fit forced through
(x, y) = (x', y')
See also
- id_color
The colors of the ideal lines
Possible types
- None
Let it be determined by the color cycle of the
color
formatoption- iterable
(e.g. list) to specify the colors manually
str
Strings may be any valid colormap name suitable for the
matplotlib.cm.get_cmap()
function or one of the color lists defined in the ‘colors.cmaps’ key of thepsyplot.rcParams
dictionary (including their reversed color maps given via the ‘_r’ extension).- matplotlib.colors.ColorMap
to automatically choose the colors according to the number of lines, etc. from the given colormap
See also
- ideal
Draw an ideal line of the fit
Possible types
- None
Don’t draw an ideal line
- list of floats
The parameters for the line. If the
fit
formatoption is in'robust'
or'fit'
, then the first value corresponds to the interception, the second to the slope. Otherwise the list corrensponds to the parameters as used in the fit function of the lines- list of list of floats
The same as above but with the specification for each array
See also
- labelprops
Set the font properties of both, x- and y-label
Possible types
- dict
A dictionary with the keys
'x'
and (or)'y'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is used for the x- and y-axis. The values in the dictionary can be one types below.- dict
Items may be any valid text property
See also
- labelsize
Set the size of both, x- and y-label
Possible types
- dict
A dictionary with the keys
'x'
and (or)'y'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is used for the x- and y-axis. The values in the dictionary can be one types below.- float
The absolute font size in points (e.g., 12)
- string
Strings might be ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’.
See also
- labelweight
Set the font size of both, x- and y-label
Possible types
- dict
A dictionary with the keys
'x'
and (or)'y'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is used for the x- and y-axis. The values in the dictionary can be one types below.- float
a float between 0 and 1000
- string
Possible strings are one of ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’.
See also
- legend
Draw a legend
This formatoption determines where and if to draw the legend. It uses the
labels
formatoption to determine the labels.Possible types
- bool
Draw a legend or not
- str or int
Specifies where to plot the legend (i.e. the location)
- dict
Give the keywords for the
matplotlib.pyplot.legend()
function
See also
labels
- legendlabels
Set the labels of the arrays in the legend
This formatoption specifies the labels for each array in the legend. You can insert any meta key from the
xarray.DataArray.attrs
via a string like'%(key)s'
. Furthermore there are some special cases:Strings like
'%Y'
,'%b'
, etc. will be replaced using thedatetime.datetime.strftime()
method as long as the data has a time coordinate and this can be converted to adatetime
object.'%(x)s'
,'%(y)s'
,'%(z)s'
,'%(t)s'
will be replaced by the value of the x-, y-, z- or time coordinate (as long as this coordinate is one-dimensional in the data)any attribute of one of the above coordinates is inserted via
axis + key
(e.g. the name of the x-coordinate can be inserted via'%(xname)s'
).Labels defined in the
psyplot.rcParams
'texts.labels'
key are also replaced when enclosed by ‘{}’. The standard labels aretinfo:
%H:%M
dtinfo:
%B %d, %Y. %H:%M
dinfo:
%B %d, %Y
desc:
%(long_name)s [%(units)s]
sdesc:
%(name)s [%(units)s]
Possible types
- str:
A single string that shall be used for all arrays.
- list of str:
Same as a single string but specified for each array
See also
- line_xlim
Specify how wide the range for the plot should be
This formatoption specifies the range of the line to use
Possible types
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
See also
- lineplot
Choose the line style of the plot
Possible types
- None
Don’t make any plotting
'area'
To make an area plot (filled between y=0 and y), see
matplotlib.pyplot.fill_between()
'areax'
To make a transposed area plot (filled between x=0 and x), see
matplotlib.pyplot.fill_betweenx()
'stacked'
Make a stacked plot
- str or list of str
The line style string to use ([‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ | (offset, on-off-dash-seq) | ‘-’ | ‘–’ | ‘-.’ | ‘:’ | ‘None’ | ‘ ‘ | ‘’]).
- nboot
Set the number of bootstrap resamples for the confidence interval
- Parameters:
int – Number of bootstrap resamples used to estimate the
ci
. The default value attempts to balance time and stability; you may want to increase this value for “final” versions of plots.
See also
- normed
Specify the normalization of the histogram
This formatoption can be used to normalize the histogram. It has no effect if the
density
formatoption is set to'kde'
Possible types
- None
Do not make any normalization
- str
One of
- counts
To make the normalization based on the total number counts
- area
To make the normalization basen on the total number of counts and area (the default behaviour of
numpy.histogram2d()
)- x, col, column or columns
To normalize every column
- y, row or rows
To normalize every row
See also
- p0
Initial parameters for the
scipy.optimize.curve_fit()
functionThis formatoptions can be used to set the initial parameters if the value of the
fit
formatoption is a callable function.Note that the automatic estimation uses the boundaries of the
param_bounds
formatoption. This only works if the boundaries are given for each parameter and finite.Possible types
- ‘auto’
The initial parameters are estimated automatically using the
from scipy.optimize.differential_evolution()
function- list of floats
The initial parameters
- list of list of floats or ‘auto’
A combination of the above types where each corresponds to one data array
- param_bounds
Parameter bounds for the function parameters
This formatoption can be used to specify the boundaries for the parameters. It only has an effect if the value of the
fit
formatoption is a callable function.These bounds will also be used by the
p0
formatoption to estimate the initial parameters.Possible types
- None
Use open boundaries
- list of tuples with length 2
The boundaries for each of the parameters
- list of tuples or None
A combination of the above types where each corresponds to one data array
- plot
Choose how to visualize a 2-dimensional scalar data field
Possible types
- None
Don’t make any plotting
- ‘mesh’
Use the
matplotlib.pyplot.pcolormesh()
function to make the plot or thematplotlib.pyplot.tripcolor()
for an unstructered grid- ‘poly’
Draw each polygon indivually. This method is used by default for unstructured grids. If there are no grid cell boundaries in the dataset, we will interpolate them
- ‘contourf’
Make a filled contour plot using the
matplotlib.pyplot.contourf()
function. The levels for the contour plot are controlled by thelevels
formatoption- ‘contour’
Same a
'contourf'
, but does not make a filled contour plot, only lines.
- post
Apply your own postprocessing script
This formatoption let’s you apply your own post processing script. Just enter the script as a string and it will be executed. The formatoption will be made available via the
self
variablePossible types
- None
Don’t do anything
- str
The post processing script as string
Note
This formatoption uses the built-in
exec()
function to compile the script. Since this poses a security risk when loading psyplot projects, it is by default disabled through thePlotter.enable_post
attribute. If you are sure that you can trust the script in this formatoption, set this attribute of the correspondingPlotter
toTrue
Examples
Assume, you want to manually add the mean of the data to the title of the matplotlib axes. You can simply do this via
from psyplot.plotter import Plotter from xarray import DataArray plotter = Plotter(DataArray([1, 2, 3])) # enable the post formatoption plotter.enable_post = True plotter.update(post="self.ax.set_title(str(self.data.mean()))") plotter.ax.get_title() "2.0"
By default, the
post
formatoption is only ran, when it is explicitly updated. However, you can use thepost_timing
formatoption, to run it automatically. E.g. for running it after every update of the plotter, you can setplotter.update(post_timing="always")
See also
post_timing
Determine the timing of this formatoption
- post_timing
Determine when to run the
post
formatoptionThis formatoption determines, whether the
post
formatoption should be run never, after replot or after every update.Possible types
- ‘never’
Never run post processing scripts
- ‘always’
Always run post processing scripts
- ‘replot’
Only run post processing scripts when the data changes or a replot is necessary
See also
post
The post processing formatoption
- precision
Set the precision of the data
This formatoption can be used to specify the precision of the data which then will be the minimal bin width of the 2D histogram or the bandwith of the kernel size (if the
density
formatoption is set to'kde'
)Possible types
- float
If 0, this formatoption has no effect at all. Otherwise it is assumed to be the precision of the data
- str
One of
{'scott' | 'silverman'}
. This uses the statsmodels package to estimate the bandwidth of the data that is then used in the histogram or KDE plot
- ticksize
Change the ticksize of the ticklabels
Possible types
- dict
A dictionary with the keys
'minor'
and (or)'major'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is put into a dictionary with the key determined by the rcParams'ticks.which'
key (usually'major'
). The values in the dictionary can be one types below.- float
The absolute font size in points (e.g., 12)
- string
Strings might be ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’.
See also
- tickweight
Change the fontweight of the ticks
Possible types
- dict
A dictionary with the keys
'minor'
and (or)'major'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is put into a dictionary with the key determined by the rcParams'ticks.which'
key (usually'major'
). The values in the dictionary can be one types below.- float
a float between 0 and 1000
- string
Possible strings are one of ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’.
See also
- title
Show the title
Set the title of the plot. You can insert any meta key from the
xarray.DataArray.attrs
via a string like'%(key)s'
. Furthermore there are some special cases:Strings like
'%Y'
,'%b'
, etc. will be replaced using thedatetime.datetime.strftime()
method as long as the data has a time coordinate and this can be converted to adatetime
object.'%(x)s'
,'%(y)s'
,'%(z)s'
,'%(t)s'
will be replaced by the value of the x-, y-, z- or time coordinate (as long as this coordinate is one-dimensional in the data)any attribute of one of the above coordinates is inserted via
axis + key
(e.g. the name of the x-coordinate can be inserted via'%(xname)s'
).Labels defined in the
psyplot.rcParams
'texts.labels'
key are also replaced when enclosed by ‘{}’. The standard labels aretinfo:
%H:%M
dtinfo:
%B %d, %Y. %H:%M
dinfo:
%B %d, %Y
desc:
%(long_name)s [%(units)s]
sdesc:
%(name)s [%(units)s]
Possible types
- str
The title for the
title()
function.
Notes
This is the title of this specific subplot! For the title of the whole figure, see the
figtitle
formatoption.See also
figtitle
,titlesize
,titleweight
,titleprops
- transpose
Switch x- and y-axes
By default, one-dimensional arrays have the dimension on the x-axis and two dimensional arrays have the first dimension on the y and the second on the x-axis. You can set this formatoption to True to change this behaviour
Possible types
- bool
If True, axes are switched
- xlabel
Set the x-axis label
Set the label for the x-axis. You can insert any meta key from the
xarray.DataArray.attrs
via a string like'%(key)s'
. Furthermore there are some special cases:Strings like
'%Y'
,'%b'
, etc. will be replaced using thedatetime.datetime.strftime()
method as long as the data has a time coordinate and this can be converted to adatetime
object.'%(x)s'
,'%(y)s'
,'%(z)s'
,'%(t)s'
will be replaced by the value of the x-, y-, z- or time coordinate (as long as this coordinate is one-dimensional in the data)any attribute of one of the above coordinates is inserted via
axis + key
(e.g. the name of the x-coordinate can be inserted via'%(xname)s'
).Labels defined in the
psyplot.rcParams
'texts.labels'
key are also replaced when enclosed by ‘{}’. The standard labels aretinfo:
%H:%M
dtinfo:
%B %d, %Y. %H:%M
dinfo:
%B %d, %Y
desc:
%(long_name)s [%(units)s]
sdesc:
%(name)s [%(units)s]
Possible types
- str
The text for the
xlabel()
function.
See also
xlabelsize
,xlabelweight
,xlabelprops
- xlim
Set the x-axis limits
Possible types
- None
To not change the current limits
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
See also
- xrange
Specify the range of the histogram for the x-dimension
This formatoption specifies the minimum and maximum of the histogram in the x-dimension
Possible types
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
Notes
This formatoption always acts on the coordinate, no matter what the value of the
transpose
formatoption isSee also
- xticklabels
Modify the x-axis ticklabels
Possible types
- dict
A dictionary with the keys
'minor'
and (or)'major'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is put into a dictionary with the key determined by the rcParams'ticks.which'
key (usually'major'
). The values in the dictionary can be one types below.- str
A formatstring like
'%Y'
for plotting the year (in the case that time is shown on the axis) or ‘%i’ for integers- array
An array of strings to use for the ticklabels
See also
- xtickprops
Specify the x-axis tick parameters
This formatoption can be used to make a detailed change of the ticks parameters on the x-axis.
Possible types
- dict
A dictionary with the keys
'minor'
and (or)'major'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is put into a dictionary with the key determined by the rcParams'ticks.which'
key (usually'major'
). The values in the dictionary can be one types below.- dict
Items may be anything of the
matplotlib.pyplot.tick_params()
function
See also
- xticks
Modify the x-axis ticks
Possible types
- dict
A dictionary with the keys
'minor'
and (or)'major'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is put into a dictionary with the key determined by the rcParams'ticks.which'
key (usually'major'
). The values in the dictionary can be one types below.- None
use the default ticks
- int
for an integer i, only every i-th tick of the default ticks are used
- numeric array
specifies the ticks manually
- str or list [str, …]
A list of the below mentioned values of the mapping like
[method, N, percmin, percmax, vmin, vmax]
, where only the first one is absolutely necessary- dict
Automatically determine the ticks corresponding to the data. The mapping can have the following keys, but only method is not optional.
- N
An integer describing the number of boundaries (or ticks per power of ten, see log and symlog above)
- percmin
The percentile to use for the minimum (by default, 0, i.e. the minimum of the array)
- percmax
The percentile to use for the maximum (by default, 100, i.e. the maximum of the array)
- vmin
The minimum to use (in which case it is not calculated from the specified method)
- vmax
The maximum to use (in which case it is not calculated from the specified method)
- method
A string that defines how minimum and maximum shall be set. This argument is not optional and can be one of the following:
- data
plot the ticks exactly where the data is.
- mid
plot the ticks in the middle of the data.
- rounded
Sets the minimum and maximum of the ticks to the rounded data minimum or maximum. Ticks are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimal tick will always be lower or equal than the data minimum, the maximal tick will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the ticks are chose such that they are symmetric around zero
- minmax
Uses the minimum as minimal tick and maximum as maximal tick
- sym
Same as minmax but symmetric around zero
- log
Use logarithmic bounds. In this case, the given number N determines the number of bounds per power of tenth (i.e.
N == 2
results in something like1.0, 5.0, 10.0, 50.0
, etc., If this second number is None, then it will be chosen such that we have around 11 boundaries but at least one per power of ten.- symlog
The same as
log
but symmetric around 0. If the number N is None, then we have around 12 boundaries but at least one per power of ten- hour
draw ticks every hour
- day
draw ticks every day
- week
draw ticks every week
- month, monthend, monthbegin
draw ticks in the middle, at the end or at the beginning of each month
- year, yearend, yearbegin
draw ticks in the middle, at the end or at the beginning of each year
For data, mid, hour, day, week, month, etc., the optional second value can be an integer i determining that every i-th data point shall be used (by default, it is set to 1). For rounded, roundedsym, minmax and sym, the second value determines the total number of ticks (defaults to 11).
Examples
Plot 11 ticks over the whole data range:
>>> plotter.update(xticks='rounded')
Plot 7 ticks over the whole data range where the maximal and minimal tick matches the data maximum and minimum:
>>> plotter.update(xticks=['minmax', 7])
Plot ticks every year and minor ticks every month:
>>> plotter.update(xticks={'major': 'year', 'minor': 'month'})
See also
- ylabel
Set the y-axis label
Set the label for the y-axis. You can insert any meta key from the
xarray.DataArray.attrs
via a string like'%(key)s'
. Furthermore there are some special cases:Strings like
'%Y'
,'%b'
, etc. will be replaced using thedatetime.datetime.strftime()
method as long as the data has a time coordinate and this can be converted to adatetime
object.'%(x)s'
,'%(y)s'
,'%(z)s'
,'%(t)s'
will be replaced by the value of the x-, y-, z- or time coordinate (as long as this coordinate is one-dimensional in the data)any attribute of one of the above coordinates is inserted via
axis + key
(e.g. the name of the x-coordinate can be inserted via'%(xname)s'
).Labels defined in the
psyplot.rcParams
'texts.labels'
key are also replaced when enclosed by ‘{}’. The standard labels aretinfo:
%H:%M
dtinfo:
%B %d, %Y. %H:%M
dinfo:
%B %d, %Y
desc:
%(long_name)s [%(units)s]
sdesc:
%(name)s [%(units)s]
Possible types
- str
The text for the
ylabel()
function.
See also
ylabelsize
,ylabelweight
,ylabelprops
- ylim
Set the y-axis limits
Possible types
- None
To not change the current limits
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
See also
- yrange
Specify the range of the histogram for the x-dimension
This formatoption specifies the minimum and maximum of the histogram in the x-dimension
Possible types
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
Notes
This formatoption always acts on the DataArray, no matter what the value of the
transpose
formatoption isSee also
- yticklabels
Modify the y-axis ticklabels
Possible types
- dict
A dictionary with the keys
'minor'
and (or)'major'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is put into a dictionary with the key determined by the rcParams'ticks.which'
key (usually'major'
). The values in the dictionary can be one types below.- str
A formatstring like
'%Y'
for plotting the year (in the case that time is shown on the axis) or ‘%i’ for integers- array
An array of strings to use for the ticklabels
See also
- ytickprops
Specify the y-axis tick parameters
This formatoption can be used to make a detailed change of the ticks parameters of the y-axis.
Possible types
- dict
A dictionary with the keys
'minor'
and (or)'major'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is put into a dictionary with the key determined by the rcParams'ticks.which'
key (usually'major'
). The values in the dictionary can be one types below.- dict
Items may be anything of the
matplotlib.pyplot.tick_params()
function
See also
- yticks
Modify the y-axis ticks
Possible types
- dict
A dictionary with the keys
'minor'
and (or)'major'
to specify which ticks are managed. If the given value is not a dictionary with those keys, it is put into a dictionary with the key determined by the rcParams'ticks.which'
key (usually'major'
). The values in the dictionary can be one types below.- None
use the default ticks
- int
for an integer i, only every i-th tick of the default ticks are used
- numeric array
specifies the ticks manually
- str or list [str, …]
A list of the below mentioned values of the mapping like
[method, N, percmin, percmax, vmin, vmax]
, where only the first one is absolutely necessary- dict
Automatically determine the ticks corresponding to the data. The mapping can have the following keys, but only method is not optional.
- N
An integer describing the number of boundaries (or ticks per power of ten, see log and symlog above)
- percmin
The percentile to use for the minimum (by default, 0, i.e. the minimum of the array)
- percmax
The percentile to use for the maximum (by default, 100, i.e. the maximum of the array)
- vmin
The minimum to use (in which case it is not calculated from the specified method)
- vmax
The maximum to use (in which case it is not calculated from the specified method)
- method
A string that defines how minimum and maximum shall be set. This argument is not optional and can be one of the following:
- data
plot the ticks exactly where the data is.
- mid
plot the ticks in the middle of the data.
- rounded
Sets the minimum and maximum of the ticks to the rounded data minimum or maximum. Ticks are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimal tick will always be lower or equal than the data minimum, the maximal tick will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the ticks are chose such that they are symmetric around zero
- minmax
Uses the minimum as minimal tick and maximum as maximal tick
- sym
Same as minmax but symmetric around zero
- log
Use logarithmic bounds. In this case, the given number N determines the number of bounds per power of tenth (i.e.
N == 2
results in something like1.0, 5.0, 10.0, 50.0
, etc., If this second number is None, then it will be chosen such that we have around 11 boundaries but at least one per power of ten.- symlog
The same as
log
but symmetric around 0. If the number N is None, then we have around 12 boundaries but at least one per power of ten- hour
draw ticks every hour
- day
draw ticks every day
- week
draw ticks every week
- month, monthend, monthbegin
draw ticks in the middle, at the end or at the beginning of each month
- year, yearend, yearbegin
draw ticks in the middle, at the end or at the beginning of each year
For data, mid, hour, day, week, month, etc., the optional second value can be an integer i determining that every i-th data point shall be used (by default, it is set to 1). For rounded, roundedsym, minmax and sym, the second value determines the total number of ticks (defaults to 11).
- class psy_reg.plotters.FitPointDensity(key, plotter=None, index_in_list=None, additional_children=[], additional_dependencies=[], **kwargs)
Bases:
PointDensity
Attributes:
bins Formatoption instance in the plotter
list of str.
coord Formatoption instance in the plotter
line_xlim Formatoption instance in the plotter
normed Formatoption instance in the plotter
precision Formatoption instance in the plotter
xrange Formatoption instance in the plotter
yrange Formatoption instance in the plotter
- property bins
bins Formatoption instance in the plotter
- children = ['line_xlim']
list of str. List of formatoptions that have to be updated before this one is updated. Those formatoptions are only updated if they exist in the update parameters.
- property coord
coord Formatoption instance in the plotter
- property line_xlim
line_xlim Formatoption instance in the plotter
- property normed
normed Formatoption instance in the plotter
- property precision
precision Formatoption instance in the plotter
- property xrange
xrange Formatoption instance in the plotter
- property yrange
yrange Formatoption instance in the plotter
- class psy_reg.plotters.FixPoint(key, plotter=None, index_in_list=None, additional_children=[], additional_dependencies=[], **kwargs)
Bases:
Formatoption
Force the fit to go through a given point
Possible types
- None
do not force the fit at all
- float f
make a linear fit forced through
(x, y) = (0, f)
- tuple (x’, y’)
make a linear fit forced through
(x, y) = (x', y')
See also
Attributes:
list of str.
fit Formatoption instance in the plotter
str
.str
.int
.Methods:
update
(value)Method that is call to update the formatoption on the axes
- connections = ['fit']
list of str. Connections to other formatoptions that are (different from
dependencies
andchildren
) not important for the update process
- property fit
fit Formatoption instance in the plotter
- name = 'Force the fit to go through a given point'
str
. A bit more verbose name than the formatoption key to be included in the gui. If None, the key is used in the gui
- priority = 30
int
. Priority value of the the formatoption determining when the formatoption is updated.10: at the end (for labels, etc.)
20: before the plotting (e.g. for colormaps, etc.)
30: before loading the data (e.g. for lonlatbox)
- update(value)
Method that is call to update the formatoption on the axes
- Parameters:
value – Value to update
- class psy_reg.plotters.IdealLine(key, plotter=None, index_in_list=None, additional_children=[], additional_dependencies=[], **kwargs)
Bases:
Formatoption
Draw an ideal line of the fit
Possible types
- None
Don’t draw an ideal line
- list of floats
The parameters for the line. If the
fit
formatoption is in'robust'
or'fit'
, then the first value corresponds to the interception, the second to the slope. Otherwise the list corrensponds to the parameters as used in the fit function of the lines- list of list of floats
The same as above but with the specification for each array
See also
Attributes:
list of str.
fit Formatoption instance in the plotter
str
.id_color Formatoption instance in the plotter
plot Formatoption instance in the plotter
Methods:
initialize_plot
(*args, **kwargs)Method that is called when the plot is made the first time
remove
()Method to remove the effects of this formatoption
update
(value)Method that is call to update the formatoption on the axes
- dependencies = ['fit', 'id_color', 'plot']
list of str. List of formatoptions that force an update of this formatoption if they are updated.
- property fit
fit Formatoption instance in the plotter
- property id_color
id_color Formatoption instance in the plotter
- initialize_plot(*args, **kwargs)
Method that is called when the plot is made the first time
- Parameters:
value – The value to use for the initialization
- property plot
plot Formatoption instance in the plotter
- remove()
Method to remove the effects of this formatoption
This method is called when the axes is cleared due to a formatoption with
requires_clearing
set to True. You don’t necessarily have to implement this formatoption if your plot results are removed by the usualmatplotlib.axes.Axes.clear()
method.
- update(value)
Method that is call to update the formatoption on the axes
- Parameters:
value – Value to update
- class psy_reg.plotters.IdealLineColor(*args, **kwargs)
Bases:
LineColors
The colors of the ideal lines
Possible types
- None
Let it be determined by the color cycle of the
color
formatoption- iterable
(e.g. list) to specify the colors manually
str
Strings may be any valid colormap name suitable for the
matplotlib.cm.get_cmap()
function or one of the color lists defined in the ‘colors.cmaps’ key of thepsyplot.rcParams
dictionary (including their reversed color maps given via the ‘_r’ extension).- matplotlib.colors.ColorMap
to automatically choose the colors according to the number of lines, etc. from the given colormap
See also
Attributes:
color Formatoption instance in the plotter
list of str.
ideal Formatoption instance in the plotter
list of str.
int
.Methods:
update
(value)Method that is call to update the formatoption on the axes
- property color
color Formatoption instance in the plotter
- dependencies = ['color']
list of str. List of formatoptions that force an update of this formatoption if they are updated.
- property ideal
ideal Formatoption instance in the plotter
- parents = ['ideal']
list of str. List of formatoptions that, if included in the update, prevent the update of this formatoption.
- priority = 10
int
. Priority value of the the formatoption determining when the formatoption is updated.10: at the end (for labels, etc.)
20: before the plotting (e.g. for colormaps, etc.)
30: before loading the data (e.g. for lonlatbox)
- update(value)
Method that is call to update the formatoption on the axes
- Parameters:
value – Value to update
- class psy_reg.plotters.InitialParameters(key, plotter=None, index_in_list=None, additional_children=[], additional_dependencies=[], **kwargs)
Bases:
Formatoption
Initial parameters for the
scipy.optimize.curve_fit()
functionThis formatoptions can be used to set the initial parameters if the value of the
fit
formatoption is a callable function.Note that the automatic estimation uses the boundaries of the
param_bounds
formatoption. This only works if the boundaries are given for each parameter and finite.Possible types
- ‘auto’
The initial parameters are estimated automatically using the
from scipy.optimize.differential_evolution()
function- list of floats
The initial parameters
- list of list of floats or ‘auto’
A combination of the above types where each corresponds to one data array
Attributes:
list of str.
bool
or a callable.list of str.
fit Formatoption instance in the plotter
str
.str
.param_bounds Formatoption instance in the plotter
int
.Methods:
p0
([i])update
(value)Method that is call to update the formatoption on the axes
- connections = ['fit']
list of str. Connections to other formatoptions that are (different from
dependencies
andchildren
) not important for the update process
- data_dependent = True
bool
or a callable. This attribute indicates whether thisFormatoption
depends on the data and should be updated if the data changes. If it is a callable, it must accept one argument: the new data. (Note: This is automatically set to True for plot formatoptions)
- dependencies = ['param_bounds']
list of str. List of formatoptions that force an update of this formatoption if they are updated.
- property fit
fit Formatoption instance in the plotter
- name = 'Initial parameter values for the fit'
str
. A bit more verbose name than the formatoption key to be included in the gui. If None, the key is used in the gui
- p0(i=None)
- property param_bounds
param_bounds Formatoption instance in the plotter
- priority = 30
int
. Priority value of the the formatoption determining when the formatoption is updated.10: at the end (for labels, etc.)
20: before the plotting (e.g. for colormaps, etc.)
30: before loading the data (e.g. for lonlatbox)
- update(value)
Method that is call to update the formatoption on the axes
- Parameters:
value – Value to update
- class psy_reg.plotters.LinRegPlotter(data=None, ax=None, auto_update=None, project=None, draw=False, make_plot=True, clear=False, enable_post=False, **kwargs)
Bases:
LinePlotter
A plotter to visualize the fit on the data
The most important formatoptions are the
fit
andci
formatoption. Otherwise this plotter behaves like thepsyplot.plotter.simple.LinePlotter
plotter classAttributes:
The number variables that one data array visualized by this plotter might have.
Draw a confidence interval
Choose the linear fitting method
Force the fit to go through a given point
The colors of the ideal lines
Draw an ideal line of the fit
Specify how wide the range for the plot should be
Set the number of bootstrap resamples for the confidence interval
Initial parameters for the
scipy.optimize.curve_fit()
functionParameter bounds for the function parameters
Switch x- and y-axes
Specify the range for the fit to use for the x-dimension
Specify the range for the fit to use for the y-dimension
- allowed_vars = 1
The number variables that one data array visualized by this plotter might have. We allow up to 3 variableswhere the second and third variable might be the errors (see the
error
formatoption)
- ci
Draw a confidence interval
Size of the confidence interval for the regression estimate. This will be drawn using translucent bands around the regression line. The confidence interval is estimated using a bootstrap; for large datasets, it may be advisable to avoid that computation by setting this parameter to None.
Possible types
- None
Do not draw and calculate a confidence interval
- float
A quantile between 0 and 100
- fit
Choose the linear fitting method
This formatoption consists makes a linear fit of the data
Possible types
- ‘fit’ or ‘linear’
make a linear fit
- ‘robust’
make a robust linear fit
- ‘poly<deg>’
Make a polynomial fit of the order
'<deg>'
- function
A callable function that takes an x-array and a y-array as input and can be used for the
scipy.optimize.curve_fit()
function- any object with a fit and predict method
A model that with a fit signature such as
model.fit(x, y).predict(x)
- None
make no fit
Notes
You can access the intercept, slope and rsquared by the correponding attribute. E.g.:
>>> plotter.update( ... legendlabels="%(intercept)s + %(slope)s * x, " ... "$R^2$=%(rsquared)s" ... )
See also
- fix
Force the fit to go through a given point
Possible types
- None
do not force the fit at all
- float f
make a linear fit forced through
(x, y) = (0, f)
- tuple (x’, y’)
make a linear fit forced through
(x, y) = (x', y')
See also
- id_color
The colors of the ideal lines
Possible types
- None
Let it be determined by the color cycle of the
color
formatoption- iterable
(e.g. list) to specify the colors manually
str
Strings may be any valid colormap name suitable for the
matplotlib.cm.get_cmap()
function or one of the color lists defined in the ‘colors.cmaps’ key of thepsyplot.rcParams
dictionary (including their reversed color maps given via the ‘_r’ extension).- matplotlib.colors.ColorMap
to automatically choose the colors according to the number of lines, etc. from the given colormap
See also
- ideal
Draw an ideal line of the fit
Possible types
- None
Don’t draw an ideal line
- list of floats
The parameters for the line. If the
fit
formatoption is in'robust'
or'fit'
, then the first value corresponds to the interception, the second to the slope. Otherwise the list corrensponds to the parameters as used in the fit function of the lines- list of list of floats
The same as above but with the specification for each array
See also
- line_xlim
Specify how wide the range for the plot should be
This formatoption specifies the range of the line to use
Possible types
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
See also
- nboot
Set the number of bootstrap resamples for the confidence interval
- Parameters:
int – Number of bootstrap resamples used to estimate the
ci
. The default value attempts to balance time and stability; you may want to increase this value for “final” versions of plots.
See also
- p0
Initial parameters for the
scipy.optimize.curve_fit()
functionThis formatoptions can be used to set the initial parameters if the value of the
fit
formatoption is a callable function.Note that the automatic estimation uses the boundaries of the
param_bounds
formatoption. This only works if the boundaries are given for each parameter and finite.Possible types
- ‘auto’
The initial parameters are estimated automatically using the
from scipy.optimize.differential_evolution()
function- list of floats
The initial parameters
- list of list of floats or ‘auto’
A combination of the above types where each corresponds to one data array
- param_bounds
Parameter bounds for the function parameters
This formatoption can be used to specify the boundaries for the parameters. It only has an effect if the value of the
fit
formatoption is a callable function.These bounds will also be used by the
p0
formatoption to estimate the initial parameters.Possible types
- None
Use open boundaries
- list of tuples with length 2
The boundaries for each of the parameters
- list of tuples or None
A combination of the above types where each corresponds to one data array
- transpose
Switch x- and y-axes
By default, one-dimensional arrays have the dimension on the x-axis and two dimensional arrays have the first dimension on the y and the second on the x-axis. You can set this formatoption to True to change this behaviour
Possible types
- bool
If True, axes are switched
- xrange
Specify the range for the fit to use for the x-dimension
This formatoption specifies the minimum and maximum of the fit in the x-dimension
Possible types
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
Notes
This formatoption always acts on the coordinate, no matter what the value of the
transpose
formatoption is
- yrange
Specify the range for the fit to use for the y-dimension
This formatoption specifies the minimum and maximum of the fit in the y-dimension
Possible types
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
Notes
This formatoption always acts on the coordinate, no matter what the value of the
transpose
formatoption isSee also
- class psy_reg.plotters.LinRegTranspose(*args, **kwargs)
Bases:
Transpose
Switch x- and y-axes
By default, one-dimensional arrays have the dimension on the x-axis and two dimensional arrays have the first dimension on the y and the second on the x-axis. You can set this formatoption to True to change this behaviour
Possible types
- bool
If True, axes are switched
Attributes:
int
.
- class psy_reg.plotters.LinearRegressionFit(*args, **kwargs)
Bases:
Formatoption
Choose the linear fitting method
This formatoption consists makes a linear fit of the data
Possible types
- ‘fit’ or ‘linear’
make a linear fit
- ‘robust’
make a robust linear fit
- ‘poly<deg>’
Make a polynomial fit of the order
'<deg>'
- function
A callable function that takes an x-array and a y-array as input and can be used for the
scipy.optimize.curve_fit()
function- any object with a fit and predict method
A model that with a fit signature such as
model.fit(x, y).predict(x)
- None
make no fit
Notes
You can access the intercept, slope and rsquared by the correponding attribute. E.g.:
>>> plotter.update( ... legendlabels="%(intercept)s + %(slope)s * x, " ... "$R^2$=%(rsquared)s" ... )
See also
Attributes:
coord Formatoption instance in the plotter
bool
or a callable.list of str.
fix Formatoption instance in the plotter
The arguments for the fit function if the
method
is 'curve_fit'str
.line_xlim Formatoption instance in the plotter
str
.p0 Formatoption instance in the plotter
param_bounds Formatoption instance in the plotter
int
.transpose Formatoption instance in the plotter
xrange Formatoption instance in the plotter
yrange Formatoption instance in the plotter
Methods:
get_kwargs
(i)Get the fitting kwargs for the line at index i
get_xline
([i])Get the x-data for the best fit line
get_xy
(i, da)make_fit
(i, x, y[, x_line])set_method
(i)update
(value)Method that is call to update the formatoption on the axes
- property coord
coord Formatoption instance in the plotter
- data_dependent = True
bool
or a callable. This attribute indicates whether thisFormatoption
depends on the data and should be updated if the data changes. If it is a callable, it must accept one argument: the new data. (Note: This is automatically set to True for plot formatoptions)
- dependencies = ['transpose', 'fix', 'xrange', 'yrange', 'coord', 'line_xlim', 'p0', 'param_bounds']
list of str. List of formatoptions that force an update of this formatoption if they are updated.
- property fix
fix Formatoption instance in the plotter
- property func_args
The arguments for the fit function if the
method
is ‘curve_fit’
- get_kwargs(i)
Get the fitting kwargs for the line at index i
- get_xline(i=0)
Get the x-data for the best fit line
- get_xy(i, da)
- property line_xlim
line_xlim Formatoption instance in the plotter
- make_fit(i, x, y, x_line=None, **kwargs)
- name = 'Change the fit method'
str
. A bit more verbose name than the formatoption key to be included in the gui. If None, the key is used in the gui
- property p0
p0 Formatoption instance in the plotter
- property param_bounds
param_bounds Formatoption instance in the plotter
- priority = 30
int
. Priority value of the the formatoption determining when the formatoption is updated.10: at the end (for labels, etc.)
20: before the plotting (e.g. for colormaps, etc.)
30: before loading the data (e.g. for lonlatbox)
- set_method(i)
- property transpose
transpose Formatoption instance in the plotter
- update(value)
Method that is call to update the formatoption on the axes
- Parameters:
value – Value to update
- property xrange
xrange Formatoption instance in the plotter
- property yrange
yrange Formatoption instance in the plotter
- class psy_reg.plotters.LinearRegressionFitCombined(*args, **kwargs)
Bases:
LinearRegressionFit
Choose the linear fitting method
This formatoption consists makes a linear fit of the data
Possible types
- ‘fit’ or ‘linear’
make a linear fit
- ‘robust’
make a robust linear fit
- ‘poly<deg>’
Make a polynomial fit of the order
'<deg>'
- function
A callable function that takes an x-array and a y-array as input and can be used for the
scipy.optimize.curve_fit()
function- any object with a fit and predict method
A model that with a fit signature such as
model.fit(x, y).predict(x)
- None
make no fit
Notes
You can access the intercept, slope and rsquared by the correponding attribute. E.g.:
>>> plotter.update( ... legendlabels="%(intercept)s + %(slope)s * x, " ... "$R^2$=%(rsquared)s" ... )
See also
Attributes:
coord Formatoption instance in the plotter
fix Formatoption instance in the plotter
line_xlim Formatoption instance in the plotter
p0 Formatoption instance in the plotter
param_bounds Formatoption instance in the plotter
transpose Formatoption instance in the plotter
xrange Formatoption instance in the plotter
yrange Formatoption instance in the plotter
Methods:
set_data
(data[, i])Reimplemented to change the arr_name attribute of the given array
- property coord
coord Formatoption instance in the plotter
- property fix
fix Formatoption instance in the plotter
- property line_xlim
line_xlim Formatoption instance in the plotter
- property p0
p0 Formatoption instance in the plotter
- property param_bounds
param_bounds Formatoption instance in the plotter
- set_data(data, i=None)
Reimplemented to change the arr_name attribute of the given array
- property transpose
transpose Formatoption instance in the plotter
- property xrange
xrange Formatoption instance in the plotter
- property yrange
yrange Formatoption instance in the plotter
- class psy_reg.plotters.NBoot(key, plotter=None, index_in_list=None, additional_children=[], additional_dependencies=[], **kwargs)
Bases:
Formatoption
Set the number of bootstrap resamples for the confidence interval
- Parameters:
int – Number of bootstrap resamples used to estimate the
ci
. The default value attempts to balance time and stability; you may want to increase this value for “final” versions of plots.
See also
ci
Attributes:
str
.str
.int
.Methods:
update
(value)Does nothing.
- name = 'Set the bootstrapping number to calculate the confidence interval'
str
. A bit more verbose name than the formatoption key to be included in the gui. If None, the key is used in the gui
- class psy_reg.plotters.ParameterBounds(key, plotter=None, index_in_list=None, additional_children=[], additional_dependencies=[], **kwargs)
Bases:
Formatoption
Parameter bounds for the function parameters
This formatoption can be used to specify the boundaries for the parameters. It only has an effect if the value of the
fit
formatoption is a callable function.These bounds will also be used by the
p0
formatoption to estimate the initial parameters.Possible types
- None
Use open boundaries
- list of tuples with length 2
The boundaries for each of the parameters
- list of tuples or None
A combination of the above types where each corresponds to one data array
Methods:
update
(value)Method that is call to update the formatoption on the axes
- update(value)
Method that is call to update the formatoption on the axes
- Parameters:
value – Value to update
- class psy_reg.plotters.XFitRange(*args, **kwargs)
Bases:
Hist2DXRange
Specify the range for the fit to use for the x-dimension
This formatoption specifies the minimum and maximum of the fit in the x-dimension
Possible types
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
Notes
This formatoption always acts on the coordinate, no matter what the value of the
transpose
formatoption isSee also
yrange
,line_xlim
Attributes:
coord Formatoption instance in the plotter
str
.plot Formatoption instance in the plotter
The range for each of the curves
transpose Formatoption instance in the plotter
Methods:
set_limit
(*args)The method to set the minimum and maximum limit
update
(value)Method that is call to update the formatoption on the axes
- property coord
coord Formatoption instance in the plotter
- property plot
plot Formatoption instance in the plotter
- property range
The range for each of the curves
- set_limit(*args)
The method to set the minimum and maximum limit
- property transpose
transpose Formatoption instance in the plotter
- update(value)
Method that is call to update the formatoption on the axes
- Parameters:
value – Value to update
- class psy_reg.plotters.XLineRange(*args, **kwargs)
Bases:
XFitRange
Specify how wide the range for the plot should be
This formatoption specifies the range of the line to use
Possible types
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
See also
xrange
Attributes:
coord Formatoption instance in the plotter
plot Formatoption instance in the plotter
transpose Formatoption instance in the plotter
- property coord
coord Formatoption instance in the plotter
- property plot
plot Formatoption instance in the plotter
- property transpose
transpose Formatoption instance in the plotter
- class psy_reg.plotters.YFitRange(*args, **kwargs)
Bases:
Hist2DYRange
Specify the range for the fit to use for the y-dimension
This formatoption specifies the minimum and maximum of the fit in the y-dimension
Possible types
- str or list [str, str] or [[str, float], [str, float]]
Automatically determine the ticks corresponding to the data. The given string determines how the limits are calculated. The float determines the percentile to use A string can be one of the following:
- rounded
Sets the minimum and maximum of the limits to the rounded data minimum or maximum. Limits are rounded to the next 0.5 value with to the difference between data max- and minimum. The minimum will always be lower or equal than the data minimum, the maximum will always be higher or equal than the data maximum.
- roundedsym
Same as rounded above but the limits are chosen such that they are symmetric around zero
- minmax
Uses the minimum and maximum
- sym
Same as minmax but symmetric around zero
- tuple (xmin, xmax)
xmin is the smaller value, xmax the larger. Any of those values can be None or one of the strings (or lists) above to use the corresponding value here
Notes
This formatoption always acts on the coordinate, no matter what the value of the
transpose
formatoption isSee also
xrange
Attributes:
coord Formatoption instance in the plotter
str
.plot Formatoption instance in the plotter
The range for each of the curves
transpose Formatoption instance in the plotter
Methods:
set_limit
(*args)The method to set the minimum and maximum limit
update
(value)Method that is call to update the formatoption on the axes
- property coord
coord Formatoption instance in the plotter
- property plot
plot Formatoption instance in the plotter
- property range
The range for each of the curves
- set_limit(*args)
The method to set the minimum and maximum limit
- property transpose
transpose Formatoption instance in the plotter
- update(value)
Method that is call to update the formatoption on the axes
- Parameters:
value – Value to update
- psy_reg.plotters.bootstrap(x, y, func, n_boot, random_seed=None, **kwargs)
Simple bootstrap algorithm used to estimate the confidence interval
This function is motivated by seaborns bootstrap algorithm
seaborn.algorithms.bootstrap()
- psy_reg.plotters.calc_ci(a, which=95, axis=None)
Return a quantile range from an array of values.