pygmt does not display images using show()
See original GitHub issuegmt version = 6.0.0 (macOS, installed via brew)
pygmt does not display newly created figures using show()
.
In [4]: fig = pygmt.Figure()
...: fig.coast(shorelines=True, region=[-90, -70, 0, 20], projection="M8i", frame=True)
...: fig.show()
pygmt-session [ERROR]: GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6.
pygmt-session [ERROR]: GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6.
pygmt-session [ERROR]: GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6.
pygmt-session [ERROR]: GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6.
pygmt-session [ERROR]: GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6.
Out[4]: <IPython.core.display.Image object>
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
pygmt.Figure.show
pygmt.Figure.show¶ ... Display a preview of the figure. Inserts the preview in the Jupyter notebook output. You will need to have IPython installed...
Read more >pygmt.Figure.show
Parameters dpi and width can be used to control the resolution and dimension of the figure in the notebook. Note: The external viewer...
Read more >Images on figures - PyGMT
Images on figures . The pygmt.Figure.image method can be used to read and place an image file in many formats (e.g., png,...
Read more >Configuring PyGMT defaults
To see the figures while using a Python script instead, use fig.show(method="external") to display the figure in the default PDF viewer.
Read more >Images on figures - PyGMT
You can also use a full URL pointing to your desired image. ... clean up the downloaded image in the current directory os.remove("gmt-logo.png")...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@MarkWieczorek I started a branch for implementing #269 (PR coming soon) and here is what I have working:
Figure.show()
will open an external viewer and return something that Jupyter knows how to embed in the notebook. There is no need formethod="enternal"
.pygmt.enable_notebook()
will disable the external viewer. This can also be set with an environment variable. I don’t really like this but I don’t think there is another way that is always reliable. matplotlib does this by deep integration with Jupyter (i.e., jupyter has code to handle matplotlib figures) which I don’t think we can mirror yet.So you could have
fig = grid.plot_gmt(projection='...', ..., show=True)
and things should work the way you expect.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!
Right, so you want to make a
plot_gmt
function that has ashow
flag which will automatically display the figure when called! I can see where you’re going here (I’ve written a similar thing before with matplotlib). So yes, the problem is that PyGMT’sfig.show()
doesn’t quite work that way (yet?)…Could you point me to some sample code on what that
plot_
function looks like (a non-gmt one will suffice). I can see you’ve opened a GMT milestone at https://github.com/SHTOOLS/SHTOOLS/milestone/1