[ncl-talk] How to reduce the size of PDF outputs

Toni Klemm toni-klemm at tamu.edu
Thu Aug 2 08:12:44 MDT 2018


Hi Sri,

Are you trying to import a PDF file into a Microsoft Word document? Maybe that is the reason why Word crashes when you try that. I usually save charts and maps as png files. If that doesn’t help, maybe it’s because your map size is too large. Below is how you can control the output format (pdf, png, …) and height and width of your plot. Try those things and see if it works. Also, if you want to produce a lot of output files, then “diro” and “filo” allow you set output directory name and output filename (it also allows you to include numbering to change the file name automatically when you repeat a loop etc.), just so you know.

Hope that helps. Let me know if you have any questions.

Greetings to my home country Germany :-)
Toni



  wks_type = "png"						; plot file type
  wks_type at wkWidth = 1500				; width dimension
  wks_type at wkHeight = 1500 				; height dimension

  diro = “~/your/output/directory/"
  filo = “your_output_filename”			; no file extension necessary

  wks = gsn_open_wks(wks_type, diro + filo)

  gsn_define_colormap(wks,"wgne15”)		; define colormap



Toni Klemm, Ph.D.
Postdoctoral Research Associate
Department of Ecosystem Science and Management
College of Agriculture and Life Sciences
Texas A&M University, College Station, TX
Contributor at the Early Career Climate Forum <http://www.eccforum.org/>
www.toni-klemm.de <http://www.toni-klemm.de/> | @toniklemm <http://twitter.com/toniklemm>







> On Aug 2, 2018, at 6:49 AM, Sri Nandini <snandini at marum.de> wrote:
> 
> Hello
> 
> I am plotting  panel figures in NCL which result in a very large pdf output size (2.3 MB).
> Attached below is the script i use , only the plotting resources are shown.
> 
> I would be  grateful if someone could advice on drastically reducing the size of these pdf outputs because, upon importing them into word, they crash the word document.
> 
> 
> ;==================================================================
> ;Here is a section of my code that draws a color fill plot
> ;====================================================================
> 
>    wks = gsn_open_wks("pdf","all_evap")
> 
>    gsn_define_colormap(wks,"wgne15")
> 
>    ;also can use precip4_diff_19lev.rgb , precip_diff_12lev.rgb  precip3_16lev.rgb precip4_11lev.rgb precip2_17lev.rgb wgne15
> 
>   res = True
> 
>   res at cnFillOn                    = True               ; turn on color fill
>   ;res at gsnSpreadColors      = True                ; use full colormap
> 
>   res at cnLinesOn            = False               ; turn off contour lines
>   res at cnLevelSelectionMode = "ManualLevels"  ; set manual contour levels
>   res at cnMinLevelValF       = 0            ; set min contour level
>   res at cnMaxLevelValF       =  4            ; set max contour level
>   res at cnLevelSpacingF      =  0.5            ; set contour spacing
> 
>   res at gsnDraw              = False           ; Do not draw plot
>   res at gsnFrame             = False           ; Do not advance frome
>   res at lbLabelBarOn         = False              ; turn off individual label bars
>   res at tiMainString         = " "
> 
>   res at gsnCenterString      = " "
>   res at gsnLeftString        = " "
>   res at gsnRightString        = " "
>   res at cnRasterModeOn        = True       ; Raster mode shows grid cells
> 
> 
>   minlat = 25.                          ; min lat to mask
>   maxlat = 80.                          ; max lat to mask
>   minlon = -10.                          ; min lon to mask
>   maxlon =  110.                          ; max lon to mask
> 
>   res at mpProjection = "LambertConformal"            ; choose projection
> 
> ;---masked plot
>   res at gsnAddCyclic = True                ; regional plot
> 
>   res at mpMinLatF = minlat              ; min lat to mask
>   res at mpMaxLatF = maxlat              ; max lat to mask
>   res at mpMinLonF = minlon              ; min lon to mask
>   res at mpMaxLonF = maxlon              ; max lon to mask
> 
>   res at gsnMaskLambertConformal = True                ; turn on lc masking
>   
> ;==================================Create arrays to hold series of plots
>     plot = new(9,graphic)   
> 
>     res at gsnCenterString             = "a) PI"
>   res at gsnStringFontHeightF = 0.017
>   plot(0)  = gsn_csm_contour_map(wks,aveX,res)
> 
>   res at gsnCenterString             = "b) 9 kyr"
>   plot(1)  = gsn_csm_contour_map(wks,aveY,res)
> 
>   res at gsnCenterString             = "c) LIG"
>   plot(2)  = gsn_csm_contour_map(wks,aveY8,res)
> 
>   res at gsnCenterString             = "d) 15.2 kyr"
>   plot(3)  = gsn_csm_contour_map(wks,aveY2,res)
> 
>   res at gsnCenterString             = "e) LGM"
>   plot(4)  = gsn_csm_contour_map(wks,aveY4,res)
> 
>   res at gsnCenterString             = "f) 35 kyr"
>   plot(5)  = gsn_csm_contour_map(wks,aveY6,res)
> 
>   res at gsnCenterString             = "g) HE1"
>   plot(6)  = gsn_csm_contour_map(wks,aveY3,res)
> 
>   res at gsnCenterString             = "h) LGM HE"
>   plot(7)  = gsn_csm_contour_map(wks,aveY5,res)
> 
>   res at gsnCenterString             = "i) HE4"
>   plot(8)  = gsn_csm_contour_map(wks,aveY7,res)
> 
>     printVarSummary(plot)
> 
>   ;add_lc_labels(wks,plot,minlat,maxlat,minlon,maxlon) ; attach latitude labels
> 
> ;=====================================Attach the polylines
>    ADD_SHAPEFILE_OUTLINES = True
>    sname = "Caspian_Basin.shp"
> 
>    pres             = True
>    pres at gsLineColor = "black"
>    pres at gsLineThicknessF = 2.0            ; 3x thickness
> 
>     shp1 = gsn_add_shapefile_polylines(wks,plot,sname,pres) 
>     printVarSummary(shp1)
> 
> ;==================================
> ; panel resources for the 4 plots
> ;==================================
>   pres1                     = True             ; modify the panel plot
>   pres1 at gsnPanelLabelBar    = True             ; common label bar
> 
>   pres1 at lbBoxEndCapStyle    = "TriangleBothEnds"; Added in NCL V6.4.0
>   ;pres1 at gsnMaximize        = True             ; large format in landscape
> 
>   pres1 at lbTitleString        = "Evaporation [ mm/day ]"                ; title string
>   pres1 at lbTitlePosition      = "bottom"              ; title position
>   pres1 at lbTitleFontHeightF   = .012                ; make title smaller
>   pres1 at pmLabelBarOrthogonalPosF =-0.01              ;-- move the labelbar upward
>   pres1 at lbTitleDirection     = "Across"             ; title direction
>   pres1 at lbLabelFontHeightF = 0.01
>   ;pres1 at gsnPanelBottom     = 0.01
> 
>    gsn_panel(wks,plot,(/3,3/),pres1)
> 
> 
> end
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180802/18599fe1/attachment.html>


More information about the ncl-talk mailing list