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

gmt.show() not working in ipython console #28

Closed
seisman opened this issue Jul 26, 2017 · 5 comments
Closed

gmt.show() not working in ipython console #28

seisman opened this issue Jul 26, 2017 · 5 comments

Comments

@seisman
Copy link
Member

seisman commented Jul 26, 2017

gmt.show() can display figure in ipython notebook but not in ipython console.

$ ipython
Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:09:58) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import gmt

In [2]: gmt.figure()

In [3]: gmt.pscoast(R='-90/-70/0/20', J='M6i', G='chocolate',
   ...:             S='skyblue', P=True, B='afg')
   ...:             

In [4]: gmt.show()
<IPython.core.display.Image object>

In [5]: 

It will be better if gmt.show() can open a new figure window just like what matplotlib.pyplot.show does.

@leouieda
Copy link
Member

@seisman currently the show function only generates the image for the notebook. I'll look into making it pop up using matplotlib and imshow. This might help us to get sphinx-gallery working as well. Thanks for the suggestion!

@leouieda
Copy link
Member

leouieda commented Aug 3, 2017

@seisman I tried implementing this using matplotlib imshow but it just looks really bad. It's not a viable solutions.

But since GMT generates PDF output, I'll try to make it open an external application with the PDF preview (possibly the browser).

@shicks-seismo
Copy link

@leouieda, not sure if this is possible, but for quick previewing, is there any way to rasterize the drawing first and then use show?

@leouieda
Copy link
Member

leouieda commented Aug 3, 2017

@shicks-seismo that's pretty much what show does right now: https://github.com/GenericMappingTools/gmt-python/blob/57d3ff7ed4f796c0e953223642387c30472caebb/gmt/figure.py#L219

But it only works for the notebook. Opening the external window would be an added option (external=True) that would open up the preview. It could be a raster but if we're opening a program window anyway we might as well make it PDF.

@leouieda
Copy link
Member

leouieda commented Aug 4, 2017

I implemented this by introducing a new keyword argument:

fig.show(external=True)

Will open a PDF preview of the figure in the default PDF viewer. It still won't work for scripts because the command is non-blocking and so the script continues to run and eventually deletes the preview. I might add an argument to savefig to make it pop up the saved figure (also non-blocking) so that it can be used in scripts.

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

No branches or pull requests

3 participants