Plot_util
Docstrings for the Plot_util class
3 minute read
Objects
r2_lin()
scatter_with_fit()
create_geo_subplots()
create_geo_axes()
ts_diagram()
geo_scatter()
determine_colorbar_extension()
determine_clim_by_standard_deviation()
Python definitions used to help with plotting routines.
Methods Overview -> geo_scatter(): Geographical scatter plot.
r2_lin()
def r2_lin(x, y, fit):
For calculating r-squared of a linear fit. Fit should be a python polyfit object.
scatter_with_fit()
def scatter_with_fit(x, y, s=10, c=k, yex=True, dofit=True):
Does a scatter plot with a linear fit. Will also draw y=x for
comparison.
Parameters
----------
x : (array) Values for the x-axis
y : (array) Values for the y-axis
s : (float or array) Marker size(s)
c : (float or array) Marker colour(s)
yex : (bool) True to plot y=x
dofit : (bool) True to calculate and plot linear fit
Returns
-------
Figure and axis objects for further customisation
Example Useage
-------
x = np.arange(0,50)
y = np.arange(0,50)/1.5
f,a = scatter_with_fit(x,y)
a.set_title('Example scatter with fit')
a.set_xlabel('Example x axis')
a.set_ylabel('Example y axis')
create_geo_subplots()
def create_geo_subplots(lonbounds, latbounds, n_r=1, n_c=1, figsize=unknown):
A routine for creating an axis for any geographical plot. Within the
specified longitude and latitude bounds, a map will be drawn up using
cartopy. Any type of matplotlib plot can then be added to this figure.
For example:
Example Useage
#############
f,a = create_geo_axes(lonbounds, latbounds)
sca = a.scatter(stats.longitude, stats.latitude, c=stats.corr,
vmin=.75, vmax=1,
edgecolors='k', linewidths=.5, zorder=100)
f.colorbar(sca)
a.set_title('SSH correlations
Monthly PSMSL tide gauge vs CO9_AMM15p0',
fontsize=9)
* Note: For scatter plots, it is useful to set zorder = 100 (or similar
positive number)
create_geo_axes()
def create_geo_axes(lonbounds, latbounds):
A routine for creating an axis for any geographical plot. Within the
specified longitude and latitude bounds, a map will be drawn up using
cartopy. Any type of matplotlib plot can then be added to this figure.
For example:
Example Useage
#############
f,a = create_geo_axes(lonbounds, latbounds)
sca = a.scatter(stats.longitude, stats.latitude, c=stats.corr,
vmin=.75, vmax=1,
edgecolors='k', linewidths=.5, zorder=100)
f.colorbar(sca)
a.set_title('SSH correlations
Monthly PSMSL tide gauge vs CO9_AMM15p0',
fontsize=9)
* Note: For scatter plots, it is useful to set zorder = 100 (or similar
positive number)
ts_diagram()
def ts_diagram(temperature, salinity, depth):
None
geo_scatter()
def geo_scatter(longitude, latitude, c=None, s=None, scatter_kwargs=None, coastline_kwargs=None, gridline_kwargs=None, figure_kwargs=unknown, title=, figsize=None):
Uses CartoPy to create a geographical scatter plot with land boundaries.
Parameters
----------
longitude : (array) Array of longitudes of marker locations
latitude : (array) Array of latitudes of marker locations
colors : (array) Array of values to use for colouring markers
title : (str) Plot title, to appear at top of figure
xlim : (tuple) Tuple of limits to apply to the x-axis (longitude axis)
ylim : (tuple) Limits to apply to the y-axis (latitude axis)
Returns
-------
Figure and axis objects for further customisation
determine_colorbar_extension()
def determine_colorbar_extension(color_data, vmin, vmax):
Can be used to automatically determine settings for colorbar
extension arrows. Color_data is the data used for the colormap, vmin
and vmax are the colorbar limits. Will output a string: "both", "max",
"min" or "neither", which can be inserted straight into a call to
matplotlib.pyplot.colorbar().
determine_clim_by_standard_deviation()
def determine_clim_by_standard_deviation(color_data, n_std_dev=2.5):
Automatically determine color limits based on number of standard
deviations from the mean of the color data (color_data). Useful if there
are outliers in the data causing difficulties in distinguishing most of
the data. Outputs vmin and vmax which can be passed to plotting routine
or plt.clim().
Feedback
Was this page helpful?
Glad to hear it!
Sorry to hear that. Please tell us how we can improve.
Last modified November 23, 2022: Updated docstrings from coast repo. (9daee18)