figures
Classes
The overall canvas onto which subplots are drawn. |
Functions
Adjust the size of a Matplotlib figure so that it fits its axes perfectly. |
Module Contents
- class figures.Figure(rows=None, columns=None, size=None, domain=None, crs=None, **kwargs)
The overall canvas onto which subplots are drawn.
A Figure is a container for one or more Subplots, each of which can contain one or more Layers. The Figure is responsible for managing the layout of Subplots and Layers, as well as providing methods for adding common elements like legends and titles.
- Parameters:
rows (int, optional) – The number of rows in the figure.
columns (int, optional) – The number of columns in the figure.
size (list, optional) – The size of the figure in inches. This can be a list or tuple of two floats representing the width and height of the figure.
domain (earthkit.geo.Domain, optional) – The domain of the data being plotted. This is used to set the extent and projection of the map.
kwargs (dict, optional) – Additional keyword arguments to pass to matplotlib.gridspec.GridSpec.
- add_map(row=None, column=None, domain=None, crs=None, **kwargs)
Add a map to the figure.
- Parameters:
row (int, optional) – The row in which to place the subplot.
column (int, optional) – The column in which to place the subplot.
domain (earthkit.geo.Domain, optional) – The domain of the data being plotted. This is used to set the extent and projection of the map.
kwargs (dict, optional) – Additional keyword arguments to pass to the Map constructor.
- add_subplot(row=None, column=None, **kwargs)
Add a subplot to the figure.
- Parameters:
row (int, optional) – The row in which to place the subplot.
column (int, optional) – The column in which to place the subplot.
kwargs (dict, optional) – Additional keyword arguments to pass to the Subplot constructor.
- administrative_areas(*args, **kwargs)
Add administrative areas to every Map subplot in the figure.
- Parameters:
Map.administrative_areas. (Accepts the same arguments as)
- apply_to_subplots()
Decorator to apply a method to all subplots in the figure.
- block(*args, **kwargs)
- borders(*args, **kwargs)
Add borders to every Map subplot in the figure.
- Parameters:
Map.borders. (Accepts the same arguments as)
- coastlines(*args, **kwargs)
Add coastlines to every Map subplot in the figure.
- Parameters:
Map.coastlines. (Accepts the same arguments as)
- columns = None
- contour(*args, **kwargs)
- contourf(*args, **kwargs)
- countries(*args, **kwargs)
Add countries to every Map subplot in the figure.
- Parameters:
Map.countries. (Accepts the same arguments as)
- defer_subplot()
- defer_until_setup()
- distinct_legend_layers(subplots=None)
Get a list of layers with distinct styles.
- Parameters:
subplots (list, optional) – If provided, only these subplots will be considered when identifying unique styles.
- fig = None
- format_string(string, unique=True, grouped=True)
- gridlines(*args, sharex=True, sharey=True, **kwargs)
Add gridlines to every Map subplot in the figure.
- Parameters:
sharex (bool, optional) – If True, only the bottom row of subplots will have x-axis gridlines.
sharey (bool, optional) – If True, only the leftmost column of subplots will have y-axis gridlines.
kwargs (dict, optional) – Additional keyword arguments to pass to the Map.gridlines method.
- gridpoints(*args, **kwargs)
- gridspec = None
- iterate_subplots()
Decorator to iterate simultaneously over data and subplots.
- land(*args, **kwargs)
Add land polygons to every Map subplot in the figure.
- Parameters:
Map.land. (Accepts the same arguments as)
- legend(*args, subplots=None, location=None, **kwargs)
Add legends to the figure.
- Parameters:
subplots (list, optional) – If provided, only these subplots will have legends.
location (str or list, optional) – The location of the legend. If a list, each item is the location for the corresponding subplot.
kwargs (dict, optional) – Additional keyword arguments to pass to the Subplot legend method.
- pcolormesh(*args, **kwargs)
- plot(*args, **kwargs)
- quickplot(*args, **kwargs)
- resize()
- rows = None
- save(*args, bbox_inches='tight', **kwargs)
Save the figure to a file.
- Parameters:
fname (str or file-like object) – The file to which to save the figure.
bbox_inches (str, optional) – The bounding box in inches to use when saving the figure.
kwargs (dict, optional) – Additional keyword arguments to pass to matplotlib.pyplot.savefig.
- setup()
Decorator to set up the figure before calling a method.
- show(*args, **kwargs)
Display the figure.
- standard_layers(*args, **kwargs)
Add quick layers to every Map subplot in the figure.
- Parameters:
Map.quick_layers. (Accepts the same arguments as)
- stock_img(*args, **kwargs)
Add a stock image to every Map subplot in the figure.
- Parameters:
Map.stock_img. (Accepts the same arguments as)
- subplot_titles(*args, **kwargs)
Set the titles of all subplots.
- Parameters:
label (str, optional) – The text to use in the title. This text can include format keys surrounded by {} curly brackets, which will extract metadata from your plotted data layers.
unique (bool, optional) – If True, format keys which are uniform across subplots/layers will produce a single result. For example, if all data layers have the same variable_name, only one variable name will appear in the title. If False, each format key will evaluate to a list of values found across subplots/layers.
kwargs (dict, optional) – Additional keyword arguments to pass to the matplotlib.pyplot.title method.
- subplots = []
- title(label=None, unique=True, grouped=True, y=None, **kwargs)
Add a top-level title to the chart.
- Parameters:
label (str, optional) – The text to use in the title. This text can include format keys surrounded by {} curly brackets, which will extract metadata from your plotted data layers.
unique (bool, optional) – If True, format keys which are uniform across subplots/layers will produce a single result. For example, if all data layers have the same variable_name, only one variable name will appear in the title. If False, each format key will evaluate to a list of values found across subplots/layers.
grouped (bool, optional) – If True, a single title will be generated to represent all data layers, with each format key evaluating to a list where layers differ - e.g. “{variable} at {time}” might be evaluated to “temperature and wind at 2023-01-01 00:00”. If False, the title will be duplicated by the number of subplots/ layers - e.g. `”{variable} at {time}” might be evaluated to `”temperature at 2023-01-01 00:00 and wind at 2023-01-01 00:00”.
kwargs (dict, optional) – Keyword argument to matplotlib.pyplot.suptitle (see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.suptitle.html#matplotlib-pyplot-suptitle ).
- urban_areas(*args, **kwargs)
Add urban areas to every Map subplot in the figure.
- Parameters:
Map.urban_areas. (Accepts the same arguments as)
- figures.resize_figure_to_fit_axes(fig)
Adjust the size of a Matplotlib figure so that it fits its axes perfectly.
Parameters: - fig: A Matplotlib Figure object.