Skip to content
Merged
29 changes: 14 additions & 15 deletions examples/gallery/images/image.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""
Images on figures
Image on a figure
=================

The :meth:`pygmt.Figure.image` method can be used to read and place an image
file in many formats (e.g., png, jpg, eps, pdf) on a figure. We must specify
the filename via the ``imagefile`` parameter or simply use the filename as
the first argument. You can also use a full URL pointing to your desired image.
The ``position`` parameter allows us to set a reference point on the map for
the image.
The :meth:`pygmt.Figure.image` method can be used to read and place an image file in
many formats (e.g., png, jpg, eps, pdf) on a figure. We must specify the filename via
the ``imagefile`` parameter or simply use the filename as the first argument. You can
also use a full URL pointing to your desired image. The ``position`` parameter allows
us to set a reference point on the map for the image.
"""

# %%
Expand All @@ -18,16 +17,16 @@
fig = pygmt.Figure()
fig.basemap(region=[0, 2, 0, 2], projection="X10c", frame=True)

# place and center the GMT logo from the GMT website to the position 1/1
# on a basemap, scaled up to be 3 cm wide and draw a rectangular border
# around the image
# Place and center ("+jCM") the image "needle.jpg" provided by GMT to the position
# ("+g") 1/1 on the current plot, scale it to a width of 8 centimeters ("+w") and draw
# a rectangular border around it
fig.image(
imagefile="https://www.generic-mapping-tools.org/_static/gmt-logo.png",
position="g1/1+w3c+jCM",
imagefile="https://oceania.generic-mapping-tools.org/cache/needle.jpg",
position="g1/1+w8c+jCM",
box=True,
)

# clean up the downloaded image in the current directory
Path("gmt-logo.png").unlink()

fig.show()

# Clean up the downloaded image in the current directory
Path("needle.jpg").unlink()