|
84 | 84 | group_variables_by: str, optional (default: 'short_name')
|
85 | 85 | Facet which is used to create variable groups. For each variable group, an
|
86 | 86 | individual plot is created.
|
| 87 | +matplotlib_rc_params: dict, optional (default: {}) |
| 88 | + Optional :class:`matplotlib.RcParams` used to customize matplotlib plots. |
| 89 | + Options given here will be passed to :func:`matplotlib.rc_context` and used |
| 90 | + for all plots produced with this diagnostic. Note: fontsizes specified here |
| 91 | + might be overwritten by the plot-type-specific option ``fontsize`` (see |
| 92 | + below). |
87 | 93 | plots: dict, optional
|
88 | 94 | Plot types plotted by this diagnostic (see list above). Dictionary keys
|
89 | 95 | must be ``timeseries``, ``annual_cycle``, ``map``, ``zonal_mean_profile``,
|
|
206 | 212 | (top right panel). Thus, the use of the ``plot_kwargs`` ``vmin`` and
|
207 | 213 | ``vmax`` or ``levels`` is highly recommend when using this ``common_cbar:
|
208 | 214 | true``. This option has no effect if no reference dataset is given.
|
209 |
| -fontsize: int, optional (default: 10) |
| 215 | +fontsize: int, optional (default: None) |
210 | 216 | Fontsize used for ticks, labels and titles. For the latter, use the given
|
211 |
| - fontsize plus 2. Does not affect suptitles. |
| 217 | + fontsize plus 2. Does not affect suptitles. If not given, use default |
| 218 | + matplotlib values. For a more fine-grained definition of fontsizes, use the |
| 219 | + option ``matplotlib_rc_params`` (see above). |
212 | 220 | gridline_kwargs: dict, optional
|
213 | 221 | Optional keyword arguments for grid lines. By default, ``color: lightgrey,
|
214 | 222 | alpha: 0.5`` are used. Use ``gridline_kwargs: false`` to not show grid
|
|
296 | 304 | (top right panel). Thus, the use of the ``plot_kwargs`` ``vmin`` and
|
297 | 305 | ``vmax`` or ``levels`` is highly recommend when using this ``common_cbar:
|
298 | 306 | true``. This option has no effect if no reference dataset is given.
|
299 |
| -fontsize: int, optional (default: 10) |
| 307 | +fontsize: int, optional (default: None) |
300 | 308 | Fontsize used for ticks, labels and titles. For the latter, use the given
|
301 |
| - fontsize plus 2. Does not affect suptitles. |
| 309 | + fontsize plus 2. Does not affect suptitles. If not given, use default |
| 310 | + matplotlib values. For a more fine-grained definition of fontsizes, use the |
| 311 | + option ``matplotlib_rc_params`` (see above). |
302 | 312 | log_y: bool, optional (default: True)
|
303 | 313 | Use logarithmic Y-axis.
|
304 | 314 | plot_func: str, optional (default: 'contourf')
|
|
448 | 458 | (top right panel). Thus, the use of the ``plot_kwargs`` ``vmin`` and
|
449 | 459 | ``vmax`` or ``levels`` is highly recommend when using this ``common_cbar:
|
450 | 460 | true``. This option has no effect if no reference dataset is given.
|
451 |
| -fontsize: int, optional (default: 10) |
| 461 | +fontsize: int, optional (default: None) |
452 | 462 | Fontsize used for ticks, labels and titles. For the latter, use the given
|
453 |
| - fontsize plus 2. Does not affect suptitles. |
| 463 | + fontsize plus 2. Does not affect suptitles. If not given, use default |
| 464 | + matplotlib values. For a more fine-grained definition of fontsizes, use the |
| 465 | + option ``matplotlib_rc_params`` (see above). |
454 | 466 | log_y: bool, optional (default: True)
|
455 | 467 | Use logarithmic Y-axis.
|
456 | 468 | plot_func: str, optional (default: 'contourf')
|
|
535 | 547 | (top right panel). Thus, the use of the ``plot_kwargs`` ``vmin`` and
|
536 | 548 | ``vmax`` or ``levels`` is highly recommend when using this ``common_cbar:
|
537 | 549 | true``. This option has no effect if no reference dataset is given.
|
538 |
| -fontsize: int, optional (default: 10) |
| 550 | +fontsize: int, optional (default: None) |
539 | 551 | Fontsize used for ticks, labels and titles. For the latter, use the given
|
540 |
| - fontsize plus 2. Does not affect suptitles. |
| 552 | + fontsize plus 2. Does not affect suptitles. If not given, use default |
| 553 | + matplotlib values. For a more fine-grained definition of fontsizes, use the |
| 554 | + option ``matplotlib_rc_params`` (see above). |
541 | 555 | plot_func: str, optional (default: 'contourf')
|
542 | 556 | Plot function used to plot the profiles. Must be a function of
|
543 | 557 | :mod:`iris.plot` that supports plotting of 2D cubes with coordinates
|
@@ -654,6 +668,7 @@ def __init__(self, config):
|
654 | 668 | self.cfg.setdefault('facet_used_for_labels', 'dataset')
|
655 | 669 | self.cfg.setdefault('figure_kwargs', {'constrained_layout': True})
|
656 | 670 | self.cfg.setdefault('group_variables_by', 'short_name')
|
| 671 | + self.cfg.setdefault('matplotlib_rc_params', {}) |
657 | 672 | self.cfg.setdefault('savefig_kwargs', {
|
658 | 673 | 'bbox_inches': 'tight',
|
659 | 674 | 'dpi': 300,
|
@@ -729,7 +744,7 @@ def __init__(self, config):
|
729 | 744 | )
|
730 | 745 | self.plots[plot_type].setdefault('cbar_kwargs_bias', {})
|
731 | 746 | self.plots[plot_type].setdefault('common_cbar', False)
|
732 |
| - self.plots[plot_type].setdefault('fontsize', 10) |
| 747 | + self.plots[plot_type].setdefault('fontsize', None) |
733 | 748 | self.plots[plot_type].setdefault('gridline_kwargs', {})
|
734 | 749 | self.plots[plot_type].setdefault('plot_func', 'contourf')
|
735 | 750 | self.plots[plot_type].setdefault('plot_kwargs', {})
|
@@ -763,7 +778,7 @@ def __init__(self, config):
|
763 | 778 | )
|
764 | 779 | self.plots[plot_type].setdefault('cbar_kwargs_bias', {})
|
765 | 780 | self.plots[plot_type].setdefault('common_cbar', False)
|
766 |
| - self.plots[plot_type].setdefault('fontsize', 10) |
| 781 | + self.plots[plot_type].setdefault('fontsize', None) |
767 | 782 | self.plots[plot_type].setdefault('log_y', True)
|
768 | 783 | self.plots[plot_type].setdefault('plot_func', 'contourf')
|
769 | 784 | self.plots[plot_type].setdefault('plot_kwargs', {})
|
@@ -809,7 +824,7 @@ def __init__(self, config):
|
809 | 824 | {'orientation': 'vertical'})
|
810 | 825 | self.plots[plot_type].setdefault('cbar_kwargs_bias', {})
|
811 | 826 | self.plots[plot_type].setdefault('common_cbar', False)
|
812 |
| - self.plots[plot_type].setdefault('fontsize', 10) |
| 827 | + self.plots[plot_type].setdefault('fontsize', None) |
813 | 828 | self.plots[plot_type].setdefault('log_y', True)
|
814 | 829 | self.plots[plot_type].setdefault('plot_func', 'contourf')
|
815 | 830 | self.plots[plot_type].setdefault('plot_kwargs', {})
|
@@ -838,7 +853,7 @@ def __init__(self, config):
|
838 | 853 | )
|
839 | 854 | self.plots[plot_type].setdefault('cbar_kwargs_bias', {})
|
840 | 855 | self.plots[plot_type].setdefault('common_cbar', False)
|
841 |
| - self.plots[plot_type].setdefault('fontsize', 10) |
| 856 | + self.plots[plot_type].setdefault('fontsize', None) |
842 | 857 | self.plots[plot_type].setdefault('plot_func', 'contourf')
|
843 | 858 | self.plots[plot_type].setdefault('plot_kwargs', {})
|
844 | 859 | self.plots[plot_type].setdefault('plot_kwargs_bias', {})
|
@@ -873,7 +888,9 @@ def __init__(self, config):
|
873 | 888 | def _add_colorbar(self, plot_type, plot_left, plot_right, axes_left,
|
874 | 889 | axes_right, dataset_left, dataset_right):
|
875 | 890 | """Add colorbar(s) for plots."""
|
876 |
| - fontsize = self.plots[plot_type]['fontsize'] |
| 891 | + fontsize = ( |
| 892 | + self.plots[plot_type]['fontsize'] or mpl.rcParams['axes.labelsize'] |
| 893 | + ) |
877 | 894 | cbar_kwargs = self._get_cbar_kwargs(plot_type)
|
878 | 895 | cbar_label_left = self._get_cbar_label(plot_type, dataset_left)
|
879 | 896 | cbar_label_right = self._get_cbar_label(plot_type, dataset_right)
|
@@ -1007,13 +1024,15 @@ def _add_stats(self, plot_type, axes, dim_coords, dataset,
|
1007 | 1024 |
|
1008 | 1025 | def _get_custom_mpl_rc_params(self, plot_type):
|
1009 | 1026 | """Get custom matplotlib rcParams."""
|
| 1027 | + custom_rc_params = {} |
1010 | 1028 | fontsize = self.plots[plot_type]['fontsize']
|
1011 |
| - custom_rc_params = { |
1012 |
| - 'axes.titlesize': fontsize + 2.0, |
1013 |
| - 'axes.labelsize': fontsize, |
1014 |
| - 'xtick.labelsize': fontsize, |
1015 |
| - 'ytick.labelsize': fontsize, |
1016 |
| - } |
| 1029 | + if fontsize is not None: |
| 1030 | + custom_rc_params.update({ |
| 1031 | + 'axes.titlesize': fontsize + 2.0, |
| 1032 | + 'axes.labelsize': fontsize, |
| 1033 | + 'xtick.labelsize': fontsize, |
| 1034 | + 'ytick.labelsize': fontsize, |
| 1035 | + }) |
1017 | 1036 | return custom_rc_params
|
1018 | 1037 |
|
1019 | 1038 | def _get_label(self, dataset):
|
@@ -1171,7 +1190,10 @@ def _plot_map_with_ref(self, plot_func, dataset, ref_dataset):
|
1171 | 1190 | projection = self._get_map_projection()
|
1172 | 1191 | plot_kwargs = self._get_plot_kwargs(plot_type, dataset)
|
1173 | 1192 | gridline_kwargs = self._get_gridline_kwargs(plot_type)
|
1174 |
| - fontsize = self.plots[plot_type]['fontsize'] |
| 1193 | + fontsize = ( |
| 1194 | + self.plots[plot_type]['fontsize'] or |
| 1195 | + mpl.rcParams['axes.labelsize'] |
| 1196 | + ) |
1175 | 1197 |
|
1176 | 1198 | # Plot dataset (top left)
|
1177 | 1199 | axes_data = fig.add_subplot(gridspec[0:2, 0:2],
|
@@ -1319,7 +1341,10 @@ def _plot_map_without_ref(self, plot_func, dataset):
|
1319 | 1341 | self._add_stats(plot_type, axes, dim_coords_dat, dataset)
|
1320 | 1342 |
|
1321 | 1343 | # Setup colorbar
|
1322 |
| - fontsize = self.plots[plot_type]['fontsize'] |
| 1344 | + fontsize = ( |
| 1345 | + self.plots[plot_type]['fontsize'] or |
| 1346 | + mpl.rcParams['axes.labelsize'] |
| 1347 | + ) |
1323 | 1348 | colorbar = fig.colorbar(plot_map, ax=axes,
|
1324 | 1349 | **self._get_cbar_kwargs(plot_type))
|
1325 | 1350 | colorbar.set_label(self._get_cbar_label(plot_type, dataset),
|
@@ -1363,7 +1388,10 @@ def _plot_zonal_mean_profile_with_ref(self, plot_func, dataset,
|
1363 | 1388 |
|
1364 | 1389 | # Options used for all subplots
|
1365 | 1390 | plot_kwargs = self._get_plot_kwargs(plot_type, dataset)
|
1366 |
| - fontsize = self.plots[plot_type]['fontsize'] |
| 1391 | + fontsize = ( |
| 1392 | + self.plots[plot_type]['fontsize'] or |
| 1393 | + mpl.rcParams['axes.labelsize'] |
| 1394 | + ) |
1367 | 1395 |
|
1368 | 1396 | # Plot dataset (top left)
|
1369 | 1397 | axes_data = fig.add_subplot(gridspec[0:2, 0:2])
|
@@ -1472,7 +1500,10 @@ def _plot_zonal_mean_profile_without_ref(self, plot_func, dataset):
|
1472 | 1500 | self._add_stats(plot_type, axes, dim_coords_dat, dataset)
|
1473 | 1501 |
|
1474 | 1502 | # Setup colorbar
|
1475 |
| - fontsize = self.plots[plot_type]['fontsize'] |
| 1503 | + fontsize = ( |
| 1504 | + self.plots[plot_type]['fontsize'] or |
| 1505 | + mpl.rcParams['axes.labelsize'] |
| 1506 | + ) |
1476 | 1507 | colorbar = fig.colorbar(plot_zonal_mean_profile, ax=axes,
|
1477 | 1508 | **self._get_cbar_kwargs(plot_type))
|
1478 | 1509 | colorbar.set_label(self._get_cbar_label(plot_type, dataset),
|
@@ -1529,7 +1560,10 @@ def _plot_hovmoeller_z_vs_time_without_ref(self, plot_func, dataset):
|
1529 | 1560 | self._add_stats(plot_type, axes, dim_coords_dat, dataset)
|
1530 | 1561 |
|
1531 | 1562 | # Setup colorbar
|
1532 |
| - fontsize = self.plots[plot_type]['fontsize'] |
| 1563 | + fontsize = ( |
| 1564 | + self.plots[plot_type]['fontsize'] or |
| 1565 | + mpl.rcParams['axes.labelsize'] |
| 1566 | + ) |
1533 | 1567 | colorbar = fig.colorbar(plot_hovmoeller,
|
1534 | 1568 | ax=axes,
|
1535 | 1569 | **self._get_cbar_kwargs(plot_type))
|
@@ -1592,7 +1626,10 @@ def _plot_hovmoeller_z_vs_time_with_ref(self, plot_func, dataset,
|
1592 | 1626 |
|
1593 | 1627 | # Options used for all subplots
|
1594 | 1628 | plot_kwargs = self._get_plot_kwargs(plot_type, dataset)
|
1595 |
| - fontsize = self.plots[plot_type]['fontsize'] |
| 1629 | + fontsize = ( |
| 1630 | + self.plots[plot_type]['fontsize'] or |
| 1631 | + mpl.rcParams['axes.labelsize'] |
| 1632 | + ) |
1596 | 1633 |
|
1597 | 1634 | # Plot dataset (top left)
|
1598 | 1635 | axes_data = fig.add_subplot(gridspec[0:2, 0:2])
|
@@ -1710,7 +1747,10 @@ def _plot_hovmoeller_time_vs_lat_or_lon_with_ref(self, plot_func, dataset,
|
1710 | 1747 |
|
1711 | 1748 | # Options used for all subplots
|
1712 | 1749 | plot_kwargs = self._get_plot_kwargs(plot_type, dataset)
|
1713 |
| - fontsize = self.plots[plot_type]['fontsize'] |
| 1750 | + fontsize = ( |
| 1751 | + self.plots[plot_type]['fontsize'] or |
| 1752 | + mpl.rcParams['axes.labelsize'] |
| 1753 | + ) |
1714 | 1754 |
|
1715 | 1755 | # Plot dataset (top left)
|
1716 | 1756 | axes_data = fig.add_subplot(gridspec[0:2, 0:2])
|
@@ -1837,7 +1877,10 @@ def _plot_hovmoeller_time_vs_lat_or_lon_without_ref(self, plot_func,
|
1837 | 1877 | plot_hovmoeller = plot_func(cube, **plot_kwargs)
|
1838 | 1878 |
|
1839 | 1879 | # Setup colorbar
|
1840 |
| - fontsize = self.plots[plot_type]['fontsize'] |
| 1880 | + fontsize = ( |
| 1881 | + self.plots[plot_type]['fontsize'] or |
| 1882 | + mpl.rcParams['axes.labelsize'] |
| 1883 | + ) |
1841 | 1884 | colorbar = fig.colorbar(plot_hovmoeller, ax=axes,
|
1842 | 1885 | **self._get_cbar_kwargs(plot_type))
|
1843 | 1886 | colorbar.set_label(self._get_cbar_label(plot_type, dataset),
|
@@ -2592,16 +2635,17 @@ def create_hovmoeller_time_vs_lat_or_lon_plot(self, datasets):
|
2592 | 2635 |
|
2593 | 2636 | def compute(self):
|
2594 | 2637 | """Plot preprocessed data."""
|
2595 |
| - for (var_key, datasets) in self.grouped_input_data.items(): |
2596 |
| - logger.info("Processing variable %s", var_key) |
2597 |
| - self.create_timeseries_plot(datasets) |
2598 |
| - self.create_annual_cycle_plot(datasets) |
2599 |
| - self.create_map_plot(datasets) |
2600 |
| - self.create_zonal_mean_profile_plot(datasets) |
2601 |
| - self.create_1d_profile_plot(datasets) |
2602 |
| - self.create_variable_vs_lat_plot(datasets) |
2603 |
| - self.create_hovmoeller_z_vs_time_plot(datasets) |
2604 |
| - self.create_hovmoeller_time_vs_lat_or_lon_plot(datasets) |
| 2638 | + with mpl.rc_context(self.cfg['matplotlib_rc_params']): |
| 2639 | + for (var_key, datasets) in self.grouped_input_data.items(): |
| 2640 | + logger.info("Processing variable %s", var_key) |
| 2641 | + self.create_timeseries_plot(datasets) |
| 2642 | + self.create_annual_cycle_plot(datasets) |
| 2643 | + self.create_map_plot(datasets) |
| 2644 | + self.create_zonal_mean_profile_plot(datasets) |
| 2645 | + self.create_1d_profile_plot(datasets) |
| 2646 | + self.create_variable_vs_lat_plot(datasets) |
| 2647 | + self.create_hovmoeller_z_vs_time_plot(datasets) |
| 2648 | + self.create_hovmoeller_time_vs_lat_or_lon_plot(datasets) |
2605 | 2649 |
|
2606 | 2650 |
|
2607 | 2651 | def main():
|
|
0 commit comments