GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
746 stars 216 forks source link

Figures plotting only half in Jupyter #291

Closed EJFielding closed 5 years ago

EJFielding commented 5 years ago

I managed to buiild GMT from source (kind of like the old days when editing the configuration file and building source was the only way). I installed pygmt and got it to import in my Jupyter notebook. When I try to make a simple plot like the "first-figure" example, it only plots the left half of the figure and chops off the top a little. This is the same for the Jupyter notebook and the saved png file. Here is the example saved: central-america-shorelines

welcome[bot] commented 5 years ago

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.

liamtoney commented 5 years ago

Thanks for posting, @EJFielding. Could you please provide the Python code you used to generate the above plot? I'm wondering if this is a figure width / portrait mode issue.

Edit: Whoops, I see that you mentioned the code that you're using above. Try setting a smaller figure width for the projection flag and see what happens... maybe projection="M4i", for example.

EJFielding commented 5 years ago

Thanks for the quick reply. Yes, if I set the projection="M4i" then I see more of the figure, but not quite all. I am a beginning Jupyter user, so I don't have any idea what controls the width of the figure. For some reason, I can only plot figures that are about 3 inches wide.

It is good that the saved file is the same, so "what you see is what you get".

seisman commented 5 years ago

it only plots the left half of the figure and chops off the top a little. This is the same for the Jupyter notebook and the saved png file.

@EJFielding Could you try following GMT commands in your terminal and check if the generated PNG file is correct?

gmt begin map png
gmt basemap -R-90/-70/0/20 -JM8i -B
gmt coast -W
gmt end

Could you also please provide your GMT version (gmt --version) and gs version (gs --version)?

EJFielding commented 5 years ago

I ran those GMT commands in the shell command line and I get the complete map.

fielding% gmt --version 6.0.0_2f22074_2019.03.09 gs --version 9.26

seisman commented 5 years ago

Could you please paste the output of following Python codes?

import pygmt
pygmt.print_clib_info()
EJFielding commented 5 years ago

From Jupyter notebook, I get this:

Loaded libgmt: binary dir: /opt/local/Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS cores: 8 grid layout: rows library path: /Users/fielding/tools/gmt/lib/libgmt.dylib padding: 2 plugin dir: /Users/fielding/tools/gmt/lib/gmt/plugins share dir: /Users/fielding/tools/gmt/share version: 6.0.0

EJFielding commented 5 years ago

I use MacPorts to install Python 3.6, so I kept my pygmt installation in my home directory tree to avoid messing with the MacPorts files, in case that makes a difference.

seisman commented 5 years ago

It looks OK to me. I have no idea where the problem is. Let's wait for @leouieda.

leouieda commented 5 years ago

@EJFielding this is interesting. From GenericMappingTools/gmt#497 it seems to be a problem with the plot units. Could you share your cmake config for building GMT?

EJFielding commented 5 years ago

Sure, I attach my config file.

ConfigUser.cmake.txt

leouieda commented 5 years ago

:thinking: I don't see anything wrong with the setup. It doesn't seem to be a problem on the Python side. I can't reproduce the effect. Which version of ghostscript do you have?

EJFielding commented 5 years ago

I have gs --version 9.26

joa-quim commented 5 years ago

When you do

gmtdefaults -D | grep PROJ_LENGTH_UNIT
PROJ_LENGTH_UNIT               = cm

it prints cm or inch? (Because the GMT 497 issue seems to be related to the use of inches)

EJFielding commented 5 years ago

I have this default when I do that on the command line:

PROJ_LENGTH_UNIT = cm

I am not sure how to check the defaults within the Jupyter notebook.

leouieda commented 5 years ago

It should be the same since we're using the same GMT library that the command line program uses.

leouieda commented 5 years ago

From the discussion in GenericMappingTools/gmt#497, do you have a gmt.conf file in the current directory? The new GMT modern mode sets the PS_MEDIA to a huge page and then crops the plot down when exporting it afterwards. If you're setting PS_MEDIA and forcing it to be letter or A4, then this would be a problem.

EJFielding commented 5 years ago

Thanks! Yes, I have a gmt.conf in this directory because I was running GMT5. It has PS_MEDIA letter in it.

EJFielding commented 5 years ago

I removed the gmt.conf file and tried the 'first-figure.py plot again and it shows the whole thing. Here is the saved PNG: central-america-shorelines

EJFielding commented 5 years ago

I think you can close this issue. Maybe it would help to put something in the documentation to remove any gmt.conf left over from previous GMT5 runs.

leouieda commented 5 years ago

Thanks, Eric! It's good to know. We're actually discussing a better solution that wouldn't require the user to take action at GenericMappingTools/gmt#497