Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mix PyGMT and matplotlib #2377

Open
seisman opened this issue Feb 20, 2023 · 1 comment
Open

Mix PyGMT and matplotlib #2377

seisman opened this issue Feb 20, 2023 · 1 comment
Labels
question Further information is requested

Comments

@seisman
Copy link
Member

seisman commented Feb 20, 2023

Originally posted in https://forum.generic-mapping-tools.org/t/mixing-pygmt-and-matplotlib/3648

Is there a way to put a matplotlib axis next to a pyGMT map? For example in a 2-column setup with the matplotlib plot on the left and pyGMT map on the right. I can imagine that I could generate the matplotlib figure, export it as an eps and then dump it into a pyGMT subplot (or shift x and y) with the “image” command, but that seems a little kludgy. Yes, I could also re-write the matplotlib function using pyGMT commands, but I’d rather not. I’ve also looked at putting a pyGMT figure into a matplotlib subfigure but that doesn’t seem to work either.

I don't have an answer yet, but the idea is interesting.

@seisman seisman added the question Further information is requested label Feb 20, 2023
@weiji14
Copy link
Member

weiji14 commented Mar 2, 2023

Copying from an old thread:

Regarding inserting plots in matplotlib, the problem is that the figure would be a raster. We could get a PNG returned by PyGMT and insert that as matplotlib axis. The problem is that it looks bad when exporting the figure later on. This was my original idea for the display mechanism but I gave up on it at the time. The "best" way to do this would be to translate postscript to matplotlib's vector format but I doubt anyone would be willing to do it. I'm not even sure it's possible since GMT does a lot of coding in the postscript itself.

If anyone is can find a way of inserting raster into matplotlib in a way that it looks good, I'd be happy to implement this in PyGMT. Mixing GMT and matplotlib in the same figure would be a dream!

Originally posted by @leouieda in #366 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants