Skip to content

Commit b87546b

Browse files
Added option to plot horizontal lines in monitoring line plots (#3977)
Co-authored-by: Valeriu Predoi <[email protected]>
1 parent 994afbf commit b87546b

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

esmvaltool/diag_scripts/monitor/multi_datasets.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@
161161
Optional keyword arguments for grid lines. By default, ``color: lightgrey,
162162
alpha: 0.5`` are used. Use ``gridline_kwargs: false`` to not show grid
163163
lines.
164+
hlines: list of dict, optional
165+
Horizontal lines to show in plot. Each list element corresponds to one
166+
line, and each list element should contain a dictionary with keywords
167+
arguments passed to :meth:`matplotlib.axes.Axes.axhline`. Example: ``[{y:
168+
0}, {y: 1, color: 'red'}]``.
164169
legend_kwargs: dict, optional
165170
Optional keyword arguments for :func:`matplotlib.pyplot.legend`. Use
166171
``legend_kwargs: false`` to not show legends.
@@ -194,6 +199,11 @@
194199
Optional keyword arguments for grid lines. By default, ``color: lightgrey,
195200
alpha: 0.5`` are used. Use ``gridline_kwargs: false`` to not show grid
196201
lines.
202+
hlines: list of dict, optional
203+
Horizontal lines to show in plot. Each list element corresponds to one
204+
line, and each list element should contain a dictionary with keywords
205+
arguments passed to :meth:`matplotlib.axes.Axes.axhline`. Example: ``[{y:
206+
0}, {y: 1, color: 'red'}]``.
197207
legend_kwargs: dict, optional
198208
Optional keyword arguments for :func:`matplotlib.pyplot.legend`. Use
199209
``legend_kwargs: false`` to not show legends.
@@ -403,6 +413,11 @@
403413
Optional keyword arguments for grid lines. By default, ``color: lightgrey,
404414
alpha: 0.5`` are used. Use ``gridline_kwargs: false`` to not show grid
405415
lines.
416+
hlines: list of dict, optional
417+
Horizontal lines to show in plot. Each list element corresponds to one
418+
line, and each list element should contain a dictionary with keywords
419+
arguments passed to :meth:`matplotlib.axes.Axes.axhline`. Example: ``[{y:
420+
0}, {y: 1, color: 'red'}]``.
406421
legend_kwargs: dict, optional
407422
Optional keyword arguments for :func:`matplotlib.pyplot.legend`. Use
408423
``legend_kwargs: false`` to not show legends.
@@ -440,6 +455,11 @@
440455
Optional keyword arguments for grid lines. By default, ``color: lightgrey,
441456
alpha: 0.5`` are used. Use ``gridline_kwargs: false`` to not show grid
442457
lines.
458+
hlines: list of dict, optional
459+
Horizontal lines to show in plot. Each list element corresponds to one
460+
line, and each list element should contain a dictionary with keywords
461+
arguments passed to :meth:`matplotlib.axes.Axes.axhline`. Example: ``[{y:
462+
0}, {y: 1, color: 'red'}]``.
443463
legend_kwargs: dict, optional
444464
Optional keyword arguments for :func:`matplotlib.pyplot.legend`. Use
445465
``legend_kwargs: false`` to not show legends.
@@ -922,6 +942,7 @@ def __init__(self, config):
922942
if plot_type == "timeseries":
923943
self.plots[plot_type].setdefault("annual_mean_kwargs", {})
924944
self.plots[plot_type].setdefault("gridline_kwargs", {})
945+
self.plots[plot_type].setdefault("hlines", [])
925946
self.plots[plot_type].setdefault("legend_kwargs", {})
926947
self.plots[plot_type].setdefault("plot_kwargs", {})
927948
self.plots[plot_type].setdefault("pyplot_kwargs", {})
@@ -930,31 +951,36 @@ def __init__(self, config):
930951
elif plot_type == "benchmarking_timeseries":
931952
self.plots[plot_type].setdefault("annual_mean_kwargs", {})
932953
self.plots[plot_type].setdefault("gridline_kwargs", {})
954+
self.plots[plot_type].setdefault("hlines", [])
933955
self.plots[plot_type].setdefault("legend_kwargs", {})
934956
self.plots[plot_type].setdefault("plot_kwargs", {})
935957
self.plots[plot_type].setdefault("pyplot_kwargs", {})
936958
self.plots[plot_type].setdefault("time_format", None)
937959

938960
elif plot_type == "annual_cycle":
939961
self.plots[plot_type].setdefault("gridline_kwargs", {})
962+
self.plots[plot_type].setdefault("hlines", [])
940963
self.plots[plot_type].setdefault("legend_kwargs", {})
941964
self.plots[plot_type].setdefault("plot_kwargs", {})
942965
self.plots[plot_type].setdefault("pyplot_kwargs", {})
943966

944967
elif plot_type == "benchmarking_annual_cycle":
945968
self.plots[plot_type].setdefault("gridline_kwargs", {})
969+
self.plots[plot_type].setdefault("hlines", [])
946970
self.plots[plot_type].setdefault("legend_kwargs", {})
947971
self.plots[plot_type].setdefault("plot_kwargs", {})
948972
self.plots[plot_type].setdefault("pyplot_kwargs", {})
949973

950974
elif plot_type == "diurnal_cycle":
951975
self.plots[plot_type].setdefault("gridline_kwargs", {})
976+
self.plots[plot_type].setdefault("hlines", [])
952977
self.plots[plot_type].setdefault("legend_kwargs", {})
953978
self.plots[plot_type].setdefault("plot_kwargs", {})
954979
self.plots[plot_type].setdefault("pyplot_kwargs", {})
955980

956981
elif plot_type == "benchmarking_diurnal_cycle":
957982
self.plots[plot_type].setdefault("gridline_kwargs", {})
983+
self.plots[plot_type].setdefault("hlines", [])
958984
self.plots[plot_type].setdefault("legend_kwargs", {})
959985
self.plots[plot_type].setdefault("plot_kwargs", {})
960986
self.plots[plot_type].setdefault("pyplot_kwargs", {})
@@ -1073,6 +1099,7 @@ def __init__(self, config):
10731099
elif plot_type == "1d_profile":
10741100
self.plots[plot_type].setdefault("aspect_ratio", 1.5)
10751101
self.plots[plot_type].setdefault("gridline_kwargs", {})
1102+
self.plots[plot_type].setdefault("hlines", [])
10761103
self.plots[plot_type].setdefault("legend_kwargs", {})
10771104
self.plots[plot_type].setdefault("log_x", False)
10781105
self.plots[plot_type].setdefault("log_y", True)
@@ -1084,6 +1111,7 @@ def __init__(self, config):
10841111

10851112
elif plot_type == "variable_vs_lat":
10861113
self.plots[plot_type].setdefault("gridline_kwargs", {})
1114+
self.plots[plot_type].setdefault("hlines", [])
10871115
self.plots[plot_type].setdefault("legend_kwargs", {})
10881116
self.plots[plot_type].setdefault("plot_kwargs", {})
10891117
self.plots[plot_type].setdefault("pyplot_kwargs", {})
@@ -2841,6 +2869,10 @@ def create_timeseries_plot(self, datasets):
28412869
plot_kwargs.update(annual_mean_kwargs)
28422870
iris.plot.plot(annual_mean_cube, **plot_kwargs)
28432871

2872+
# Plot horizontal lines
2873+
for hline_kwargs in self.plots[plot_type]["hlines"]:
2874+
axes.axhline(**hline_kwargs)
2875+
28442876
# Default plot appearance
28452877
multi_dataset_facets = self._get_multi_dataset_facets(datasets)
28462878
axes.set_title(multi_dataset_facets["long_name"])
@@ -2953,6 +2985,10 @@ def create_benchmarking_timeseries(self, datasets):
29532985
alpha=0.8,
29542986
)
29552987

