question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pygmt does not display images using show()

See original GitHub issue

gmt 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:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
leouiedacommented, Nov 28, 2019

@MarkWieczorek I started a branch for implementing #269 (PR coming soon) and here is what I have working:

  1. Calling Figure.show() will open an external viewer and return something that Jupyter knows how to embed in the notebook. There is no need for method="enternal".
  2. Calling 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!

0reactions
weiji14commented, Nov 5, 2019

Right, so you want to make a plot_gmt function that has a show 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’s fig.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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found