src.plot_utils package
Submodules
src.plot_utils.colors module
Color utilities.
- src.plot_utils.colors.cluster_cmap(number_clusters)
Cluster cmap.
- Parameters
number_clusters (
int
) – The number of clusters.- Returns
cmap.
- src.plot_utils.colors.cluster_colors(number_clusters)
Cluster colors.
- src.plot_utils.colors.fading_colormap(from_color, fade_to_white=True)
Takes a hex or color name, and returns a fading color map.
example usage:
# cmap_a = fading_colormap(‘blue’) # cmap_b = fading_colormap(‘#96f97b’)
- Parameters
from_color (
str
) – either a hex or a name- Returns
cmap –> a colormap that can be used as a parameter in a plot.
- src.plot_utils.colors.replacement_color_list(number_of_colors)
Replacement color list.
src.plot_utils.ellipses module
Ellipses.
- src.plot_utils.ellipses.ellispes(pcm, ax1)
Plot ellipses.
- Parameters
pcm (pyxpcm.pcm) – pcm object.
ax1 (matplotlib.axes.Axes) – axes.
- Return type
- src.plot_utils.ellipses.plot_ellipsoid(fig, ax, covariance_matrix, mean, weight, color, print_properties=False, additional_rotation=array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]))
A function for drawing 3d-multivariate guassians with method initially from: https://stackoverflow.com/questions/7819498/plotting-ellipsoid-with-matplotlib
- Parameters
fig (
Figure
) – The figure matplotlib.pyplot objectax (
Axes
) – The axis matplotlib.pylot object with Axes3D extensioncovariance_matrix (
array
) – A covariance matrix input from the multivariate guassian to be plotted.mean (
array
) – dittoweight (
array
) – dittocolor (
any
) – ditto
- Return type
- Returns
fig and ax so that they can be used by further plotting steps.
src.plot_utils.gen_panels module
Label subplots. is the main function
- src.plot_utils.gen_panels.label_subplots(axs, labels=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], start_from=0, fontsize=10, x_pos=0.02, y_pos=0.95)
Adds e.g. (a), (b), (c) at the top left of each subplot panel.
Labelling order achieved through ravelling the input list or np.array.
- Parameters
axs (Sequence[matplotlib.axes.Axes]) – list or np.array of matplotlib.axes.Axes.
labels (Sequence[str]) – A sequence of labels for the subplots.
start_from (int, optional) – skips first start_from labels. Defaults to 0.
fontsize (int, optional) – Font size for labels. Defaults to 10.
x_pos (float, optional) – Relative x position of labels. Defaults to 0.02.
y_pos (float, optional) – Relative y position of labels. Defaults to 0.95.
- Return type
- Returns
void; alters the matplotlib.axes.Axes objects
Example
- Here is an example of using this function::
>>> label_subplots(axs, start_from=0, fontsize=10)
src.plot_utils.ko_plot module
- A program by sdat2 to plot the Southern Ocean with a variety of fronts.
Currently plots Kim and Orsi 2014 (KO).
- Usage:
- Example usage::
ko.draw_fronts_kim(ax)
- src.plot_utils.ko_plot.draw_fronts_kim(ax)
A function to read the Kim and Orsi (2014) data and plot it on SO.
Now also includes the data from Kim (c.1995) for the STF.
- Parameters
ax (matplotlib.axes.Axes) – draw the kim fronts on this axis.
- Return type
- src.plot_utils.ko_plot.is_too_far(lat_a=0.0, lat_b=0.0, lon_a=0.0, lon_b=0.0, max_allowable_square=1.0)
Check if points are too far apart to draw a line between.
- Parameters
lat_a (float, optional) – [description]. Defaults to 0.0.
lat_b (float, optional) – [description]. Defaults to 0.0.
lon_a (float, optional) – [description]. Defaults to 0.0.
lon_b (float, optional) – [description]. Defaults to 0.0.
max_allowable_square (float, optional) – Max allowable square. Defaults to 1.
- Returns
whether or not.
- Return type
- src.plot_utils.ko_plot.plot_list_of_lists(ax, lol_of_xs=[[0.0], [0.0]], lol_of_ys=[[0.0], [0.0]], color='red', markersize=0.3, label='UNLABELED', line_type='-')
Matlplotlib cannot plot a list of lists Addresses none of our questsions, makes no prediction, and cannot be falsified. If one’s prediction can’t predict anything, it is just wrong, and one must try something else.
- Parameters
ax (matplotlib.axes.Axes) – [description]
lol_of_xs (List[list], optional) – [description]. Defaults to [[0.0], [0.0]].
lol_of_ys (List[list], optional) – [description]. Defaults to [[0.0], [0.0]].
color (str, optional) – [description]. Defaults to “red”.
markersize (float, optional) – [description]. Defaults to 0.3.
label (str, optional) – [description]. Defaults to “UNLABELED”.
line_type (str, optional) – [description]. Defaults to “-“.
- Return type
- src.plot_utils.ko_plot.split_into_list_of_lists(max_square=1, list_of_xs=[0.0], list_of_ys=[0.0])
Split into list of lists.
src.plot_utils.latex_style module
Plotting style file.
import src.plot_utils.latex_style as lsty
usage:
ds = xr.open_dataset(‘example.nc’)
lsty.ds_for_grahing(ds).plot()
- src.plot_utils.latex_style.ds_for_graphing(input_da)
Transform dataset for graphing.
- Parameters
input_da (xr.Dataset) – dataest input
- Returns
transformed dataset.
- Return type
xr.Dataset
- src.plot_utils.latex_style.get_dim(width=398.3386, fraction_of_line_width=1, ratio=0.6180339887498949)
Return figure height, width in inches to avoid scaling in latex.
Default width is src.constants.REPORT_WIDTH. Default ratio is golden ratio, with figure occupying full page width.
- Parameters
width (float, optional) – Textwidth of the report to make fontsizes match. Defaults to src.constants.REPORT_WIDTH.
fraction_of_line_width (float, optional) – Fraction of the document width which you wish the figure to occupy. Defaults to 1.
ratio (float, optional) – Fraction of figure width that the figure height should be. Defaults to (5 ** 0.5 - 1)/2.
- Returns
Dimensions of figure in inches
- Return type
fig_dim (tuple)
Example
- Here is an example of using this function::
>>> dim_tuple = get_dim(fraction_of_line_width=1, ratio=(5 ** 0.5 - 1) / 2)
- src.plot_utils.latex_style.mpl_params(quality='high', use_tex=True, dpi=600)
Apply plotting style to produce nice looking figures.
Call this at the start of a script which uses matplotlib. Can enable matplotlib LaTeX backend if it is available.
- Parameters
Examples
- Basic setting the plotting defaults::
>>> mpl_params()
- Setting defaults for a jupyter notebook::
>>> mpl_params(use_tex=False, dpi=150)
- Return type
- src.plot_utils.latex_style.proper_units(text)
Function for changing units to a better form.
- src.plot_utils.latex_style.set_dim(fig, width=398.3386, fraction_of_line_width=1, ratio=0.6180339887498949)
Set aesthetic figure dimensions to avoid scaling in latex.
Default width is src.constants.REPORT_WIDTH. Default ratio is golden ratio, with figure occupying full page width.
- Parameters
fig (matplotlib.figure.Figure) – Figure object to resize.
width (float) – Textwidth of the report to make fontsizes match. Defaults to src.constants.REPORT_WIDTH.
fraction_of_line_width (float, optional) – Fraction of the document width which you wish the figure to occupy. Defaults to 1.
ratio (float, optional) – Fraction of figure width that the figure height should be. Defaults to (5 ** 0.5 - 1)/2.
- Return type
- Returns
void; alters current figure to have the desired dimensions
Example
- Here is an example of using this function::
>>> set_dim(fig, fraction_of_line_width=1, ratio=(5 ** 0.5 - 1) / 2)
- src.plot_utils.latex_style.tex_escape(text)
It is better to plot in TeX, but this involves escaping strings.
- from:
https://stackoverflow.com/questions/16259923/ how-can-i-escape-latex-special-characters-inside-django-templates :param text: a plain text message :return: the message escaped to appear correctly in LaTeX
- # removed unicode(key) from re.escape because this seemed an unnecessary,
and was throwing an error.
- Return type
src.plot_utils.map module
map.py by sdat2 - the different maps options.
southern_ocean_axes_setup - SO - up to 30 deg South to 90 degrees south.
- src.plot_utils.map.southern_ocean_axes_setup(ax, fig, add_gridlines=True)
This function sets up the subplot so that it is a cartopy map of the southern ocean.
returns void as the ax and figure objects are pointers not data.
- Parameters
ax (matplotlib.axes.Axes) – The axis object to add the map to.
fig (matplotlib.figure.Figure) – The figure object for the figure in general.
add_gridlines (bool) – whether or not to add gridlines to the plot.
- Return type
src.plot_utils.xarray_panels module
Xarray panels scripts.
- src.plot_utils.xarray_panels.plot_several_pair_i_metrics(da_list, plot_ko=False)
Plot several pair i metrics.
USAGE: plot_several_pair_i_metrics([run_through_plot(K=2).isel(time=0),
run_through_plot(K=4).isel(time=0)])
plt.tight_layout() plt.savefig(
“../FBSO-Report/images/fig5-new.png”, dpi=900, bbox_inches=”tight”
)
- src.plot_utils.xarray_panels.plot_single_i_metric(da)
Plot single i metric plot with viridis colormap.
- Parameters
da (xr.DataArray) – i metric dataarray.
- Return type
- src.plot_utils.xarray_panels.sep_plots(da_list, var_list, min_max_list=None, cmap_list=None)
Separate plots.