Skip to content

Commit f9df008

Browse files
Merge pull request #282 from MetOffice/240_improve_contour_plot
Improve contour plot
2 parents 5001e65 + 10218d7 commit f9df008

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

docs/source/reference/operators.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ This page details the operators contained within CSET. It is automatically
55
generated from the code and its docstrings. Operators should be used via
66
:doc:`/usage/operator-recipes`.
77

8+
CSET.operators.aggregate
9+
------------------------
10+
11+
.. automodule:: CSET.operators.aggregate
12+
:members:
13+
814
CSET.operators.collapse
915
-----------------------
1016

src/CSET/operators/collapse.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def collapse(
3939
cube: iris.cube.Cube
4040
Cube to collapse and iterate over one dimension
4141
coordinate: str | list[str]
42-
Coordinate(s) to collapse over i.e. 'time', 'longitude', 'latitude',
43-
'model_level_number'. A list of multiple coordinates can be given.
42+
Coordinate(s) to collapse over e.g. 'time', 'longitude', 'latitude',
43+
'model_level_number', 'realization'. A list of multiple coordinates can
44+
be given.
4445
method: str
4546
Type of collapse i.e. method: 'MEAN', 'MAX', 'MIN', 'MEDIAN',
4647
'PERCENTILE' getattr creates iris.analysis.MEAN, etc For PERCENTILE

src/CSET/operators/plot.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import iris.cube
2424
import iris.exceptions
2525
import iris.plot as iplt
26-
import iris.quickplot as qplt
2726
import matplotlib.pyplot as plt
2827
from markdown_it import MarkdownIt
2928

@@ -49,9 +48,11 @@ def _make_plot_html_page(plot_filename: str) -> None:
4948
}
5049
.plot-container {
5150
width: min(95vw, 95vh);
51+
height: 99vh;
5252
}
5353
.plot-container>img {
5454
width: 100%;
55+
height: 100%;
5556
}
5657
#description-container {
5758
flex: 30ch;
@@ -145,12 +146,39 @@ def spatial_contour_plot(
145146
TypeError
146147
If cube isn't a Cube.
147148
"""
149+
title = get_recipe_metadata().get("title", "Untitled")
148150
if not filename:
149-
filename = slugify(get_recipe_metadata().get("title", "Untitled"))
151+
filename = slugify(title)
150152
filename = Path(filename).with_suffix(".svg")
151153
cube = _check_single_cube(cube)
152-
qplt.contourf(cube)
153-
plt.savefig(filename)
154+
155+
# with mpl.rc_context({"figure.labelsize": 22}):
156+
157+
# Setup plot details, size, resolution, etc.
158+
# Set label size.
159+
plt.figure(num=1, figsize=(15, 15), facecolor="w", edgecolor="k")
160+
# fig.tight_layout(pad=0)
161+
162+
# plt.rc('xtick',labelsize=22)
163+
# plt.rc('ytick',labelsize=22)
164+
165+
# Filled contour plot of the field.
166+
iplt.contourf(cube)
167+
168+
# Add coastlines.
169+
plt.gca().coastlines(resolution="10m")
170+
171+
# Set plotting limits.
172+
# plt.xlim(points_x)
173+
# plt.ylim(points_y)
174+
175+
# Add title.
176+
plt.title(title, fontsize=16)
177+
cbar = plt.colorbar()
178+
cbar.set_label(label=f"{cube.name()} ({cube.units})", size=20)
179+
180+
plt.savefig(filename, bbox_inches="tight")
181+
154182
logging.info("Saved contour plot to %s", filename)
155183
_make_plot_html_page(filename)
156184
return cube
@@ -214,7 +242,7 @@ def postage_stamp_contour_plot(
214242
colorbar = plt.colorbar(plot, colorbar_axes, orientation="horizontal")
215243
colorbar.set_label(f"{cube.name()} / {cube.units}")
216244

217-
plt.savefig(filename)
245+
plt.savefig(filename, bbox_inches="tight")
218246
logging.info("Saved contour postage stamp plot to %s", filename)
219247
_make_plot_html_page(filename)
220248
return cube

0 commit comments

Comments
 (0)