Skip to content

Commit f14ea73

Browse files
committed
Add DataArray.gmt.imshow() function to show 2D DataArray easily
1 parent 3022282 commit f14ea73

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pygmt/accessors.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import xarray as xr
55
from pygmt.exceptions import GMTInvalidInput
6+
from pygmt.figure import Figure
67
from pygmt.src.grdinfo import grdinfo
78

89

@@ -72,3 +73,19 @@ def gtype(self, value):
7273
f"Invalid coordinate system type: {value}, should be a boolean of "
7374
"either 0 for Cartesian or 1 for Geographic"
7475
)
76+
77+
def imshow(self):
78+
"""
79+
Image plot of 2D DataArray.
80+
81+
Examples
82+
--------
83+
84+
>>> from pygmt.datasets import load_earth_relief
85+
>>> grid = load_earth_age()
86+
>>> grid.gmt.imshow()
87+
"""
88+
fig = Figure()
89+
fig.grdimage(self._obj, frame=True)
90+
fig.colorbar()
91+
fig.show()

0 commit comments

Comments
 (0)