15
15
except ImportError :
16
16
_HAS_IPYTHON = False
17
17
18
-
18
+ import numpy as np
19
19
from pygmt .clib import Session
20
20
from pygmt .exceptions import GMTError , GMTInvalidInput
21
21
from pygmt .helpers import (
@@ -75,12 +75,9 @@ class Figure:
75
75
"""
76
76
A GMT figure to handle all plotting.
77
77
78
- Use the plotting methods of this class to add elements to the figure. You
79
- can preview the figure using :meth:`pygmt.Figure.show` and save the figure
80
- to a file using :meth:`pygmt.Figure.savefig`.
81
-
82
- Unlike traditional GMT figures, no figure file is generated until you call
83
- :meth:`pygmt.Figure.savefig` or :meth:`pygmt.Figure.psconvert`.
78
+ Use the plotting methods of this class to add elements to the figure. You can
79
+ preview the figure using :meth:`pygmt.Figure.show` and save the figure to a file
80
+ using :meth:`pygmt.Figure.savefig`.
84
81
85
82
Examples
86
83
--------
@@ -94,8 +91,8 @@ class Figure:
94
91
>>> assert Path("my-figure.png").exists()
95
92
>>> Path("my-figure.png").unlink()
96
93
97
- The plot region can be specified through ISO country codes (for example,
98
- ``"JP"`` for Japan):
94
+ The plot region can be specified through ISO country codes (for example, ``"JP"``
95
+ for Japan):
99
96
100
97
>>> import pygmt
101
98
>>> fig = pygmt.Figure()
@@ -122,14 +119,8 @@ def _activate_figure(self):
122
119
Start and/or activate the current figure.
123
120
124
121
All plotting commands run afterward will append to this figure.
125
-
126
- Unlike the command-line version (``gmt figure``), this method does not
127
- trigger the generation of a figure file. An explicit call to
128
- :meth:`pygmt.Figure.savefig` or :meth:`pygmt.Figure.psconvert` must be
129
- made in order to get a file.
130
122
"""
131
- # Passing format '-' tells pygmt.end to not produce any files.
132
- fmt = "-"
123
+ fmt = "-" # Passing format "-" tells pygmt.end to not produce any files.
133
124
with Session () as lib :
134
125
lib .call_module (module = "figure" , args = [self ._name , fmt ])
135
126
@@ -142,7 +133,7 @@ def _preprocess(self, **kwargs):
142
133
return kwargs
143
134
144
135
@property
145
- def region (self ):
136
+ def region (self ) -> np . ndarray :
146
137
"""
147
138
The geographic WESN bounding box for the current figure.
148
139
"""
@@ -480,7 +471,7 @@ def show(
480
471
pdf = self ._preview (
481
472
fmt = "pdf" , dpi = dpi , anti_alias = False , as_bytes = False , ** kwargs
482
473
)
483
- launch_external_viewer (pdf , waiting = waiting )
474
+ launch_external_viewer (pdf , waiting = waiting ) # type: ignore[arg-type]
484
475
case "none" :
485
476
pass # Do nothing
486
477
case _:
@@ -489,26 +480,26 @@ def show(
489
480
"'notebook', 'none' or None."
490
481
)
491
482
492
- def _preview (self , fmt , dpi , as_bytes = False , ** kwargs ):
483
+ def _preview (self , fmt : str , dpi : int , as_bytes : bool = False , ** kwargs ):
493
484
"""
494
485
Grab a preview of the figure.
495
486
496
487
Parameters
497
488
----------
498
- fmt : str
499
- The image format. Can be any extension that
500
- :meth:`pygmt.Figure.savefig` recognizes.
501
- dpi : int
489
+ fmt
490
+ The image format. Can be any extension that :meth:`pygmt.Figure.savefig`
491
+ recognizes.
492
+ dpi
502
493
The image resolution (dots per inch).
503
- as_bytes : bool
504
- If ``True``, will load the image as a bytes string and return that
505
- instead of the file name.
494
+ as_bytes
495
+ If ``True``, will load the binary contents of the image as a bytes object,
496
+ and return that instead of the file name.
506
497
507
498
Returns
508
499
-------
509
- preview : str or bytes
510
- If ``as_bytes= False``, this is the file name of the preview image
511
- file. Else , it is the file content loaded as a bytes string .
500
+ preview
501
+ If ``as_bytes = False``, this is the file name of the preview image file.
502
+ Otherwise , it is the file content loaded as a bytes object .
512
503
"""
513
504
fname = Path (self ._preview_dir .name ) / f"{ self ._name } .{ fmt } "
514
505
self .savefig (fname , dpi = dpi , ** kwargs )
0 commit comments