Skip to content

Commit 0c19dfb

Browse files
seismanleouieda
authored andcommitted
Wrapper method for image (#241)
Simple wrapper method. Doesn't do any IO (delegates to GMT).
1 parent 4617492 commit 0c19dfb

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

doc/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Plotting data and laying out the map:
2727
Figure.grdcontour
2828
Figure.grdimage
2929
Figure.logo
30+
Figure.image
3031

3132
Saving and displaying the figure:
3233

gmt/base_plotting.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def logo(self, **kwargs):
494494
D : str
495495
``'[g|j|J|n|x]refpoint+wwidth[+jjustify][+odx[/dy]]'``.
496496
Sets reference point on the map for the image.
497-
F: bool or str
497+
F : bool or str
498498
Without further options, draws a rectangular border around the
499499
GMT logo.
500500
{U}
@@ -505,3 +505,36 @@ def logo(self, **kwargs):
505505
raise GMTInvalidInput("Option D must be specified.")
506506
with Session() as lib:
507507
lib.call_module("logo", build_arg_string(kwargs))
508+
509+
@fmt_docstring
510+
@use_alias(R="region", J="projection")
511+
@kwargs_to_strings(R="sequence")
512+
def image(self, imagefile, **kwargs):
513+
"""
514+
Place images or EPS files on maps.
515+
516+
Reads an Encapsulated PostScript file or a raster image file and plots it on a map.
517+
518+
{gmt_module_docs}
519+
520+
{aliases}
521+
522+
Parameters
523+
----------
524+
{J}
525+
{R}
526+
D: str
527+
``'[g|j|J|n|x]refpoint+rdpi+w[-]width[/height][+jjustify][+nnx[/ny]][+odx[/dy]]'``
528+
Sets reference point on the map for the image.
529+
F : bool or str
530+
``'[+cclearances][+gfill][+i[[gap/]pen]][+p[pen]][+r[radius]][+s[[dx/dy/][shade]]]'``
531+
Without further options, draws a rectangular border around the
532+
image using **MAP_FRAME_PEN**.
533+
M : bool
534+
Convert color image to monochrome grayshades using the (television)
535+
YIQ-transformation.
536+
"""
537+
kwargs = self._preprocess(**kwargs)
538+
with Session() as lib:
539+
arg_str = " ".join([imagefile, build_arg_string(kwargs)])
540+
lib.call_module("image", arg_str)

gmt/tests/baseline/test_image.png

13.8 KB
Loading

gmt/tests/test_image.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Tests image.
3+
"""
4+
import os
5+
6+
import pytest
7+
8+
from .. import Figure
9+
10+
11+
TEST_IMG = os.path.join(os.path.dirname(__file__), "baseline", "test_logo.png")
12+
13+
14+
@pytest.mark.mpl_image_compare
15+
def test_image():
16+
"Place images on map"
17+
fig = Figure()
18+
fig.image(TEST_IMG, D="x0/0+w1i", F="+pthin,blue")
19+
return fig

0 commit comments

Comments
 (0)