Skip to content

Figure.savefig should support postscript format #300

Closed

Description

@iceseismic

Description of the problem

Screen Errors when I try a fig.savefig when using filenames with a ".ps" extension ; same savefig works fine with 'eps' extension or 'png' extension

Full code that generated the error

#!/usr/bin/python3
import pygmt
fig = pygmt.Figure()
region = [176.5, 178.7, -39.8, -38.05]
print(region)
fig.basemap(region=region, projection="M4i", frame=True)
fig.coast(land="grey", water="azure1",shorelines=True)
fig.savefig("trythis_pygmt_map.ps")

Full error message

(pygmt) [stephen@akatea autogps]$ python example.py
[176.5, 178.7, -39.8, -38.05]
Traceback (most recent call last):
  File "example.py", line 11, in <module>
    fig.savefig("trythis_pygmt_map.ps")
  File "/sp/prj/tvz95/mypython8_pip_python3p6_pygmt/pygmt/figure.py", line 211, in savefig
    raise GMTInvalidInput("Unknown extension '.{}'".format(ext))
pygmt.exceptions.GMTInvalidInput: Unknown extension '.ps'

System information

  • Operating system: Linux
  • Python installation (Anaconda, system, ETS): Anaconda
  • Version of GMT: 6.0
  • Version of Python: 3.6
  • Version of this package:

"date": "2019-03-25T11:59:11-1000",
"full-revisionid": "5b8c6590ea7031c4e2a708d0dd94c1ec363bc198",
"version": "0.0.1a0+25.g5b8c659"

  • If using conda, paste the output of conda list below:
