diff --git a/examples/gallery/histograms/histogram.py b/examples/gallery/histograms/histogram.py index e31f74f8627..e6f69add4c8 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(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 d97f5d8f87c..b493de63476 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(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))) + fig = pygmt.Figure() fig.basemap( region=[-xymax - 0.5, xymax + 0.5, -xymax - 0.5, xymax + 0.5], diff --git a/examples/gallery/symbols/points.py b/examples/gallery/symbols/points.py index 961415ab8da..58ab127d003 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(low=region[0], high=region[1], size=100) +y = rng.uniform(low=region[2], high=region[3], size=100) + fig = pygmt.Figure() # Create a 15 cm x 15 cm basemap with a Cartesian projection (X) using the diff --git a/examples/gallery/symbols/scatter.py b/examples/gallery/symbols/scatter.py index cfc30afbef9..c62575c4852 100644 --- a/examples/gallery/symbols/scatter.py +++ b/examples/gallery/symbols/scatter.py @@ -13,18 +13,22 @@ 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 + # Generate standard normal distributions centered on 0 + # 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, scale=0.5, size=n) * 0.5 # random size, in cm + # plot data points as circles (style="c"), with different sizes fig.plot( x=x, diff --git a/examples/tutorials/advanced/cartesian_histograms.py b/examples/tutorials/advanced/cartesian_histograms.py index c68b7e7d948..c90d1876922 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(loc=mean, scale=stddev, size=42) +data02 = rng.normal(loc=mean, scale=stddev * 2, size=42) # %%