metview-python
metview-python copied to clipboard
Importing a matplotlib figure as a subfigure
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
Hi @wolke-wanderer, I guess there are two ways that could work, although neither is completely efficient.
- 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. - 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