output of conda list
#
# Name                    Version                   Build  Channel
asn1crypto                0.24.0                py36_1003    conda-forge
basemap                   1.2.0            py36h673bf1a_2    conda-forge
ca-certificates           2019.3.9             hecc5488_0    conda-forge
certifi                   2019.3.9                 py36_0    conda-forge
cffi                      1.12.2           py36hf0e25f4_1    conda-forge
chardet                   3.0.4                 py36_1003    conda-forge
cryptography              2.6.1            py36h72c5cf5_0    conda-forge
cycler                    0.10.0                     py_1    conda-forge
dbus                      1.13.2               h714fa37_1  
decorator                 4.4.0                      py_0    conda-forge
expat                     2.2.5             hf484d3e_1002    conda-forge
fontconfig                2.13.1            he4413a7_1000    conda-forge
freetype                  2.10.0               he983fc9_0    conda-forge
future                    0.17.1                py36_1000    conda-forge
geos                      3.7.1             hf484d3e_1000    conda-forge
gettext                   0.19.8.1          hc5be6a0_1002    conda-forge
glib                      2.56.2            had28632_1001    conda-forge
gst-plugins-base          1.14.0               hbbd80ab_1  
gstreamer                 1.14.0               hb453b48_1  
icu                       58.2              hf484d3e_1000    conda-forge
idna                      2.8                   py36_1000    conda-forge
jpeg                      9c                h14c3975_1001    conda-forge
kiwisolver                1.0.1           py36h6bb024c_1002    conda-forge
libblas                   3.8.0                4_openblas    conda-forge
libcblas                  3.8.0                4_openblas    conda-forge
libffi                    3.2.1             he1b5a44_1006    conda-forge
libgcc-ng                 8.2.0                hdf63c60_1  
libgfortran               3.0.0                         1    conda-forge
libgfortran-ng            7.3.0                hdf63c60_0  
libiconv                  1.15              h516909a_1005    conda-forge
liblapack                 3.8.0                4_openblas    conda-forge
libpng                    1.6.36            h84994c4_1000    conda-forge
libstdcxx-ng              8.2.0                hdf63c60_1  
libtiff                   4.0.10            h648cc4a_1001    conda-forge
libuuid                   2.32.1            h14c3975_1000    conda-forge
libxcb                    1.13              h14c3975_1002    conda-forge
libxml2                   2.9.8             h143f9aa_1005    conda-forge
libxslt                   1.1.32            h4785a14_1002    conda-forge
lxml                      4.3.3            py36h7ec2d77_0    conda-forge
matplotlib                3.0.3                    py36_0    conda-forge
matplotlib-base           3.0.3            py36h167e16e_0    conda-forge
ncurses                   6.1               hf484d3e_1002    conda-forge
numpy                     1.16.2           py36h8b7e671_1    conda-forge
obspy                     1.1.1            py36h3010b51_0    conda-forge
olefile                   0.46                       py_0    conda-forge
openblas                  0.3.5                ha44fe06_0    conda-forge
openssl                   1.1.1b               h14c3975_1    conda-forge
packaging                 19.0                       py_0    conda-forge
pandas                    0.24.2           py36hf484d3e_0    conda-forge
pcre                      8.43                 he6710b0_0  
pillow                    6.0.0            py36he7afcd5_0    conda-forge
pip                       19.0.3                   py36_0    conda-forge
proj4                     4.9.3                h470a237_8    conda-forge
pthread-stubs             0.4               h14c3975_1001    conda-forge
pycparser                 2.19                     py36_1    conda-forge
pyopenssl                 19.0.0                   py36_0    conda-forge
pyparsing                 2.3.1                      py_0    conda-forge
pypdf2                    1.26.0                     py_2    conda-forge
pyproj                    1.9.5.1         py36h2944ce7_1006    conda-forge
pyqt                      5.6.0           py36h13b7fb3_1008    conda-forge
pyshp                     2.1.0                      py_0    conda-forge
pysocks                   1.6.8                 py36_1002    conda-forge
python                    3.6.7             h381d211_1004    conda-forge
python-dateutil           2.8.0                      py_0    conda-forge
pytz                      2018.9                     py_0    conda-forge
qt                        5.6.3                h8bf5577_3  
readline                  7.0               hf8c457e_1001    conda-forge
reportlab                 3.5.17           py36h7d98c4e_0    conda-forge
requests                  2.21.0                py36_1000    conda-forge
scipy                     1.2.1            py36h09a28d5_1    conda-forge
setuptools                40.8.0                   py36_0    conda-forge
sip                       4.18.1          py36hf484d3e_1000    conda-forge
six                       1.12.0                py36_1000    conda-forge
sqlalchemy                1.3.2            py36h516909a_0    conda-forge
sqlite                    3.26.0            h67949de_1001    conda-forge
tk                        8.6.9             h84994c4_1001    conda-forge
tornado                   6.0.2            py36h516909a_0    conda-forge
urllib3                   1.24.1                py36_1000    conda-forge
wheel                     0.33.1                   py36_0    conda-forge
xarray                    0.12.0                     py_0    conda-forge
xorg-libxau               1.0.9                h14c3975_0    conda-forge
xorg-libxdmcp             1.1.3                h516909a_0    conda-forge
xz                        5.2.4             h14c3975_1001    conda-forge
zlib                      1.2.11            h14c3975_1004    conda-forge