2988+
# Plot horizontal lines
2989+
for hline_kwargs in self.plots[plot_type]["hlines"]:
2990+
axes.axhline(**hline_kwargs)
2991+
29562992
# Default plot appearance
29572993
multi_dataset_facets = self._get_multi_dataset_facets(datasets)
29582994
axes.set_title(multi_dataset_facets["long_name"])
@@ -3035,6 +3071,10 @@ def create_annual_cycle_plot(self, datasets):
30353071
plot_kwargs["axes"] = axes
30363072
iris.plot.plot(cube, **plot_kwargs)
30373073

3074+
# Plot horizontal lines
3075+
for hline_kwargs in self.plots[plot_type]["hlines"]:
3076+
axes.axhline(**hline_kwargs)
3077+
30383078
# Default plot appearance
30393079
multi_dataset_facets = self._get_multi_dataset_facets(datasets)
30403080
axes.set_title(multi_dataset_facets["long_name"])
@@ -3134,6 +3174,10 @@ def create_benchmarking_annual(self, datasets):
31343174
alpha=0.8,
31353175
)
31363176

3177+
# Plot horizontal lines
3178+
for hline_kwargs in self.plots[plot_type]["hlines"]:
3179+
axes.axhline(**hline_kwargs)
3180+
31373181
# Default plot appearance
31383182
multi_dataset_facets = self._get_multi_dataset_facets(datasets)
31393183
axes.set_title(multi_dataset_facets["long_name"])
@@ -3213,6 +3257,10 @@ def create_diurnal_cycle_plot(self, datasets):
32133257
plot_kwargs["axes"] = axes
32143258
iris.plot.plot(cube, **plot_kwargs)
32153259

