Skip to content

PyGMT figure cutting off colorbar label #2085

Closed

Description

@EJFielding

Description of the problem

I added a colorbar to a plot3d and the default position is good, but when I added an "x" label with the frame parameter, the display image (in a Jupyter notebook) and the saved image has part of the text cut off.

Full code that generated the error

I think this will run without the input files.

import pygmt
fig2 = pygmt.Figure()

xsecProj = "M20c"
xsecProj = "U14/20c"
xsecReg = [-100.5, -99.1, 16.0, 17.5]
xsecReg3D = [-100.5, -99.1, 16.0, 17.5, 5.0,35.0]
xsecRegZ = [5.0,35.0]
xsecProjZ = "-15c"
xsec5View = [-160.,0.04,0.0]

#set Fault = 'Acapulco'
Fault="Acapulco"

slipD=Fault+".slipdir"
fault=Fault+".fault"
ellipses='ellipse_'+slipD

frameType=["WSZ", "zaf+lDepth (km)"]

pygmt.makecpt(cmap="hot", series=(0, 2, 0.1), reverse=True)

fig2.plot3d(
    fault,
    projection=xsecProj,
    region=xsecReg3D,
    zsize=xsecProjZ,
    perspective=xsec5View,
    pen="thin",
    close=True, color="+z", cmap=True,
    frame=frameType
)
fig2.plot3d(slipD, pen="thick,black",
    projection=xsecProj,
    region=xsecReg3D,
    zsize=xsecProjZ,
    perspective=xsec5View
           )
fig2.plot3d(ellipses, pen="thin",
    projection=xsecProj,
    region=xsecReg3D,
    zsize=xsecProjZ,
    perspective=xsec5View
           )
    

fig2.coast(
    region=xsecReg3D,
    perspective=xsec5View,
    shorelines="1p,black",
)
positionCB="JMB+o2c/0c+w7c/0.5c+mc"
positionCB=None
fig2.colorbar(frame=["a0.5", "x+lSlip", "y+lm"], position=positionCB)

fig2.show()
fig2.savefig(Fault+"-slip-plot.png")

Full error message

No error reported

See attached plot output.

System information

Please paste the output of python -c "import pygmt; pygmt.show_versions()":

PyGMT information:
  version: v0.7.0
System information:
  python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:00:52)  [Clang 13.0.1 ]
  executable: /Users/fielding/anaconda3/envs/pygmt/bin/python
  machine: macOS-11.6.8-x86_64-i386-64bit
Dependency information:
  numpy: 1.23.2
  pandas: 1.4.3
  xarray: 2022.6.0
  netCDF4: 1.6.0
  packaging: 21.3
  geopandas: None
  ghostscript: 9.54.0
  gmt: 6.4.0
GMT library information:
  binary dir: /Users/fielding/anaconda3/envs/pygmt/bin
  cores: 16
  grid layout: rows
  library path: /Users/fielding/anaconda3/envs/pygmt/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/fielding/anaconda3/envs/pygmt/lib/gmt/plugins
  share dir: /Users/fielding/anaconda3/envs/pygmt/share/gmt
  version: 6.4.0

Acapulco-slip-plot

Activity

  1. added
    bug
    on Aug 27, 2022
  2. EJFielding commented on Aug 27, 2022

    @EJFielding
    Author

    The code above contains the workaround of specifying the color bar position, which works well. It would be nice if the default plot did not have the text cut off.

  3. EJFielding commented on Aug 27, 2022

    @EJFielding
    Author

    I found that the plot is complete if I change the horizontal width of the projection to 15c instead of 20c. Does PyGMT have a page size that it is working with? Where is that defined? I did not see an explanation in the documentation about the effective page size.

  4. seisman commented on Aug 28, 2022

    @seisman
    Member

    Does PyGMT have a page size that it is working with?

    No, PyGMT's paper size is the same as GMT, which is 11.6 meter by 11.6 meter, but the plotting origin is only 12.7 centimeter (or 2.54 centimeter in old GMT versions) away from the left-bottom corner of the paper. So the image will be cropped if the position of the colorbar is too low.

    However, I can't reproduce your issue locally. Here is the image I have (without your slip data file):
    Acapulco-slip-plot

    Could you please check if you have a gmt.conf file in your current directory or in your home directory?

  5. EJFielding commented on Aug 28, 2022

    @EJFielding
    Author

    Yes, I found that I did have a gmt.conf file in the directory because I was running regular GMT there before. This is what it had:

    #
    # GMT 6.3.0 Defaults file
    #
    # FORMAT Parameters
    #
    FORMAT_GEO_OUT                 = Ddd.x
    #
    # PostScript Parameters
    #
    PS_MEDIA                       = letter
    
  6. seisman commented on Aug 28, 2022

    @seisman
    Member

    PS_MEDIA in your gmt.conf file is likely the cause. What happens if you remove it?

  7. EJFielding commented on Aug 28, 2022

    @EJFielding
    Author

    I removed the gmt.conf completely and I got the same result.

  8. seisman commented on Aug 28, 2022

    @seisman
    Member

    I removed the gmt.conf completely and I got the same result.

    Do you mean you got the correct result or the incorrect result after removing gmt.conf?

  9. EJFielding commented on Aug 28, 2022

    @EJFielding
    Author

    I got the same plot with the label clipped that I got before. When does PyGMT read the gmt.conf file? Maybe it had already read the file before I deleted it. I saw an older discussion on the GMT forum about somebody having similar trouble with regular GMT in modern mode (https://forum.generic-mapping-tools.org/t/cropping-goes-through-titles-axis-labels/2933/8). I have been careless about removing the gmt.* files after running GMT and it seems that causes these problems. I ran my notebook in a new empty directory and it produced the expected results.

  10. EJFielding commented on Aug 28, 2022

    @EJFielding
    Author

    I will close this as not a PyGMT issue. It seems to be in the upstream GMT modern mode interaction with pre-existing gmt.conf files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions