metview-python icon indicating copy to clipboard operation
metview-python copied to clipboard

Importing a matplotlib figure as a subfigure

Open wolke-wanderer opened this issue 5 months ago • 1 comments

Is your feature request related to a problem? Please describe.

I've made a figure in matplotlib of a combination of some timeseries that I would like to plot alongside some maps generated with metview. Is there a way to directly import a matplotlib figure as a subplot in mv.mvl_regular_layout or mv.plot_superpage? (Or alternatively to export objects that matplotlib can natively work with?)

Describe the solution you'd like

A way to export from mv.plot as matplotlib fig, axs objects

Describe alternatives you've considered

Remaking the entire plot within existing metview functions, but this is cumbersome and package lock-in.

Additional context

No response

Organisation

KNMI

wolke-wanderer avatar Aug 17 '25 10:08 wolke-wanderer

Hi @wolke-wanderer, I guess there are two ways that could work, although neither is completely efficient.

  1. if you can export your matplotlib plot to a PNG file, then you should be able to import it into your Metview plot using the mimport() function https://metview.readthedocs.io/en/latest/gen_files/icon_functions/mimport.html. This is something that can be plotted onto a page.
  2. depending on exactly how you have your layout defined, you can export any Metview plot to PNG (or PDF/SVG) and then import this into matplotlib. See https://metview.readthedocs.io/en/latest/gen_files/toc/plot.html#graphical-output along with any Gallery example, e.g. https://metview.readthedocs.io/en/latest/gen_files/gallery/contour9.html

iainrussell avatar Aug 18 '25 18:08 iainrussell