Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

include-figures.rst 16 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
  1. .. _include-gmt-graphics:
  2. Including GMT Graphics into your Documents
  3. ==========================================
  4. Now that you made some nice graphics with GMT, it is time to add them
  5. to a document, an article, a report, your dissertation, a poster, a web
  6. page, or a presentation. Of course, you could try the old-fashioned
  7. scissors and glue stick. More likely, you want to incorporate your
  8. graphics electronically into the document. Depending on the application,
  9. it is best to set your GMT script to produce the most suitable format,
  10. such as Encapsulated PostScript (EPS), Portable Document Format (PDF), or some raster
  11. format (e.g., JPEG, PNG, or TIFF) in order to incorporate them into the
  12. document.
  13. - When creating a document intended for printing (article,
  14. dissertation, or poster) it is best to preserve the scalable vector
  15. characteristics of the default PDF file. Modern
  16. programs will often allow the inclusion of PDF files. That way, the
  17. sharpness of lines and fonts will be preserved and can be scaled up
  18. or down as required.
  19. - When the aim is to display the graphics on a computer screen or
  20. present it using a projector, it is wise to select
  21. a raster format. Although applications like
  22. PowerPoint can convert PDF to a ratser for you, you can best take the
  23. conversion into your own hands for the best results.
  24. Using GMT modern mode you simply select the format most suitable for your
  25. purpuse when running :doc:`/begin` or :doc:`/figure`.
  26. The remainder of this Chapter will show how to include GMT classicly produced
  27. PostScript graphics into documents and how to achieve the best quality results.
  28. Making GMT Encapsulated PostScript Files
  29. ------------------------------------------
  30. GMT classic mode produces freeform PostScript files. Note that a freeform
  31. PostScript file may contain special operators (such as
  32. ``Setpagedevice``) that is specific to printers (e.g., selection of
  33. paper tray). Some previewers may not
  34. understand these valid instructions and may fail to image the file.
  35. Also, embedding freeform PostScript with such instructions in it into
  36. a larger document can cause printing to fail. While you could choose
  37. another viewer (we recommend **ghostview**) to view single plots
  38. prepared by GMT, it is generally wiser to convert PostScript to EPS
  39. output when you are creating a plot intended for inclusion into a larger
  40. document. Some programs (and some publishers as well) do not allow the
  41. use of instructions like ``Setpagedevice`` as part of embedded graphics.
  42. An EPS file that is to be placed into another document needs to have
  43. correct bounding box parameters. These are found in the
  44. PostScript Document Comment %%BoundingBox. Applications that generate
  45. EPS files should set these parameters correctly. Because GMT\ makes
  46. the PostScript files on the fly, often with several overlays, it is
  47. not possible to do so accurately. Therefore, if you need and EPS version
  48. with a "tight" BoundingBox you need to post-process your
  49. PostScript file. There are several ways in which this can be
  50. accomplished.
  51. - Programs such as Adobe Illustrator, Aldus Freehand, and
  52. Corel Draw will allow you to edit the BoundingBox graphically.
  53. - A command-line alternative is to use freely-available program
  54. **epstool** from the makers of Aladdin ghostscript. Running
  55. ::
  56. epstool -c -b myplot.ps
  57. should give a tight BoundingBox; **epstool** assumes the plot is
  58. page size and not a huge poster.
  59. - Another option is to use **ps2epsi** which also comes with the
  60. ghostscript package. Running
  61. ::
  62. ps2epsi myplot.ps myplot.eps
  63. should also do the trick. The downside is that this program adds an
  64. "image" of the plot in the preamble of the EPS file, thus increasing
  65. the file size significantly. This image is a rough rendering of your
  66. PostScript graphics that some programs will show on screen while
  67. you are editing your document. This image is basically a placeholder
  68. for the PostScript graphics that will actually be printed.
  69. - However, the preferred option is to use the GMT utility
  70. :doc:`/psconvert`. Its **-A** option will
  71. figure out the tightest BoundingBox, again using ghostscript in
  72. the background. For example, running
  73. ::
  74. gmt psconvert -A -Te myplot.ps
  75. will convert the PostScript file ``myplot.ps`` into an encapsulated
  76. PostScript file ``myplot.eps`` which is exactly cropped to the tightest possible
  77. BoundingBox.
  78. If you do not want to modify your illustration but just include it in a
  79. text document: many word processors (such as Microsoft Word or Apple Pages) will let you include a
  80. PostScript file that you may place but not edit. Newer versions of
  81. those programs also allow you to include PDF versions of your graphics.
  82. Except for Pages, you will not be able to view the EPS figure
  83. on-screen, but it will print correctly.
  84. Converting GMT PostScript to PDF or raster images
  85. ---------------------------------------------------
  86. Since Adobe's PDF (Portable Document Format) seems to have become the
  87. *de facto* standard for vector graphics, you are often well off
  88. converting GMT produced PostScript files to PDF. Being both vector
  89. formats (i.e., they basically describe all objects, text and graphics as
  90. lines and curves), such conversion sounds awfully straightforward and
  91. not worth a full section in this document. But experience has shown
  92. differently, since most converters cut corners by using the same tool
  93. (Aladdin's ghostscript) with basic default options that are not
  94. devised to produce the best quality PDF files.
  95. For some applications it is practical or even essential that you convert
  96. your PostScript file into a raster format, such as GIF (Graphics
  97. Interchange Format), TIFF (Tagged Image File Format), PNG (Portable
  98. Network Graphics), or JPEG (Joint Photographic Experts Group). A web
  99. page is better served with a raster image that will immediately show on
  100. a web browser, than with a PostScript file that needs to be downloaded
  101. to view, despite the better printing quality of the PostScript image.
  102. A less obvious reason to convert your image to a raster format is to
  103. by-pass PowerPoint's rendering engine in case you want to embed
  104. the image into a presentation.
  105. The are a number of programs that will convert PostScript files to PDF
  106. or raster formats, like Aladdin's **pstopdf**, pbmplus' **pstoimg**,
  107. or GraphicsMagick's and ImageMagick's **convert**, most of which run ghostscript
  108. behind the scenes. The same is true for viewers like **ghostview** and
  109. Apple's **Preview**. So a lot of the times when people report that
  110. their PostScript plot does not look right but prints fine, it is the
  111. way ghostscript is used with its most basic settings that is to blame.
  112. When converting or viewing PostScript goes awry
  113. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  114. Here are some notorious pitfalls with ghostscript (and other
  115. rendering programs for that matter).
  116. Rendering.
  117. When you are converting to a raster format, make sure you use a high
  118. enough resolution so that the pixels do not show when it is enlarged
  119. onto a screen or using a projector. The right choice of resolution
  120. depends on the application, but do not feel limited to the default
  121. 72 dpi (dots-per-inch) that is offered by most converters.
  122. Image compression.
  123. There are *lossy* and *non-lossy* compressions. A compression
  124. algorithm is called "lossy" when information is lost in the
  125. conversion: there is no way back to get the full original. The
  126. effect can be seen when there are sharp color transitions in your
  127. image: the edges will get blurry in order to allow a more efficient
  128. compression. JPEG uses a lossy compression, PNG is non-lossy, and
  129. TIFF generally does not use compression at all. We therefore
  130. recommend you convert to PNG if you need to rasterize your plot, and
  131. leave JPEG to photographs.
  132. Embedded image compression.
  133. When your GMT plot includes objects produced by
  134. :doc:`/grdimage`, :doc:`/image` or
  135. :doc:`/legend`, they are seen as
  136. "images". The default options of ghostscript will use a
  137. *lossy* compression (similar to JPEG) on those images when
  138. converting them to PDF objects. This can be avoided, however, by
  139. inhibiting the compression altogether, or using the non-lossy
  140. *flate* compression, similar to the one used in the old
  141. **compress** program. This compression is fully reversible, so
  142. that your image does not suffer any loss.
  143. Auto-rotation.
  144. The ghostscript engine has the annoying habit to automatically
  145. rotate an image produced with portrait orientation (using the **-P**
  146. option) so that the height is always larger than the width. So if
  147. you have an image that was printed in portrait mode but happens to
  148. have a width larger than height (for example a global map), it would
  149. suddenly get rotated. Again, this function needs to be switched off.
  150. Apple's Preview uses the ghostscript engine and suffers
  151. from the same annoying habit. Oddly enough, ghostscript does
  152. not force landscape plots to be "horizontal".
  153. Anti-aliasing.
  154. This is not something to worry about when converting to PDF, but
  155. certainly when producing raster images (discussed below).
  156. *Anti-aliasing* in this context means that the rendering tries to
  157. avoid *aliasing*, for example, sampling only the blacks in a
  158. black-and-white hachure. It does so by first oversampling the image
  159. and then using "gray-shades" when a target pixel is only partially
  160. white or black.
  161. Clearly, this can lead to some unwanted results. First, all edges
  162. and lines get blurry and second, the assumption of a white
  163. background causes the gray shades to stand out when transferring the
  164. image to background with a different color (like the popular
  165. sleep-inducing blue in PowerPoint presentations). A more
  166. surprising effect of anti-aliasing is that the seams between tiles
  167. that make up the land mask when using
  168. :doc:`/coast` will become visible. The
  169. anti-aliasing somehow decides to blur the edges of all polygons,
  170. even when they are seamlessly connected to other polygons.
  171. It is therefore wise to overrule the default anti-aliasing option
  172. and over-sample the image yourself by choosing a higher resolution.
  173. Including fonts.
  174. When you are producing print-ready copy to publishers, they will
  175. often (and justifiably) ask that you include all fonts in your PDF
  176. document. Again, ghostscript (and all converters relying on
  177. that engine) will not do so by default.
  178. Using :doc:`/psconvert`
  179. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  180. The remedy to all the problems mentioned in the previous section is
  181. readily available to you in the form of the GMT utility
  182. :doc:`/psconvert`. It is designed to provide
  183. the best quality PDF and raster files using ghostscript as a
  184. rendering engine. The program :doc:`/psconvert` avoids anti-aliasing and
  185. lossy compression techniques that are default to ghostscript and
  186. includes the fonts into the resulting PDF file to ensure portability. By
  187. default the fonts are rendered at 720 dots-per-inch in a PDF file and
  188. images are sampled to 300 dpi, but that can be changed with the **-E**
  189. option. Simply run
  190. ::
  191. gmt psconvert -A -P -Tf *.ps
  192. to convert all PostScript files to PDF while cropping it to the
  193. smallest possible BoundingBox. Or use the **-Tg** option to convert your
  194. files to PNG.
  195. The **-P** option of :doc:`/psconvert` may
  196. also come in handy. When you have *not* supplied the **-P** option in
  197. your first GMT plot command, your plot will be in Landscape mode. That
  198. means that the plot will be rotated 90° (anti-clockwise) to fit
  199. on a Portrait mode page when coming out of the printer. The **-P**
  200. option of :doc:`/psconvert` will undo that
  201. rotation, so that you do not have to do so within your document. This
  202. will only affect Landscape plots; Portrait plots will not be rotated.
  203. We should note that the **-A** option in :doc:`/psconvert` has many modifiers
  204. that can be used to control background color, framing, padding, and overall
  205. scaling of the result.
  206. Examples
  207. --------
  208. GMT graphics in LaTeX
  209. ~~~~~~~~~~~~~~~~~~~~~
  210. To add the graphics into a LaTeX document we use the
  211. ``\includegraphics`` command supplied by the package. In the preamble of
  212. your LaTeX document you will need to include the line
  213. ::
  214. \usepackage{graphicx}
  215. The inclusion of the graphics will probably be inside a floating figure
  216. environment; something like this
  217. ::
  218. \begin{figure}
  219. \includegraphics{myplot}
  220. \caption{This is my first plot in \LaTeX.}
  221. \label{fig:myplot}
  222. \end{figure}
  223. Note that the ``\includegraphics`` command does not require you to add
  224. the suffix ``.pdf`` to the file name. If you run **pdflatex**, it will
  225. look automatically for ``myplot.pdf``. If you run **latex**, it will use ``myplot.eps`` instead.
  226. You can scale your plot using the options ``width=``, ``height=``, or
  227. ``scale=``. In addition, if your original graphics was produced in
  228. Landscape mode (i.e., you did *not* use GMT's **-P** option: not
  229. while plotting, nor in :doc:`/psconvert`),
  230. you will need to rotate the plot as well. For example,
  231. ::
  232. \includegraphics[angle=-90,width=0.8\textwidth]{myplot}
  233. will rotate the image 90° clockwise and scale it such that its width
  234. (after rotation) will be 80% of the width of the text column.
  235. GMT graphics in **PowerPoint**
  236. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  237. .. _Rendering:
  238. .. figure:: /_images/rendering.png
  239. :height: 540 px
  240. :width: 720 px
  241. :align: center
  242. :scale: 50 %
  243. Examples of rendered images in a PowerPoint presentation
  244. .. _PowerPoint_dialogue:
  245. .. figure:: /_images/formatpicture.png
  246. :height: 516 px
  247. :width: 545 px
  248. :align: center
  249. :scale: 50 %
  250. PowerPoint's Format Picture dialogue to set scale and rotation.
  251. In Figure :ref:`Rendered images <Rendering>` we have attempted to include
  252. Example :ref:`example_20` into a PowerPoint presentation.
  253. First the PostScript file was converted to PDF (using
  254. :doc:`/psconvert`), then loaded into
  255. PowerPoint and the white background color was made transparent
  256. using the formatting toolbar (shown on the left side of
  257. Figure :ref:`Rendered images <Rendering>`). Clearly, when we let PowerPoint
  258. do the rendering, we do not get the best result:
  259. * The anti-aliasing causes the tiles that make up the land to stand
  260. out. This is because the anti-aliasing algorithm blurs all edges,
  261. even when the tiles join seamlessly.
  262. * The background color was assumed to be white, hence the text is
  263. "smoothed" using gray shades. Instead, shades of blue which would be
  264. appropriate for the background we are using.
  265. On the central column of Figure :ref:`Rendered images <Rendering>` we have
  266. included PNG
  267. versions of a portion of the same example. This shows the workings of
  268. anti-aliasing and different resolutions. All samples were obtained with
  269. **convert**. The one on the top uses all default settings, resulting
  270. in an anti-aliased image at 72 dpi resolution (very much like the PDF
  271. included directly into PowerPoint).
  272. Just switching anti-aliasing off (middle) is clearly not an option
  273. either. It is true that we got rid of the gray blurring and the seams
  274. between the tiles, but without anti-aliasing the image becomes very
  275. blocky. The solution is to render the image at a higher resolution
  276. (e.g., 300 dpi) without anti-aliasing and then shrink the image to the
  277. appropriate size (bottom of the central column in
  278. Figure :ref:`Rendered images <Rendering>`). The scaling, rotation as well as
  279. the selection
  280. of the transparent color can be accomplished through the "Formatting"
  281. tool bar and the "Format Picture" dialogue box of PowerPoint
  282. (Figure :ref:`PowerPoint dialogue box <PowerPoint_dialogue>`), which can be
  283. found by double clicking the
  284. included image (or selecting and right-clicking or control-clicking on a
  285. one-button mouse).
  286. Concluding remarks
  287. ------------------
  288. These examples do not constitute endorsements of the products mentioned
  289. above; they only represent our limited experience with adding
  290. PostScript to various types of documents. For other solutions and
  291. further help, please post messages to the GMT user forum.
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...