Activity

  1. welcome commented on Apr 5, 2019

    @welcome

    👋 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.

  2. changed the title [-]savefig failed for .ps extension , ok for other extensions[/-] [+]Figure.savefig should support postscript format[/+] on Apr 24, 2019
  3. added
    feature request
    good first issue
    help wanted
    question
    and removed
    feature request
    good first issue
    help wanted
    question
    on Apr 24, 2019
  4. leouieda commented on Apr 24, 2019

    @leouieda
    Member

    👋 Hi @iceseismic thanks for reporting. This is a limitation on how the new GMT modern mode operates (this is the basis for pygmt). The postscript is built in the background by GMT and only finalized and given to the user when psconvert is called or the session ends. The way we've structured PyGMT makes it impossible to get the underlying ps file (it will be incomplete).

    Is this something you really need? I've converted this into a feature request so we can keep track and maybe try to think of a way to do it.

    PS: Thanks for completely filling out the template 🥇 You'd be surprised how many people completely ignore it.

  5. iceseismic commented on Apr 24, 2019

    @iceseismic
    Author

    No worries - thanks for the explanation ; personally I would only need the postscript available when psconvert is called.

  6. leouieda commented on Apr 24, 2019

    @leouieda
    Member

    OK, good to know @iceseismic. That was our thinking as well in the design of GMT 6. Most people only care about png and pdf and only use the ps as an intermediate state.

  7. 3 remaining items

  8. seisman commented on May 27, 2021

    @seisman
    Member

    Here is a minimal Python script to reproduce the issue:

    import pygmt
    
    fig = pygmt.Figure()
    fig.basemap(region=[0, 10, 0, 10], frame=True)
    fig.savefig("map.ps")

    Currently, PyGMT raises the following error:

    Traceback (most recent call last):
      File "test.py", line 9, in <module>
        fig.savefig("map.ps")
      File "/Users/seisman/Gits/gmt/pygmt/pygmt/figure.py", line 240, in savefig
        raise GMTInvalidInput("Unknown extension '.{}'".format(ext))
    pygmt.exceptions.GMTInvalidInput: Unknown extension '.ps'
    

    If I change "map.ps" to "map.pdf", the equivalent GMT CLI calls are:

    gmt begin pygmt-session
    gmt figure 16c4d60f519f47f8b766c3d9168c6f8b -
    gmt figure 16c4d60f519f47f8b766c3d9168c6f8b -
    gmt basemap -B -R0/10/0/10
    gmt figure 16c4d60f519f47f8b766c3d9168c6f8b -
    gmt psconvert -A -Fmap -Qg2 -Qt2 -Tf
    gmt end
    

    So, is there a possibility to allow "psconvert" to output the PS file? @PaulWessel

  9. PaulWessel commented on May 27, 2021

    @PaulWessel

    Hm, we do this in GMT somehow. Looking at function process_figures in gmt_init.c it looks like you need to avoid passing -A for PostScript output but we do pass -Tp for PostScript.

  10. PaulWessel commented on May 27, 2021

    @PaulWessel

    Also, I do not know where the "Unknown extension" message comes from - I cannot find it in the GMT source code?

  11. seisman commented on May 27, 2021

    @seisman
    Member

    Hm, we do this in GMT somehow. Looking at function process_figures in gmt_init.c it looks like you need to avoid passing -A for PostScript output but we do pass -Tp for PostScript.

    So, -Tp is an undocumented feature in GMT.

    Changing -Tf to -Tp and removing -A, I can get the PS file, but it's incorrectly "cropped" due to the larger origin shifts in modern mode. See the screenshot below:

    image

    Also, I do not know where the "Unknown extension" message comes from - I cannot find it in the GMT source code?

    The "Unknown extension" message is from PyGMT, not GMT.

  12. PaulWessel commented on May 27, 2021

    @PaulWessel

    The 5 inch shift is only imposed for non-PS plots but not sure how that works in Pygmt. If we run something like this:

    gmt basemap -R0/40/0/40 -JM6i -B -ps t -V

    then I get these messages

    basemap [INFORMATION]: You should specify a paper size when requesting a PostScript file.
    basemap [INFORMATION]: Changing paper size to A4, but we cannot know if this is adequate for your plot; better to use PS_MEDIA explicitly.
    

    since I did not specifically ran gmt set or used PS_MEDIA. This also means margin is left at 1 inch and not set to 5. All this happens in gmt_plotinit. Since you pass - instead of ps to gmt figure then I suspect it does not know yet that you are doing PS.

  13. PaulWessel commented on May 27, 2021

    @PaulWessel

    The alternative answer is to convince anyone who wants to get a PS file that they are wrong and should get an EPS or PDF. PS serves no useful purpose as far as I know.

  14. seisman commented on May 27, 2021

    @seisman
    Member

    OK. EPS also works for me.

    I think for PyGMT, we should at least update the warning message to recommend ".eps" or ".pdf" when ".ps" is requested.

  15. added this to the 0.4.0 milestone on May 27, 2021
  16. added
    maintenance
    enhancement
    and removed
    feature request
    maintenance
    on May 27, 2021
  17. EJFielding commented on May 27, 2021

    @EJFielding

    Yes, recommending .eps or .pdf sounds like the best plan to me.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions