From 66a107784be5c194626d4ee24bc3a7fd2ed41ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 30 Oct 2023 19:51:00 +0100 Subject: [PATCH 01/11] Follow NPY002 in gallery 'histogram.py' --- examples/gallery/histograms/histogram.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gallery/histograms/histogram.py b/examples/gallery/histograms/histogram.py index e31f74f8627..5c144931921 100644 --- a/examples/gallery/histograms/histogram.py +++ b/examples/gallery/histograms/histogram.py @@ -12,12 +12,12 @@ import numpy as np import pygmt -np.random.seed(100) - # Generate random elevation data from a normal distribution +rng = np.random.default_rng(seed=100) mean = 100 # mean of distribution stddev = 25 # standard deviation of distribution -data = mean + stddev * np.random.randn(521) +data = rng.normal(mean, stddev, 521) + fig = pygmt.Figure() From f53643cfd35f155f01876b69ff4a42908360e162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 30 Oct 2023 19:51:47 +0100 Subject: [PATCH 02/11] Follow NPY002 in gallery 'scatter_and_histograms.py' --- examples/gallery/histograms/scatter_and_histograms.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/gallery/histograms/scatter_and_histograms.py b/examples/gallery/histograms/scatter_and_histograms.py index d97f5d8f87c..ed841e22247 100644 --- a/examples/gallery/histograms/scatter_and_histograms.py +++ b/examples/gallery/histograms/scatter_and_histograms.py @@ -13,15 +13,16 @@ import numpy as np import pygmt -np.random.seed(19680801) - # Generate random data from a standard normal distribution centered on 0 -x = np.random.randn(1000) -y = np.random.randn(1000) +# with a standard deviation of 1 +rng = np.random.default_rng(seed=19680801) +x = rng.normal(0, 1, 1000) +y = rng.normal(0, 1, 1000) # Get axis limits xymax = max(np.max(np.abs(x)), np.max(np.abs(y))) + fig = pygmt.Figure() fig.basemap( region=[-xymax - 0.5, xymax + 0.5, -xymax - 0.5, xymax + 0.5], From 057b0e3391e2d7d99363e6b83e0c5cdfb587c9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 30 Oct 2023 19:52:30 +0100 Subject: [PATCH 03/11] Follow NPY002 in gallery 'points.py' --- examples/gallery/symbols/points.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/gallery/symbols/points.py b/examples/gallery/symbols/points.py index 961415ab8da..f1e48712006 100644 --- a/examples/gallery/symbols/points.py +++ b/examples/gallery/symbols/points.py @@ -11,10 +11,11 @@ import pygmt # Generate a random set of points to plot -np.random.seed(42) +rng = np.random.default_rng(seed=42) region = [150, 240, -10, 60] -x = np.random.uniform(region[0], region[1], 100) -y = np.random.uniform(region[2], region[3], 100) +x = rng.uniform(region[0], region[1], 100) +y = rng.uniform(region[2], region[3], 100) + fig = pygmt.Figure() # Create a 15 cm x 15 cm basemap with a Cartesian projection (X) using the From 86571bb19c83429e6ceff7ff6a62bd42768362a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 30 Oct 2023 20:17:53 +0100 Subject: [PATCH 04/11] Follow NPY002 in tutorial 'scatter.py' --- examples/gallery/symbols/scatter.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/gallery/symbols/scatter.py b/examples/gallery/symbols/scatter.py index cfc30afbef9..3d8ba40817c 100644 --- a/examples/gallery/symbols/scatter.py +++ b/examples/gallery/symbols/scatter.py @@ -13,18 +13,20 @@ import numpy as np import pygmt -np.random.seed(19680801) +rng = np.random.default_rng(seed=19680801) n = 200 # number of random data points fig = pygmt.Figure() fig.basemap( - region=[-0.1, 1.1, -0.1, 1.1], + region=[-1, 1, -1, 1], projection="X10c/10c", - frame=["xa0.2fg", "ya0.2fg", "WSrt"], + frame=["xa0.5fg", "ya0.5fg", "WSrt"], ) for fill in ["gray73", "darkorange", "slateblue"]: - x, y = np.random.rand(2, n) # random X and Y data in [0,1] - size = np.random.rand(n) * 0.5 # random size [0,0.5], in cm + x = rng.normal(0, 0.5, n) # random x data + y = rng.normal(0, 0.5, n) # random y data + size = rng.normal(0, 0.5, n) * 0.5 # random size, in cm + # plot data points as circles (style="c"), with different sizes fig.plot( x=x, From 989925a14c73154b721afdc82958c2f743235438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 30 Oct 2023 20:19:07 +0100 Subject: [PATCH 05/11] Follow NPY002 in tutorial 'cartesian_histograms.py' --- examples/tutorials/advanced/cartesian_histograms.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/tutorials/advanced/cartesian_histograms.py b/examples/tutorials/advanced/cartesian_histograms.py index c68b7e7d948..221ae530878 100644 --- a/examples/tutorials/advanced/cartesian_histograms.py +++ b/examples/tutorials/advanced/cartesian_histograms.py @@ -22,7 +22,7 @@ # %% # Generate random data from a normal distribution: -np.random.seed(100) +rng = np.random.default_rng(seed=100) # Mean of distribution mean = 100 @@ -30,8 +30,8 @@ stddev = 20 # Create two data sets -data01 = np.random.normal(mean, stddev, 42) -data02 = np.random.normal(mean, stddev * 2, 42) +data01 = rng.normal(mean, stddev, 42) +data02 = rng.normal(mean, stddev * 2, 42) # %% From a8641cac0cabcc4954e23acd522d928b8df6ffb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:48:11 +0100 Subject: [PATCH 06/11] Use keyword arguments Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/symbols/points.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/symbols/points.py b/examples/gallery/symbols/points.py index f1e48712006..58ab127d003 100644 --- a/examples/gallery/symbols/points.py +++ b/examples/gallery/symbols/points.py @@ -13,8 +13,8 @@ # Generate a random set of points to plot rng = np.random.default_rng(seed=42) region = [150, 240, -10, 60] -x = rng.uniform(region[0], region[1], 100) -y = rng.uniform(region[2], region[3], 100) +x = rng.uniform(low=region[0], high=region[1], size=100) +y = rng.uniform(low=region[2], high=region[3], size=100) fig = pygmt.Figure() From 4c49874cc7c213a13d29b93116ea2d4093a3676d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:49:13 +0100 Subject: [PATCH 07/11] Use keyword arguments Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/symbols/scatter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/symbols/scatter.py b/examples/gallery/symbols/scatter.py index 3d8ba40817c..cf1fef41273 100644 --- a/examples/gallery/symbols/scatter.py +++ b/examples/gallery/symbols/scatter.py @@ -23,8 +23,8 @@ frame=["xa0.5fg", "ya0.5fg", "WSrt"], ) for fill in ["gray73", "darkorange", "slateblue"]: - x = rng.normal(0, 0.5, n) # random x data - y = rng.normal(0, 0.5, n) # random y data + x = rng.normal(loc=0, scale=0.5, size=n) # random x data + y = rng.normal(loc=0, scale=0.5, size=n) # random y data size = rng.normal(0, 0.5, n) * 0.5 # random size, in cm # plot data points as circles (style="c"), with different sizes From 6af2f372a3a42a3fac7d2eb5dbb11456dc54c808 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Tue, 31 Oct 2023 08:52:39 +0100 Subject: [PATCH 08/11] Use keyword arguments and add comment --- examples/gallery/symbols/scatter.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/gallery/symbols/scatter.py b/examples/gallery/symbols/scatter.py index cf1fef41273..ccd88594df2 100644 --- a/examples/gallery/symbols/scatter.py +++ b/examples/gallery/symbols/scatter.py @@ -23,9 +23,11 @@ frame=["xa0.5fg", "ya0.5fg", "WSrt"], ) for fill in ["gray73", "darkorange", "slateblue"]: + # Generate standard normal distributions centered on 0 + # with a standard deviation of 1 x = rng.normal(loc=0, scale=0.5, size=n) # random x data y = rng.normal(loc=0, scale=0.5, size=n) # random y data - size = rng.normal(0, 0.5, n) * 0.5 # random size, in cm + size = rng.normal(loc=0, sclae=0.5, size=n) * 0.5 # random size, in cm # plot data points as circles (style="c"), with different sizes fig.plot( From c36f7fa4e2922ed57911c3d06239a01bb2f69952 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Tue, 31 Oct 2023 08:58:14 +0100 Subject: [PATCH 09/11] Use keyword arguments --- examples/gallery/histograms/histogram.py | 2 +- examples/gallery/histograms/scatter_and_histograms.py | 4 ++-- examples/tutorials/advanced/cartesian_histograms.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/gallery/histograms/histogram.py b/examples/gallery/histograms/histogram.py index 5c144931921..e6f69add4c8 100644 --- a/examples/gallery/histograms/histogram.py +++ b/examples/gallery/histograms/histogram.py @@ -16,7 +16,7 @@ rng = np.random.default_rng(seed=100) mean = 100 # mean of distribution stddev = 25 # standard deviation of distribution -data = rng.normal(mean, stddev, 521) +data = rng.normal(loc=mean, scale=stddev, size=521) fig = pygmt.Figure() diff --git a/examples/gallery/histograms/scatter_and_histograms.py b/examples/gallery/histograms/scatter_and_histograms.py index ed841e22247..b493de63476 100644 --- a/examples/gallery/histograms/scatter_and_histograms.py +++ b/examples/gallery/histograms/scatter_and_histograms.py @@ -16,8 +16,8 @@ # Generate random data from a standard normal distribution centered on 0 # with a standard deviation of 1 rng = np.random.default_rng(seed=19680801) -x = rng.normal(0, 1, 1000) -y = rng.normal(0, 1, 1000) +x = rng.normal(loc=0, scale=1, size=1000) +y = rng.normal(loc=0, scale=1, size=1000) # Get axis limits xymax = max(np.max(np.abs(x)), np.max(np.abs(y))) diff --git a/examples/tutorials/advanced/cartesian_histograms.py b/examples/tutorials/advanced/cartesian_histograms.py index 221ae530878..c90d1876922 100644 --- a/examples/tutorials/advanced/cartesian_histograms.py +++ b/examples/tutorials/advanced/cartesian_histograms.py @@ -30,8 +30,8 @@ stddev = 20 # Create two data sets -data01 = rng.normal(mean, stddev, 42) -data02 = rng.normal(mean, stddev * 2, 42) +data01 = rng.normal(loc=mean, scale=stddev, size=42) +data02 = rng.normal(loc=mean, scale=stddev * 2, size=42) # %% From fae92c558bcc28d137c08805f2d578890e33dcfd Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Tue, 31 Oct 2023 09:00:47 +0100 Subject: [PATCH 10/11] Use plural --- examples/gallery/symbols/scatter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/symbols/scatter.py b/examples/gallery/symbols/scatter.py index ccd88594df2..0c5ac3a940b 100644 --- a/examples/gallery/symbols/scatter.py +++ b/examples/gallery/symbols/scatter.py @@ -24,7 +24,7 @@ ) for fill in ["gray73", "darkorange", "slateblue"]: # Generate standard normal distributions centered on 0 - # with a standard deviation of 1 + # with standard deviations of 1 x = rng.normal(loc=0, scale=0.5, size=n) # random x data y = rng.normal(loc=0, scale=0.5, size=n) # random y data size = rng.normal(loc=0, sclae=0.5, size=n) * 0.5 # random size, in cm From 76ceba7c80b101e2c0b814ea23d94104ee37dfe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:01:10 +0100 Subject: [PATCH 11/11] Fix typo in keyword argument Co-authored-by: Dongdong Tian --- examples/gallery/symbols/scatter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/symbols/scatter.py b/examples/gallery/symbols/scatter.py index 0c5ac3a940b..c62575c4852 100644 --- a/examples/gallery/symbols/scatter.py +++ b/examples/gallery/symbols/scatter.py @@ -27,7 +27,7 @@ # with standard deviations of 1 x = rng.normal(loc=0, scale=0.5, size=n) # random x data y = rng.normal(loc=0, scale=0.5, size=n) # random y data - size = rng.normal(loc=0, sclae=0.5, size=n) * 0.5 # random size, in cm + size = rng.normal(loc=0, scale=0.5, size=n) * 0.5 # random size, in cm # plot data points as circles (style="c"), with different sizes fig.plot(