Plotting and display
Every surface inherits these methods: the plotting helpers from BaseSurfacePlot and the display and coordinate methods from BaseSurface.
BaseSurfacePlot
binned_stat_2d
surface.binned_stat_2d(x, y, values, statistic = 'sum', xlim = None, ylim = None, binsize = 1, bins = None)
Create a two-dimensional binned statistic via scipy.
Parameters
-
x(numpy.ndarray): A sequence of values to be binned along in the first dimension -
y: A sequence of values to be binned along in the second dimension -
values(numpy.ndarray): The data on which the statistic will be computed. This must have the same shape asx, or a list of sequences that each have the same shape asx -
statistic(str or callable): The statistic to compute via scipy. Per scipy, the following are available:"count": the number of points inside each bin"max": the maximum for points inside each bin"mean": the mean of values for points inside each bin"median": the median for points inside each bin"min": the minimum for points inside each bin"std": the standard deviation for points inside each bin"sum": the sum of the values for points inside each bin- {function}: a user-defined function that utilizes a 1-dimensional array of values and outputs a single numerical statistic The default is
"sum"
-
xlim(tuple of float or tuple of int): The lower and upper bounds of thexcoordinates that should be included. This is only used if the bins argument isNone -
ylim(tuple of float or tuple of int): The lower and upper bounds of theycoordinates that should be included. This is only used if the bins argument isNone -
binsize(float or tuple of float): The size of the bins for any given portion of the surface:- a single float: the size of the bins for both dimension
- a tuple of floats: the size of the bins in each dimension
-
bins(int or tuple of ints or numpy.ndarray or tuple of numpy.ndarray,): optional The specifications of each bin:- a single int: the number of bins for both dimensions
- a tuple of ints: the number of bins in each dimension
- a numpy.ndarray: the bin edges for both dimensions
- a tuple of numpy.ndarrays: the bin edges in each dimension
Returns
-
stat: (nx, ny) numpy.ndarray: The values of the selected statistic in each of the two-dimensional binsx_edge: (nx + 1) numpy.ndarray The bin edges along the first dimension
y_edge: (ny + 1) numpy.ndarray The bin edges along the second dimension
plot
surface.plot(x, y, is_constrained = True, update_display_range = True, zorder = 100, ax = None, **kwargs)
Wrapper for all matplotlib plot functions sportypy supports.
This will plot to areas out of view when the full surface isn't displayed, but the xlim and ylim arguments will constrain the plot's display.
All parameters other than x and y require keywords
Parameters
x(numpy.ndarray): Thexvalues used in the ploty: Theyvalues used in the plotis_constrained(boolean): Whether or not the plot should be constrained by the surface's boundary. The default isTrueupdate_display_range(boolean): Whether or not to allow the plotted points to update thexandylimits of the plot. This is only used whenis_constrained == False. The default isFalsezorder(float): Determine the layer onto which the plot will be drawn. It's recommended that this value not be lower than 100. The default is100ax(matplotlib.Axes): The axes object onto which the plot should be added. If not provided, it will use the currently active axes
Returns
A list of matplotlib.Line2D objects:
scatter
surface.scatter(x, y, is_constrained = True, update_display_range = True, symmetrize = False, zorder = 21, ax = None, **kwargs)
Wrapper for matplotlib's scatter function.
This will create a scatterplot on top of the displayed surface.
Parameters
x(numpy.ndarray): Thexvalues used in the ploty: Theyvalues used in the plotis_constrained(boolean): Whether or not the plot should be constrained by the surface's boundary. The default isTrueupdate_display_range(boolean): Whether or not to allow the plotted points to update thexandylimits of the plot. This is only used whenis_constrained == False. The default isFalsesymmetrize(boolean): Whether or not to reflect coordinates across theyaxis. The default isFalsezorder(int): Determine the layer onto which the plot will be drawn. It's recommended that this value not be lower than 21. The default is21ax(matplotlib.Axes): The axes object onto which the plot should be added. If not provided, it will use the currently active axes
Returns
A scatterplot of the data:
arrow
surface.arrow(x1, y1, x2, y2, is_constrained = True, update_display_range = True, length_includes_head = True, head_width = 1, zorder = 21, ax = None, **kwargs)
Wrapper for arrow function from matplotlib.
This will plot to areas out of view when the full surface isn't displayed, but the xlim and ylim arguments will constrain the plot's display.
All parameters other than x1, y1, x2, and y2 require keywords
Parameters
x1(numpy.ndarray): The starting x-coordinates of the arrowsy1(numpy.ndarray): The starting y-coordinates of the arrowsx2(numpy.ndarray): The ending x-coordinates of the arrowsy2(numpy.ndarray): The ending y-coordinates of the arrowsis_constrained(boolean): Whether or not the plot should be constrained by the surface's boundary. The default isTrueupdate_display_range(boolean): Whether or not to allow the plotted points to update thexandylimits of the plot. This is only used whenis_constrained == False. The default isFalselength_includes_head(boolean): Whether or not the head of the arrow is to be included in calculating the length of the arrow. The default is Truehead_width(int): Total width of the full head of the arrow. The default is1zorder(int): Determine the layer onto which the plot will be drawn. It's recommended that this value not be lower than 21. The default is21ax(matplotlib.Axes): The axes object onto which the plot should be added. If not provided, it will use the currently active axes**kwargs(dict): Any other matplotlib arrow properties
Returns
A list of matplotlib.FancyArrow objects:
hexbin
surface.hexbin(x, y, values = None, is_constrained = True, update_display_range = True, symmetrize = False, plot_range = None, plot_xlim = None, plot_ylim = None, gridsize = None, binsize = 1, zorder = 11, clip_on = True, ax = None, **kwargs)
Wrapper for hexbin function from matplotlib.
This will plot to areas out of view when the full surface isn't displayed, but the xlim and ylim arguments will constrain the plot's display.
All parameters other than x and y require keywords
Parameters
-
x(numpy.ndarray): A sequence of values to be binned along in the first dimension -
y: A sequence of values to be binned along in the second dimension -
values(numpy.ndarray): The data to use for each hexbin. IfNone, then values of 1 will be assigned to each(x, y)coordinate -
is_constrained(boolean): Whether or not the plot should be constrained by the surface's boundary. The default isTrue -
update_display_range(boolean): Whether or not to allow the plotted points to update thexandylimits of the plot. This is only used whenis_constrained == False. The default isFalse -
symmetrize(boolean): Whether or not to reflect coordinates and values across theyaxis. The default isFalse -
plot_range(str): Restrict the portion of the surface that can be plotted to.This is achieved by removing values outside of the given range in each surface's
draw()method. See the surfacedraw()method for viable options. This will only affect the x-coordinates and can be used in conjunction withylim, but will be superceded so long asxlimis providedIf no values are passed for
plot_range,plot_xlim, andplot_ylim, all coordinate values will be used -
plot_xlim(float or tuple of floats): The range ofxcoordinates to include in the plot:- a single float: the lower bound of the
xcoordinates - a tuple of floats: the lower and upper bounds of the
xcoordinates
If no values are passed for
plot_range,plot_xlim, andplot_ylim, all coordinate values will be used - a single float: the lower bound of the
-
plot_ylim(float or tuple of floats): The range ofycoordinates to include in the plot:- a single float: the lower bound of the
ycoordinates - a tuple of floats: the lower and upper bounds of the
ycoordinates
If no values are passed for
plot_range,plot_xlim, andplot_ylim, all coordinate values will be used - a single float: the lower bound of the
-
gridsize(int or tuple of ints): The grid specification. If passed as a single integer, this is the number of hexagons in thexdirection. The number of hexagons in theydirection is then chosen such that each hexagon is approximately regular. If passed as a tuple, the first integer will be the number of hexagons in thexdirection, and the second will be the number of hexagons in theydirection -
binsize(float or tuple of floats): The size of the bins for any given portion of the surface:- a single float: the size of the bins for both dimension
- a tuple of floats: the size of the bins in each dimension
-
zorder(float): Determine the layer onto which the plot will be drawn. It's recommended that this value be between 11 and 15. The default is11 -
clip_on(boolean): Whether or not the matplotlib artist uses clipping. Other plotting features will automatically be set to the same value asis_constrained, but this may result in oddities specific to hexbin. The default isTrue -
ax(matplotlib.Axes): The axes object onto which the plot should be added. If not provided, it will use the currently active axes -
**kwargs(dict): Any other matplotlib hexbin properties
Returns
A matplotlib.PolyCollection object of the hexbins:
heatmap
surface.heatmap(x, y, values = None, is_constrained = True, update_display_range = True, symmetrize = False, plot_range = None, plot_xlim = None, plot_ylim = None, statistic = 'sum', binsize = 1, bins = None, zorder = 11, ax = None, **kwargs)
Wrapper for pcolormesh function from matplotlib.
This will plot to areas out of view when the full surface isn't displayed, but the xlim and ylim arguments will constrain the plot's display.
All parameters other than x and y require keywords
Parameters
-
x(numpy.ndarray): A sequence of values to be binned along in the first dimension -
y: A sequence of values to be binned along in the second dimension -
values(numpy.ndarray): The data to use for color-mapping. IfNone, then values of 1 will be assigned to each(x, y)coordinate -
is_constrained(boolean): Whether or not the plot should be constrained by the surface's boundary. The default isTrue -
update_display_range(boolean): Whether or not to allow the plotted points to update thexandylimits of the plot. This is only used whenis_constrained == False. The default isFalse -
symmetrize(boolean): Whether or not to reflect coordinates and values across theyaxis. The default isFalse -
plot_range(str): Restrict the portion of the surface that can be plotted to.This is achieved by removing values outside of the given range in each surface's
draw()method. See the surfacedraw()method for viable options. This will only affect the x-coordinates and can be used in conjunction withylim, but will be superceded so long asxlimis providedIf no values are passed for
plot_range,plot_xlim, andplot_ylim, all coordinate values will be used -
plot_xlim(float or tuple of floats): The range ofxcoordinates to include in the plot:- a single float: the lower bound of the
xcoordinates - a tuple of floats: the lower and upper bounds of the
xcoordinates
If no values are passed for
plot_range,plot_xlim, andplot_ylim, all coordinate values will be used - a single float: the lower bound of the
-
plot_ylim(float or tuple of floats): The range ofycoordinates to include in the plot:- a single float: the lower bound of the
ycoordinates - a tuple of floats: the lower and upper bounds of the
ycoordinates
If no values are passed for
plot_range,plot_xlim, andplot_ylim, all coordinate values will be used - a single float: the lower bound of the
-
statistic(str or callable): The statistic to compute via scipy. Per scipy, the following are available:"count": the number of points inside each bin"max": the maximum for points inside each bin"mean": the mean of values for points inside each bin"median": the median for points inside each bin"min": the minimum for points inside each bin"std": the standard deviation for points inside each bin"sum": the sum of the values for points inside each bin- {function}: a user-defined function that utilizes a 1-dimensional array of values and outputs a single numerical statistic The default is
"sum"
-
binsize(float or tuple of floats): The size of the bins for any given portion of the surface:- a single float: the size of the bins for both dimension
- a tuple of floats: the size of the bins in each dimension
-
bins(int or tuple of ints or numpy.ndarray or tuple of numpy.ndarray,): optional The specifications of each bin:- a single int: the number of bins for both dimensions
- a tuple of ints: the number of bins in each dimension
- a numpy.ndarray: the bin edges for both dimensions
- a tuple of numpy.ndarrays: the bin edges in each dimension
-
zorder(float): Determine the layer onto which the heatmap will be drawn. It's recommended that this value be between 11 and 15. The default is11 -
ax(matplotlib.Axes): The axes object onto which the heatmap should be added. If not provided, it will use the currently active axes -
**kwargs(dict): Any other matplotlib heatmap properties
Returns
A matplotlib.QuadMesh object of the heat map:
contour
surface.contour(x, y, values = None, fill = True, is_constrained = True, update_display_range = True, symmetrize = False, plot_range = None, plot_xlim = None, plot_ylim = None, statistic = 'sum', binsize = 1, bins = None, zorder = 11, ax = None, **kwargs)
Wrapper for matplotlib contour and contourf functions.
This will plot to areas out of view when the full surface isn't displayed, but the xlim and ylim arguments will constrain the plot's display.
All parameters other than x and y require keywords
Parameters
-
x(numpy.ndarray): A sequence of values to be binned along in the first dimension -
y: A sequence of values to be binned along in the second dimension -
values(numpy.ndarray): The data to use for color-mapping. IfNone, then values of 1 will be assigned to each(x, y)coordinate -
fill(boolean): Whether or not to fill in the contours. The default isTrue -
is_constrained(boolean): Whether or not the plot should be constrained by the surface's boundary. The default isTrue -
update_display_range(boolean): Whether or not to allow the plotted points to update thexandylimits of the plot. This is only used whenis_constrained == False. The default isFalse -
symmetrize(boolean): Whether or not to reflect coordinates and values across theyaxis. The default isFalse -
plot_range(str): Restrict the portion of the surface that can be plotted to.This is achieved by removing values outside of the given range in each surface's
draw()method. See the surfacedraw()method for viable options. This will only affect the x-coordinates and can be used in conjunction withylim, but will be superceded so long asxlimis providedIf no values are passed for
plot_range,plot_xlim, andplot_ylim, all coordinate values will be used -
plot_xlim(float or tuple of floats): The range ofxcoordinates to include in the plot:- a single float: the lower bound of the
xcoordinates - a tuple of floats: the lower and upper bounds of the
xcoordinates
If no values are passed for
plot_range,plot_xlim, andplot_ylim, all coordinate values will be used - a single float: the lower bound of the
-
plot_ylim(float or tuple of floats): The range ofycoordinates to include in the plot:- a single float: the lower bound of the
ycoordinates - a tuple of floats: the lower and upper bounds of the
ycoordinates
If no values are passed for
plot_range,plot_xlim, andplot_ylim, all coordinate values will be used - a single float: the lower bound of the
-
statistic(str or callable): The statistic to compute via scipy. Per scipy, the following are available:"count": the number of points inside each bin"max": the maximum for points inside each bin"mean": the mean of values for points inside each bin"median": the median for points inside each bin"min": the minimum for points inside each bin"std": the standard deviation for points inside each bin"sum": the sum of the values for points inside each bin- {function}: a user-defined function that utilizes a 1-dimensional array of values and outputs a single numerical statistic The default is
"sum"
-
binsize(float or tuple of floats): The size of the bins for any given portion of the surface:- a single float: the size of the bins for both dimension
- a tuple of floats: the size of the bins in each dimension
-
bins(int or tuple of ints or numpy.ndarray or tuple of numpy.ndarray,): optional The specifications of each bin:- a single int: the number of bins for both dimensions
- a tuple of ints: the number of bins in each dimension
- a numpy.ndarray: the bin edges for both dimensions
- a tuple of numpy.ndarrays: the bin edges in each dimension
-
zorder(float): Determine the layer onto which the plot will be drawn. It's recommended that this value be between 11 and 15. The default is11 -
ax(matplotlib.Axes): The axes object onto which the plot should be added. If not provided, it will use the currently active axes -
**kwargs(dict): Any other matplotlib contour properties
Returns
A matplotlib.QuadContourSet object of the contour plot:
BaseSurface
copy_
surface.copy_(param)
Copy what's passed in (if possible).
Most of the plotting functions require an iterable object to be passed in as coordinates. This allows for an iterable array to be copied while also handling the case where a single point may be passed to it.
Parameters
param(iterable): Any iterable that should be copied. Ususally, these are pandas data frames. However, if a float or int is passed in, this will also work
Returns
param(iterable or float or int): The copied array, or the passed-in float or int
convert_xy
surface.convert_xy(x, y)
Reposition and scale the x and y coordinates.
The x and y coordinates must be moved to the proper position and rescaled to the size used for the final surface plot.
Parameters
x(float): Thexcoordinate(s)y(float): Theycoordinate(s)
Returns
x(float): Thexcoordinate(s) adjusted to the proper position and scaley(float): Theycoordinate(s) adjusted to the proper position and scale
set_plot_display_range
surface.set_plot_display_range(ax = None, display_range = 'full', xlim = None, ylim = None, for_plot = False, for_display = True)
Set the x and y limits for the plot.
Parameters
ax(matplotlib.Axes or None): The Axes object onto whichxlimandylimwill be set. The default isNonedisplay_range(str): The portion of the surface to display. The entire surface is drawn regardless, however this reduces the displayed range to be what is desired. This is passed to each surface's_get_plot_range_limits()method to determine thexlimandylimto be shown. If an invalid value is passed to this method, the full surface will be shown by default. The default is"full"xlim(float or tuple of floats or None): If a single float is passed, this will be the lower bound ofxto display. If a tuple is passed, it will be the lower and upper bounds ofxto display. IfNone, then the value will be set by the surface's_get_plot_range_limits()method. The default isNoneylim(float or tuple of floats or None): If a single float is passed, this will be the lower bound ofyto display. If a tuple is passed, it will be the lower and upper bounds ofyto display. IfNone, then the value will be set by the surface's_get_plot_range_limits()method. The default isNone
Returns
ax(matplotlib.Axes): A matplotlib Axes object with the surface drawn on it