|
1 | 1 | """
|
2 |
| -Images on figures |
| 2 | +Image on a figure |
3 | 3 | =================
|
4 | 4 |
|
5 |
| -The :meth:`pygmt.Figure.image` method can be used to read and place an image |
6 |
| -file in many formats (e.g., png, jpg, eps, pdf) on a figure. We must specify |
7 |
| -the filename via the ``imagefile`` parameter or simply use the filename as |
8 |
| -the first argument. You can also use a full URL pointing to your desired image. |
9 |
| -The ``position`` parameter allows us to set a reference point on the map for |
10 |
| -the image. |
| 5 | +The :meth:`pygmt.Figure.image` method can be used to read and place an image file in |
| 6 | +many formats (e.g., png, jpg, eps, pdf) on a figure. We must specify the filename via |
| 7 | +the ``imagefile`` parameter or simply use the filename as the first argument. You can |
| 8 | +also use a full URL pointing to your desired image. The ``position`` parameter allows |
| 9 | +us to set a reference point on the map for the image. |
11 | 10 | """
|
12 | 11 |
|
13 | 12 | # %%
|
|
18 | 17 | fig = pygmt.Figure()
|
19 | 18 | fig.basemap(region=[0, 2, 0, 2], projection="X10c", frame=True)
|
20 | 19 |
|
21 |
| -# place and center the GMT logo from the GMT website to the position 1/1 |
22 |
| -# on a basemap, scaled up to be 3 cm wide and draw a rectangular border |
23 |
| -# around the image |
| 20 | +# Place and center ("+jCM") the image "needle.jpg" provided by GMT to the position |
| 21 | +# ("+g") 1/1 on the current plot, scale it to a width of 8 centimeters ("+w") and draw |
| 22 | +# a rectangular border around it |
24 | 23 | fig.image(
|
25 |
| - imagefile="https://www.generic-mapping-tools.org/_static/gmt-logo.png", |
26 |
| - position="g1/1+w3c+jCM", |
| 24 | + imagefile="https://oceania.generic-mapping-tools.org/cache/needle.jpg", |
| 25 | + position="g1/1+w8c+jCM", |
27 | 26 | box=True,
|
28 | 27 | )
|
29 | 28 |
|
30 |
| -# clean up the downloaded image in the current directory |
31 |
| -Path("gmt-logo.png").unlink() |
32 |
| - |
33 | 29 | fig.show()
|
| 30 | + |
| 31 | +# Clean up the downloaded image in the current directory |
| 32 | +Path("needle.jpg").unlink() |
0 commit comments