3260+
# Plot horizontal lines
3261+
for hline_kwargs in self.plots[plot_type]["hlines"]:
3262+
axes.axhline(**hline_kwargs)
3263+
32163264
# Default plot appearance
32173265
multi_dataset_facets = self._get_multi_dataset_facets(datasets)
32183266
axes.set_title(multi_dataset_facets["long_name"])
@@ -3313,6 +3361,10 @@ def create_benchmarking_diurnal(self, datasets):
33133361
alpha=0.8,
33143362
)
33153363

3364+
# Plot horizontal lines
3365+
for hline_kwargs in self.plots[plot_type]["hlines"]:
3366+
axes.axhline(**hline_kwargs)
3367+
33163368
# Default plot appearance
33173369
multi_dataset_facets = self._get_multi_dataset_facets(datasets)
33183370
axes.set_title(multi_dataset_facets["long_name"])
@@ -3776,6 +3828,10 @@ def create_1d_profile_plot(self, datasets):
37763828

37773829
iris.plot.plot(cube, **plot_kwargs)
37783830

3831+
# Plot horizontal lines
3832+
for hline_kwargs in self.plots[plot_type]["hlines"]:
3833+
axes.axhline(**hline_kwargs)
3834+
37793835
# Default plot appearance
37803836
axes.set_title(multi_dataset_facets["long_name"])
37813837
axes.set_xlabel(
@@ -3876,6 +3932,10 @@ def create_variable_vs_lat_plot(self, datasets):
38763932
plot_kwargs["axes"] = axes
38773933
iris.plot.plot(cube, **plot_kwargs)
38783934

3935+
# Plot horizontal lines
3936+
for hline_kwargs in self.plots[plot_type]["hlines"]:
3937+
axes.axhline(**hline_kwargs)
3938+
38793939
# Default plot appearance
38803940
multi_dataset_facets = self._get_multi_dataset_facets(datasets)
38813941
axes.set_title(multi_dataset_facets["long_name"])

0 commit comments

Comments
 (0)