Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Ghostscript to Increase Resolution of Graph

    Hello all,

    I am seeking to increase the resolution of a graph to 300 dpi for publication. While I've seen solutions that use a third-party software to do so, I'm more interested in learning how to do it by using code in STATA. I stumbled upon this solution (#5), but am having trouble applying it on my Mac. Here is what I have:

    Code:
    graph set ps pagesize custom
    graph set ps mag 300
    graph set ps pagewidth 15
    graph set ps pageheight 12
    graph set ps tmargin 0
    graph set ps lmargin 0
    graph set ps logo off
    graph set ps fontface Helvetica //
    
    *The graph
    use "/Users/yuna/Downloads/Data_Figure_3.dta"
    graph twoway  (line Coeff SurplusLabor, lcolor(black)) (line CI_low SurplusLabor, lcolor(black) lpattern(dash) ) (line CI_high SurplusLabor, lcolor (black) lpattern(dash)) (line SurplusLaborfrequency SurplusLabor, yaxis(2)) if SurplusLabor>=0&SurplusLabor<=.9, legend(off) ytitle("Effect of Change in China's Export Share") xtitle("Surplus Labor")
    
    *This seems to be where my error is*
    /*#delimit ;
     shell /usr/local/bin/gs
             -dSAFER -dBATCH -dNOPAUSE
             -r100 -g1100x800 -sDEVICE=png16m
             -dGraphicsAlphaBits=4 -dTextAlphaBits=4
             -sOutputFile= "figure3.png" "figure3.ps";
    This is the error message I receive:

    Code:
    . #delimit ;
    delimiter now ;
    .  shell /usr/local/bin/gs
    >          -dSAFER -dBATCH -dNOPAUSE
    >          -r100 -g1100x800 -sDEVICE=png16m
    >          -dGraphicsAlphaBits=4 -dTextAlphaBits=4
    >          -sOutputFile= gs "jsa.png" gs "jsa.ps";
    
    GPL Ghostscript 9.21 (2017-03-16)
    Copyright (C) 2017 Artifex Software, Inc.  All rights reserved.
    This software comes with NO WARRANTY: see the file PUBLIC for details.
    Error: /undefinedfilename in (gs)
    Operand stack:
    
    Execution stack:
       %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2
    >    %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1
    >   %stopped_push
    Dictionary stack:
       --dict:1210/1684(ro)(G)--   --dict:0/20(G)--   --dict:78/200(L)--
    Current allocation mode is local
    Last OS error: No such file or directory
    GPL Ghostscript 9.21: Unrecoverable error, exit code 1
    Any idea as to what might be going wrong? I'm new at using ghostscript, so I don't have a full grasp of any syntax errors I might be experiencing

  • #2
    Dear Yu,

    Although Ghostscript has served me well, it is possible to export png files from Stata directly and control the resolution, i.e. increase the file size. The 'thing' with resolution is that you cannot increase it as such but that you have to increase the size of the image and reduce it's proportions when you 'paste' it in another file. E.g. word or powerpoint and then create a PDF. Then the actual dpi of the image in the PDF will have more dpi's although how you control your printer, when the PDF is printed, again will have an effect. I mean to get 600dpi both the image in the PDF as the printer resolution must be 600dpi.
    The reason why you better use Stata's png export instead of Ghostscript is that with version 15 you can control the opacity of colors (which is great) and Ghostscript does not support that (which is sad).
    To try this, use:
    Code:
    sysuse auto , clear
    twoway scatter price mpg [aweight=displacement], msymbol(o) mfcolor(cyan%20)
    graph export testExport.png , replace
    graph export testExportPPTsize.png , width(1500) height(1100) replace
    for more information about Stata's png export functionality, consult:
    Code:
    h png_options
    Happy graphing!
    http://publicationslist.org/eric.melse

    Comment


    • #3
      Originally posted by ericmelse View Post

      Although Ghostscript has served me well, it is possible to export png files from Stata directly and control the resolution, i.e. increase the file size. The 'thing' with resolution is that you cannot increase it as such but that you have to increase the size of the image and reduce it's proportions when you 'paste' it in another file. E.g. word or powerpoint and then create a PDF. Then the actual dpi of the image in the PDF will have more dpi's although how you control your printer, when the PDF is printed, again will have an effect. I mean to get 600dpi both the image in the PDF as the printer resolution must be 600dpi.
      Great tip, thanks!
      I would add that yu can load the resultig png fie in Irfanview and change the DPIs in the image->information menu from 96 to your desired value, which will adjust it to the desired print size.

      Comment


      • #4
        I have found this solution to work well on the Mac:
        https://www.statalist.org/forums/for...or-publication

        Comment

        Working...
        X