From 7181cf14e650dbee48988676c160b70a1cbd946e Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 3 Jan 2021 17:37:30 +0100 Subject: [PATCH 1/4] Add a gallery example for datetime inputs (#779) Co-authored-by: Dongdong Tian --- examples/gallery/plot/datetime-inputs.py | 61 ++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 examples/gallery/plot/datetime-inputs.py diff --git a/examples/gallery/plot/datetime-inputs.py b/examples/gallery/plot/datetime-inputs.py new file mode 100644 index 00000000000..33c88ba7cf5 --- /dev/null +++ b/examples/gallery/plot/datetime-inputs.py @@ -0,0 +1,61 @@ +""" +Datetime inputs +--------------- + +Datetime inputs of the following types are supported in PyGMT: + +- :class:`numpy.datetime64` +- :class:`pandas.DatetimeIndex` +- :class:`xarray.DataArray`: datetimes included in a *xarray.DataArray* +- raw datetime strings in `ISO format `__ (e.g. ``"YYYY-MM-DD"``, ``"YYYY-MM-DDTHH"``, and ``"YYYY-MM-DDTHH:MM:SS"``) +- Python built-in :class:`datetime.datetime` and :class:`datetime.date` + +We can pass datetime inputs based on one of the types listed above directly to the ``x`` and ``y`` arguments +of e.g. the :meth:`pygmt.Figure.plot` method: + +The ``region`` argument has to include the :math:`x` and :math:`y` axis limits as *str* in the form +*date_min/date_max/ymin/ymax*. + +""" + +import datetime + +import numpy as np +import pandas as pd +import pygmt +import xarray as xr + +fig = pygmt.Figure() + +# create a basemap with limits of 2010-01-01 to 2020-06-01 on the x axis and +# 0 to 10 on the y axis +fig.basemap( + projection="X15c/5c", region="2010-01-01/2020-06-01/0/10", frame=["WSen", "af"] +) + +# numpy.datetime64 types +x = np.array(["2010-06-01", "2011-06-01T12", "2012-01-01T12:34:56"], dtype="datetime64") +y = [1, 2, 3] +fig.plot(x, y, style="c0.4c", pen="1p", color="red3") + +# pandas.DatetimeIndex +x = pd.date_range("2013", periods=3, freq="YS") +y = [4, 5, 6] +fig.plot(x, y, style="t0.4c", pen="1p", color="gold") + +# xarray.DataArray +x = xr.DataArray(data=pd.date_range(start="2015-03", periods=3, freq="QS")) +y = [7.5, 6, 4.5] +fig.plot(x, y, style="s0.4c", pen="1p") + +# raw datetime strings +x = ["2016-02-01", "2016-06-04T14", "2016-10-04T00:00:15"] +y = [7, 8, 9] +fig.plot(x, y, style="a0.4c", pen="1p", color="dodgerblue") + +# the Python built-in datetime and date +x = [datetime.date(2018, 1, 1), datetime.datetime(2019, 6, 1, 20, 5, 45)] +y = [6.5, 4.5] +fig.plot(x, y, style="i0.4c", pen="1p", color="seagreen") + +fig.show() From a40a075226b1ffc3a0596d4a525521f23ac38c43 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 5 Jan 2021 07:32:14 +0000 Subject: [PATCH 2/4] Add lakes alias to Figure.coast() (#781) * Add lakes alias to coast in base_plotting.py * Changing color to fill * Update coast docstring to r-string and change line lengths * Add test for lake alias to test_coast.py * Run make format * Update pygmt/base_plotting.py Co-authored-by: Dongdong Tian * Update pygmt/base_plotting.py Co-authored-by: Dongdong Tian * Fixing doc string length Co-authored-by: Dongdong Tian --- pygmt/base_plotting.py | 12 +++++++++--- pygmt/tests/test_coast.py | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pygmt/base_plotting.py b/pygmt/base_plotting.py index fdd63e73c58..1d476650379 100644 --- a/pygmt/base_plotting.py +++ b/pygmt/base_plotting.py @@ -60,6 +60,7 @@ def _preprocess(self, **kwargs): # pylint: disable=no-self-use R="region", J="projection", A="area_thresh", + C="lakes", B="frame", D="resolution", I="rivers", @@ -77,7 +78,7 @@ def _preprocess(self, **kwargs): # pylint: disable=no-self-use ) @kwargs_to_strings(R="sequence", p="sequence") def coast(self, **kwargs): - """ + r""" Plot continents, shorelines, rivers, and borders on maps Plots grayshaded, colored, or textured land-masses [or water-masses] on @@ -110,8 +111,13 @@ def coast(self, **kwargs): hierarchical level that is lower than min_level or higher than max_level will not be plotted. {B} - C : str - Set the shade, color, or pattern for lakes and river-lakes. + lakes : str or list + *fill*\ [**+l**\ |**+r**\ ] + Set the shade, color, or pattern for lakes and river-lakes. The + default is the fill chosen for wet areas set by the ``water`` + argument. Optionally, specify separate fills by appending + **+l** for lakes or **+r** for river-lakes, and passing multiple + strings in a list. resolution : str Selects the resolution of the data set to use ((f)ull, (h)igh, (i)ntermediate, (l)ow, and (c)rude). diff --git a/pygmt/tests/test_coast.py b/pygmt/tests/test_coast.py index 6e93959af4f..db7289c44ea 100644 --- a/pygmt/tests/test_coast.py +++ b/pygmt/tests/test_coast.py @@ -57,6 +57,7 @@ def test_coast_aliases(): Y="a10c", p="135/25", t=13, + C="blue", ) fig_test.coast( region=[-30, 30, -40, 40], # R @@ -74,6 +75,7 @@ def test_coast_aliases(): yshift="a10c", # Y perspective=[135, 25], # p transparency=13, # t + lakes="blue", # C ) return fig_ref, fig_test From ad8a0e00ba5601f182d8c82ca53b4c970c8df7ba Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 6 Jan 2021 22:09:51 +0000 Subject: [PATCH 3/4] Update GMT argument in the cylindric projections gallery to doc standards (#789) * Update doc string for cyl_cassini.py * Updating doc string for cyl_equal_area.py * Updating doc string for cyl_equidistant.py * Updating doc string for cyl_mercator.py * Updating doc string for cyl_miller.py * Update doc string for cyl_stereographic.py * Update doc string for cyl_transverse_mercator.py * Update doc string for cyl_universal_transverse_mercator.py Co-authored-by: Dongdong Tian --- examples/projections/cyl/cyl_cassini.py | 5 ++++- examples/projections/cyl/cyl_equal_area.py | 6 ++++-- examples/projections/cyl/cyl_equidistant.py | 5 ++++- examples/projections/cyl/cyl_mercator.py | 7 +++++-- examples/projections/cyl/cyl_miller.py | 5 ++++- examples/projections/cyl/cyl_stereographic.py | 9 ++++++--- examples/projections/cyl/cyl_transverse_mercator.py | 7 +++++-- .../projections/cyl/cyl_universal_transverse_mercator.py | 5 ++++- 8 files changed, 36 insertions(+), 13 deletions(-) diff --git a/examples/projections/cyl/cyl_cassini.py b/examples/projections/cyl/cyl_cassini.py index 7ac6907e162..efd9318111d 100644 --- a/examples/projections/cyl/cyl_cassini.py +++ b/examples/projections/cyl/cyl_cassini.py @@ -11,7 +11,10 @@ meridian, each meridian 90° away, and equator are straight lines; all other meridians and parallels are complex curves. -``Clon0/lat0/width``: ``lon0`` and ``lat0`` specifies the projection center. +**c**\ *lon0/lat0*\ */scale* or **C**\ *lon0/lat0*\ */width* + +The projection is set with **c** or **C**. The projection center is set by *lon0/lat0*, +and the figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/cyl/cyl_equal_area.py b/examples/projections/cyl/cyl_equal_area.py index 74fc8eb4312..d2e33563756 100644 --- a/examples/projections/cyl/cyl_equal_area.py +++ b/examples/projections/cyl/cyl_equal_area.py @@ -6,8 +6,10 @@ latitude is selected as the standard parallel. However, they are all equal area and hence non-conformal. All meridians and parallels are straight lines. -``Ylon0/lat0/width``: Give central meridian ``lon0``, the standard parallel ``lat0``, -and the figure ``width``. +**y**\ *lon0/lat0*\ */scale* or **Y**\ *lon0/lat0*\ */width* + +The projection is set with **y** or **Y**. The projection center is set by *lon0/lat0*, +and the figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/cyl/cyl_equidistant.py b/examples/projections/cyl/cyl_equidistant.py index 7a236466ad6..e3b0f2e60ae 100644 --- a/examples/projections/cyl/cyl_equidistant.py +++ b/examples/projections/cyl/cyl_equidistant.py @@ -6,7 +6,10 @@ latitudes. The most common form is the Plate Carrée projection, where the scaling of longitudes and latitudes is the same. All meridians and parallels are straight lines. -``Qwidth``: Give the figure ``width``. +**q**\ *scale* or **Q**\ *width* + +The projection is set with **q** or **Q**, and the figure size is set +with *scale* or *width*. """ import pygmt diff --git a/examples/projections/cyl/cyl_mercator.py b/examples/projections/cyl/cyl_mercator.py index 2cfdce4329c..fefdc6c27d9 100644 --- a/examples/projections/cyl/cyl_mercator.py +++ b/examples/projections/cyl/cyl_mercator.py @@ -12,8 +12,11 @@ extensively for world maps in which the distortion towards the polar regions grows rather large. -``M[lon0/][lat0/]width``: Give central meridian ``lon0`` (optional) and -standard parallel ``lat0`` (optional). +**m**\ [*lon0[/lat0]*]\ */scale* or **M**\ [*lon0*][*/lat0*]\ */width* + +The projection is set with **m** or **M**. The central meridian is set with the +option *lon0* and the standard parallel is set with the option *lat0*. +The figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/cyl/cyl_miller.py b/examples/projections/cyl/cyl_miller.py index 4d2503793a2..a5196a8e03b 100644 --- a/examples/projections/cyl/cyl_miller.py +++ b/examples/projections/cyl/cyl_miller.py @@ -9,7 +9,10 @@ by using Mercator’s formula with 0.8 times the actual latitude, thus avoiding the singular poles; the result was then divided by 0.8. -``J[lon0/]width``: Give the optional central meridian ``lon0`` and the figure ``width``. +**j**\ [*lon0/*]\ */scale* or **J**\ [*lon0/*]\ */width* + +The projection is set with **j** or **J**. The central meridian is set by the +optional *lon0*, and the figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/cyl/cyl_stereographic.py b/examples/projections/cyl/cyl_stereographic.py index 7e5c1c13ed4..30fa5be4cfc 100644 --- a/examples/projections/cyl/cyl_stereographic.py +++ b/examples/projections/cyl/cyl_stereographic.py @@ -10,9 +10,12 @@ antipodal point on the equator. The cylinder crosses the sphere at two standard parallels, equidistant from the equator. -``Cyl_stere/[lon0/][lat0/]width``: Give central meridian ``lon0`` (optional) and -standard parallel ``lat0`` (optional). The standard parallel is typically one of these -(but can be any value): +**cyl_stere/**\ [*lon0/*]\ [*lat0/*]\ *scale* +or **Cyl_stere/**\ [*lon0/*]\ [*lat0/*]\ *width* +The projection is set with **cyl_stere** or **Cyl_stere**. The central meridian is set +by the optional *lon0*, and the figure size is set with *scale* or *width*. + +The standard parallel is typically one of these (but can be any value): * 66.159467 - Miller's modified Gall * 55 - Kamenetskiy's First diff --git a/examples/projections/cyl/cyl_transverse_mercator.py b/examples/projections/cyl/cyl_transverse_mercator.py index 854d780b309..50f1648fec2 100644 --- a/examples/projections/cyl/cyl_transverse_mercator.py +++ b/examples/projections/cyl/cyl_transverse_mercator.py @@ -8,8 +8,11 @@ center. The central meridian, each meridian 90° away from the center, and equator are straight lines; other parallels and meridians are complex curves. -``T[lon0/][lat0/]width``: Give central meridian ``lon0``, the latitude of the -origin ``lat0`` (optional), and the figure width. +**t**\ *lon0/*\ [*lat0/*\ ]\ *scale* or **T**\ *lon0/*\ [*lat0/*\ ]\ *width* + +The projection is set with **t** or **T**. The central meridian is set +by *lon0*, the latitude of the origin is set by the optional *lat0*, and the figure +size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/cyl/cyl_universal_transverse_mercator.py b/examples/projections/cyl/cyl_universal_transverse_mercator.py index aaea1844c66..bc8a8d4ef95 100644 --- a/examples/projections/cyl/cyl_universal_transverse_mercator.py +++ b/examples/projections/cyl/cyl_universal_transverse_mercator.py @@ -14,7 +14,10 @@ 1 part in 1,000 from true scale at equator. The ellipsoidal projection expressions are accurate for map areas that extend less than 10 away from the central meridian. -``U[UTM Zone/][lat0/]width``: Give UTM Zone ``UTM Zone``, and the figure width. +**u**\ *zone/scale* or **U**\ *zone/width* + +the projection is set with **u** or **U**. *zone* sets the zone for the figure, and +the figure size is set wtih *scale* or *width*. """ import pygmt From e5e25cf0d85dda9d2b2807258ffef88963a6f9ce Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 8 Jan 2021 02:09:07 +0000 Subject: [PATCH 4/4] Update GMT argument in the miscellaneous projections gallery to doc standards (#790) * Update doc string for misc_eckertIV.py * Update doc string for misc_eckertVI.py * Update doc string for misc_hammer.py * Update doc string for misc_mollweide.py * Update doc string for misc_robinson.py * Update doc string for misc_sinusoidal.py * Update doc string for misc_van_der_grinten.py * Update doc string for misc_winkel_tripel.py --- examples/projections/cyl/cyl_stereographic.py | 1 + examples/projections/misc/misc_eckertIV.py | 6 ++++-- examples/projections/misc/misc_eckertVI.py | 7 +++++-- examples/projections/misc/misc_hammer.py | 6 ++++-- examples/projections/misc/misc_mollweide.py | 6 ++++-- examples/projections/misc/misc_robinson.py | 6 ++++-- examples/projections/misc/misc_sinusoidal.py | 6 ++++-- examples/projections/misc/misc_van_der_grinten.py | 6 ++++-- examples/projections/misc/misc_winkel_tripel.py | 6 ++++-- 9 files changed, 34 insertions(+), 16 deletions(-) diff --git a/examples/projections/cyl/cyl_stereographic.py b/examples/projections/cyl/cyl_stereographic.py index 30fa5be4cfc..5748c5ef43f 100644 --- a/examples/projections/cyl/cyl_stereographic.py +++ b/examples/projections/cyl/cyl_stereographic.py @@ -12,6 +12,7 @@ **cyl_stere/**\ [*lon0/*]\ [*lat0/*]\ *scale* or **Cyl_stere/**\ [*lon0/*]\ [*lat0/*]\ *width* + The projection is set with **cyl_stere** or **Cyl_stere**. The central meridian is set by the optional *lon0*, and the figure size is set with *scale* or *width*. diff --git a/examples/projections/misc/misc_eckertIV.py b/examples/projections/misc/misc_eckertIV.py index 867e12b1620..595fa48a51e 100644 --- a/examples/projections/misc/misc_eckertIV.py +++ b/examples/projections/misc/misc_eckertIV.py @@ -7,8 +7,10 @@ meridian and all parallels are straight lines; other meridians are equally spaced elliptical arcs. The scale is true along latitude 40°30’. -``Kf[central meridian]/width``: Give the optional central meridian (default is the -center of the region) and the map width. +**kf**\ [*lon0/*]\ *scale* or **Kf**\ [*lon0/*]\ *width* + +The projection is set with **kf** or **Kf**. The central meridian is set with the +optional *lon0*, and the figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/misc/misc_eckertVI.py b/examples/projections/misc/misc_eckertVI.py index 6219e2a605f..cb93a153f07 100644 --- a/examples/projections/misc/misc_eckertVI.py +++ b/examples/projections/misc/misc_eckertVI.py @@ -7,8 +7,11 @@ Central meridian and all parallels are straight lines; other meridians are equally spaced sinusoids. The scale is true along latitude 49°16’. -``Ks[central meridian]/width``: Give the optional central meridian (default is the -center of the region) and the map width. + +**ks**\ [*lon0/*]\ *scale* or **Ks**\ [*lon0/*]\ *width* + +The projection is set with **ks** or **Ks**. The central meridian is set with the +optional *lon0*, and the figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/misc/misc_hammer.py b/examples/projections/misc/misc_hammer.py index 613ffa7f2fc..31edadcffda 100644 --- a/examples/projections/misc/misc_hammer.py +++ b/examples/projections/misc/misc_hammer.py @@ -7,8 +7,10 @@ similar, but is not equal-area). The border is an ellipse, equator and central meridian are straight lines, while other parallels and meridians are complex curves. -``H[central meridian]/width``: Give the optional central meridian (default is the center -of the region) and the map width. +**h**\ [*lon0/*]\ *scale* or **H**\ [*lon0/*]\ *width* + +The projection is set with **h** or **H**. The central meridian is set with the +optional *lon0*, and the figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/misc/misc_mollweide.py b/examples/projections/misc/misc_mollweide.py index 4a563e4a0b6..5fe04dcbd7d 100644 --- a/examples/projections/misc/misc_mollweide.py +++ b/examples/projections/misc/misc_mollweide.py @@ -9,8 +9,10 @@ mainly for global maps showing data distributions. It is occasionally referenced under the name homalographic projection. -``W[central meridian]/width``: Give the optional central meridian (default is the center -of the region) and the map width. +**w**\ [*lon0/*]\ *scale* or **W**\ [*lon0/*]\ *width* + +The projection is set with **w** or **W**. The central meridian is set with the +optional *lon0*, and the figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/misc/misc_robinson.py b/examples/projections/misc/misc_robinson.py index f95a5beed22..f2c6b0b0136 100644 --- a/examples/projections/misc/misc_robinson.py +++ b/examples/projections/misc/misc_robinson.py @@ -10,8 +10,10 @@ originally developed for use by Rand McNally and is currently used by the National Geographic Society. -``N[central meridian]/width``: Give the optional central meridian (default is the center -of the region) and the map width. +**n**\ [*lon0/*]\ *scale* or **N**\ [*lon0/*]\ *width* + +The projection is set with **n** or **N**. The central meridian is set with the +optional *lon0*, and the figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/misc/misc_sinusoidal.py b/examples/projections/misc/misc_sinusoidal.py index bb474f9e6f0..93bac1a9938 100644 --- a/examples/projections/misc/misc_sinusoidal.py +++ b/examples/projections/misc/misc_sinusoidal.py @@ -8,8 +8,10 @@ meridians are sinusoidal curves. Parallels are all equally spaced straight lines, with scale being true along all parallels (and central meridian). -``I[central meridian]/width``: Give the optional central meridian (default is the center -of the region) and the map width. +**i**\ [*lon0/*]\ *scale* or **I**\ [*lon0/*]\ *width* + +The projection is set with **i** or **I**. The central meridian is set with the +optional *lon0*, and the figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/misc/misc_van_der_grinten.py b/examples/projections/misc/misc_van_der_grinten.py index 5a1e98004a0..a297b950c39 100644 --- a/examples/projections/misc/misc_van_der_grinten.py +++ b/examples/projections/misc/misc_van_der_grinten.py @@ -7,8 +7,10 @@ other meridians are arcs of circles. The scale is true along the Equator only. Its main use is to show the entire world enclosed in a circle. -``V[central meridian]/width``: Give the optional central meridian (default is the center -of the region) and the map width. +**v**\ [*lon0/*]\ *scale* or **V**\ [*lon0/*]\ *width* + +The projection is set with **v** or **V**. The central meridian is set with the +optional *lon0*, and the figure size is set with *scale* or *width*. """ import pygmt diff --git a/examples/projections/misc/misc_winkel_tripel.py b/examples/projections/misc/misc_winkel_tripel.py index 0b2ea3962f0..adbc238172f 100644 --- a/examples/projections/misc/misc_winkel_tripel.py +++ b/examples/projections/misc/misc_winkel_tripel.py @@ -16,8 +16,10 @@ (not Hammer-Aitoff) projections. The poles map into straight lines 0.4 times the length of equator. -``R[central meridian]/width``: Give the optional central meridian (default is the center -of the region) and the map width. +**r**\ [*lon0/*]\ *scale* or **R**\ [*lon0/*]\ *width* + +The projection is set with **r** or **R**. The central meridian is set with the +optional *lon0*, and the figure size is set with *scale* or *width*. """ import pygmt