From 7ad7f00dd0a4aeb82c254cae90a6a3327cb87e01 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 4 Mar 2021 18:19:11 +0100 Subject: [PATCH 01/33] Provide gallery example to show coloring of points by categories To close the >2 year old issue #244 here's a gallery example highlighting the coloring of points by categories. --- examples/gallery/plot/points-categorial.py | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 examples/gallery/plot/points-categorial.py diff --git a/examples/gallery/plot/points-categorial.py b/examples/gallery/plot/points-categorial.py new file mode 100644 index 00000000000..93b757c7191 --- /dev/null +++ b/examples/gallery/plot/points-categorial.py @@ -0,0 +1,48 @@ +""" +Color points by categories +--------------------------- +The :meth:`pygmt.Figure.plot` method can be used to plot symbols which are +color-coded by categories. +""" + +import numpy as np +import pandas as pd +import pygmt + +# Load sample iris data, and convert 'species' column to categorical dtype +df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/iris.csv") +df["species"] = df.species.astype(dtype="category") + +# Use pygmt.info to get region bounds (xmin, xmax, ymin, ymax) +# The below example will return a numpy array like [2. 4.4 4.3 7.9] +region = pygmt.info( + table=df[["sepal_width", "sepal_length"]], # x and y columns + per_column=True, # report output as a numpy array +) + +# Make our 2D categorial scatter plot, coloring each of the 3 species differently +fig = pygmt.Figure() + +# Generate basemap of 10cm x 10cm size +fig.basemap( + region=region, + projection="X10c/10c", + frame=['xafg+l"Sepal Width"', 'yafg+l"Sepal Length"', "WSen"], +) + +# Define colormap to use for three categories +pygmt.makecpt(cmap="inferno", color_model="+c", series=(0, 3, 1)) + +fig.plot( + x=df.sepal_width, # Use one feature as x data input + y=df.sepal_length, # Use another feature as y data input + sizes=df.petal_width + / df.petal_length, # Vary each symbol size according to the ratio of the two remaining features + color=df.species.cat.codes.astype(int), # Points colored by categorical number code + cmap=True, # Use colormap created by makecpt + no_clip=True, # Do not clip symbols that fall exactly on the map bounds + style="cc", # Use circles as symbols with size in centimeter units + transparency=40, # Set transparency level for all symbols to deal with overplotting +) + +fig.show() From 57b9a383f3e6a4b96f6aa379811313d67720a80e Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Fri, 5 Mar 2021 17:26:23 +0100 Subject: [PATCH 02/33] updated content based on reviews --- examples/gallery/plot/points-categorial.py | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/examples/gallery/plot/points-categorial.py b/examples/gallery/plot/points-categorial.py index 93b757c7191..593907cfc65 100644 --- a/examples/gallery/plot/points-categorial.py +++ b/examples/gallery/plot/points-categorial.py @@ -5,19 +5,20 @@ color-coded by categories. """ -import numpy as np import pandas as pd +import numpy as np import pygmt -# Load sample iris data, and convert 'species' column to categorical dtype -df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/iris.csv") +# Load sample penguins data and convert 'species' column to categorical dtype +df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/penguins.csv") df["species"] = df.species.astype(dtype="category") # Use pygmt.info to get region bounds (xmin, xmax, ymin, ymax) # The below example will return a numpy array like [2. 4.4 4.3 7.9] region = pygmt.info( - table=df[["sepal_width", "sepal_length"]], # x and y columns + table=df[["bill_length_mm", "bill_depth_mm"]], # x and y columns per_column=True, # report output as a numpy array + spacing="3/2" # rounds x and y intervals by 3 and 2 respectively ) # Make our 2D categorial scatter plot, coloring each of the 3 species differently @@ -27,22 +28,28 @@ fig.basemap( region=region, projection="X10c/10c", - frame=['xafg+l"Sepal Width"', 'yafg+l"Sepal Length"', "WSen"], -) + frame=['xafg+l"Snoot length in mm"', 'yafg+l"Snoot depth in mm"', "WSen"]) # Define colormap to use for three categories pygmt.makecpt(cmap="inferno", color_model="+c", series=(0, 3, 1)) fig.plot( - x=df.sepal_width, # Use one feature as x data input - y=df.sepal_length, # Use another feature as y data input - sizes=df.petal_width - / df.petal_length, # Vary each symbol size according to the ratio of the two remaining features - color=df.species.cat.codes.astype(int), # Points colored by categorical number code - cmap=True, # Use colormap created by makecpt - no_clip=True, # Do not clip symbols that fall exactly on the map bounds - style="cc", # Use circles as symbols with size in centimeter units - transparency=40, # Set transparency level for all symbols to deal with overplotting + # Use one feature as x data input (snoot length) + x=df.bill_length_mm, + # Use another feature as y data input (snoot depth) + y=df.bill_depth_mm, + # Vary each symbol size according to another feature (body mass) + sizes=7.5 * 10 ** -5 * df.body_mass_g, + # Points colored by categorical number code + color=df.species.cat.codes.astype(int), + # Use colormap created by makecpt + cmap=True, + # Do not clip symbols that fall close to the map bounds + no_clip=True, + # Use circles as symbols with size in centimeter units + style="cc", + # Set transparency level for all symbols to deal with overplotting + transparency=40 ) -fig.show() +fig.show() \ No newline at end of file From 87dce833a2c03ca27e40997c032bbc7a650786b4 Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Fri, 5 Mar 2021 16:31:10 +0000 Subject: [PATCH 03/33] [format-command] fixes --- examples/gallery/plot/points-categorial.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/gallery/plot/points-categorial.py b/examples/gallery/plot/points-categorial.py index 593907cfc65..30701e79687 100644 --- a/examples/gallery/plot/points-categorial.py +++ b/examples/gallery/plot/points-categorial.py @@ -5,8 +5,8 @@ color-coded by categories. """ -import pandas as pd import numpy as np +import pandas as pd import pygmt # Load sample penguins data and convert 'species' column to categorical dtype @@ -18,7 +18,7 @@ region = pygmt.info( table=df[["bill_length_mm", "bill_depth_mm"]], # x and y columns per_column=True, # report output as a numpy array - spacing="3/2" # rounds x and y intervals by 3 and 2 respectively + spacing="3/2", # rounds x and y intervals by 3 and 2 respectively ) # Make our 2D categorial scatter plot, coloring each of the 3 species differently @@ -28,7 +28,8 @@ fig.basemap( region=region, projection="X10c/10c", - frame=['xafg+l"Snoot length in mm"', 'yafg+l"Snoot depth in mm"', "WSen"]) + frame=['xafg+l"Snoot length in mm"', 'yafg+l"Snoot depth in mm"', "WSen"], +) # Define colormap to use for three categories pygmt.makecpt(cmap="inferno", color_model="+c", series=(0, 3, 1)) @@ -49,7 +50,7 @@ # Use circles as symbols with size in centimeter units style="cc", # Set transparency level for all symbols to deal with overplotting - transparency=40 + transparency=40, ) -fig.show() \ No newline at end of file +fig.show() From 34bd57bff7d62d481638175e9f8091253ddc165a Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 6 Mar 2021 10:09:09 +0100 Subject: [PATCH 04/33] Update examples/gallery/plot/points-categorial.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/plot/points-categorial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorial.py b/examples/gallery/plot/points-categorial.py index 30701e79687..f0cd98e5d49 100644 --- a/examples/gallery/plot/points-categorial.py +++ b/examples/gallery/plot/points-categorial.py @@ -21,7 +21,7 @@ spacing="3/2", # rounds x and y intervals by 3 and 2 respectively ) -# Make our 2D categorial scatter plot, coloring each of the 3 species differently +# Make our 2D categorical scatter plot, coloring each of the 3 species differently fig = pygmt.Figure() # Generate basemap of 10cm x 10cm size From 65966e1c9a8a7b6b4b9751724d3a5c545eb710ba Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 6 Mar 2021 10:09:20 +0100 Subject: [PATCH 05/33] Update examples/gallery/plot/points-categorial.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/plot/points-categorial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorial.py b/examples/gallery/plot/points-categorial.py index f0cd98e5d49..39feec3e62b 100644 --- a/examples/gallery/plot/points-categorial.py +++ b/examples/gallery/plot/points-categorial.py @@ -28,7 +28,7 @@ fig.basemap( region=region, projection="X10c/10c", - frame=['xafg+l"Snoot length in mm"', 'yafg+l"Snoot depth in mm"', "WSen"], + frame=['xafg+l"Bill length in mm"', 'yafg+l"Bill depth in mm"', "WSen"], ) # Define colormap to use for three categories From 68616b5298f2e7d5445085a75dc6e2b912b3f864 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 6 Mar 2021 10:09:35 +0100 Subject: [PATCH 06/33] Update examples/gallery/plot/points-categorial.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/plot/points-categorial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorial.py b/examples/gallery/plot/points-categorial.py index 39feec3e62b..6aed9ff9b6e 100644 --- a/examples/gallery/plot/points-categorial.py +++ b/examples/gallery/plot/points-categorial.py @@ -35,7 +35,7 @@ pygmt.makecpt(cmap="inferno", color_model="+c", series=(0, 3, 1)) fig.plot( - # Use one feature as x data input (snoot length) + # Use one feature as x data input (bill length) x=df.bill_length_mm, # Use another feature as y data input (snoot depth) y=df.bill_depth_mm, From 96c82f8b101b64afb1af06d279d2243e8e4c65f4 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 6 Mar 2021 10:09:45 +0100 Subject: [PATCH 07/33] Update examples/gallery/plot/points-categorial.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/plot/points-categorial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorial.py b/examples/gallery/plot/points-categorial.py index 6aed9ff9b6e..89f5214beb7 100644 --- a/examples/gallery/plot/points-categorial.py +++ b/examples/gallery/plot/points-categorial.py @@ -37,7 +37,7 @@ fig.plot( # Use one feature as x data input (bill length) x=df.bill_length_mm, - # Use another feature as y data input (snoot depth) + # Use another feature as y data input (bill depth) y=df.bill_depth_mm, # Vary each symbol size according to another feature (body mass) sizes=7.5 * 10 ** -5 * df.body_mass_g, From bc7dc1b972e468c6041ece7f24ac56d21d833fea Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sat, 6 Mar 2021 10:13:30 +0100 Subject: [PATCH 08/33] updated content based on reviews --- .../plot/{points-categorial.py => points-categorical.py} | 3 +++ 1 file changed, 3 insertions(+) rename examples/gallery/plot/{points-categorial.py => points-categorical.py} (93%) diff --git a/examples/gallery/plot/points-categorial.py b/examples/gallery/plot/points-categorical.py similarity index 93% rename from examples/gallery/plot/points-categorial.py rename to examples/gallery/plot/points-categorical.py index 89f5214beb7..38eca132767 100644 --- a/examples/gallery/plot/points-categorial.py +++ b/examples/gallery/plot/points-categorical.py @@ -53,4 +53,7 @@ transparency=40, ) +# A colorbar displaying the individual categories will be added after the +# upcoming GMT 6.2.0. version was released. + fig.show() From 8c3c4f9fb5384b150c058a86ad9e41de792358f4 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 7 Mar 2021 11:44:04 +0100 Subject: [PATCH 09/33] updated content based on reviews --- examples/gallery/plot/points-categorical.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index 38eca132767..ec31448482d 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -14,7 +14,7 @@ df["species"] = df.species.astype(dtype="category") # Use pygmt.info to get region bounds (xmin, xmax, ymin, ymax) -# The below example will return a numpy array like [2. 4.4 4.3 7.9] +# The below example will return a numpy array like [30.0, 60.0, 12.0, 22.0] region = pygmt.info( table=df[["bill_length_mm", "bill_depth_mm"]], # x and y columns per_column=True, # report output as a numpy array @@ -28,7 +28,9 @@ fig.basemap( region=region, projection="X10c/10c", - frame=['xafg+l"Bill length in mm"', 'yafg+l"Bill depth in mm"', "WSen"], + frame=['xafg+l"Bill length in mm"', + 'yafg+l"Bill depth in mm"', + 'WSen+t"Penguin size at Palmer Station"], ) # Define colormap to use for three categories From 52b23c0e024364a9d943ca21288310c21c6bc222 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 7 Mar 2021 11:45:07 +0100 Subject: [PATCH 10/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/plot/points-categorical.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index ec31448482d..f7947c329a3 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -55,7 +55,7 @@ transparency=40, ) -# A colorbar displaying the individual categories will be added after the -# upcoming GMT 6.2.0. version was released. +# A colorbar displaying the different penguin species types will be added +# once GMT 6.2.0 is released. fig.show() From e5c71ebec69364fce2a6d2e36c1fbb042e00e0f7 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 7 Mar 2021 12:32:29 +0100 Subject: [PATCH 11/33] corrected typo --- examples/gallery/plot/points-categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index f7947c329a3..99fdde1af98 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -30,7 +30,7 @@ projection="X10c/10c", frame=['xafg+l"Bill length in mm"', 'yafg+l"Bill depth in mm"', - 'WSen+t"Penguin size at Palmer Station"], + 'WSen+t"Penguin size at Palmer Station"'], ) # Define colormap to use for three categories From cc9756e8e252a166981e219fb6a75399a62cf22e Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 7 Mar 2021 16:03:53 +0100 Subject: [PATCH 12/33] modified docstrings --- examples/gallery/plot/points-categorical.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index 99fdde1af98..08fa06f2c30 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -2,7 +2,13 @@ Color points by categories --------------------------- The :meth:`pygmt.Figure.plot` method can be used to plot symbols which are -color-coded by categories. +color-coded by categories. In the example below, we show how the +`palmerpenguins dataset `__ +can be visualized. Here, we can pass the individual categories included in +the species column directly to the `color` parameter via +`color=df.species.cat.codes.astype(int)`. Additionally, we have to set +`cmap=True`. A desired colormap can be selected via the `pygmt.makecpt` +method. """ import numpy as np From 1974ba5c62362d3ee2e76746c6659c47ce49fb49 Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Sun, 7 Mar 2021 15:05:42 +0000 Subject: [PATCH 13/33] [format-command] fixes --- examples/gallery/plot/points-categorical.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index 08fa06f2c30..c1888c693c4 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -34,9 +34,11 @@ fig.basemap( region=region, projection="X10c/10c", - frame=['xafg+l"Bill length in mm"', - 'yafg+l"Bill depth in mm"', - 'WSen+t"Penguin size at Palmer Station"'], + frame=[ + 'xafg+l"Bill length in mm"', + 'yafg+l"Bill depth in mm"', + 'WSen+t"Penguin size at Palmer Station"', + ], ) # Define colormap to use for three categories From 5434d2f9d5ff17347e7f385a2d7cbf47a4e0bcb5 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Sun, 7 Mar 2021 16:19:16 +0100 Subject: [PATCH 14/33] updates --- examples/gallery/plot/points-categorical.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index c1888c693c4..084243abd25 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -5,9 +5,9 @@ color-coded by categories. In the example below, we show how the `palmerpenguins dataset `__ can be visualized. Here, we can pass the individual categories included in -the species column directly to the `color` parameter via -`color=df.species.cat.codes.astype(int)`. Additionally, we have to set -`cmap=True`. A desired colormap can be selected via the `pygmt.makecpt` +the species column directly to the ``color`` parameter via +``color=df.species.cat.codes.astype(int)``. Additionally, we have to set +``cmap=True``. A desired colormap can be selected via the :meth:`pygmt.makecpt` method. """ From e096fc6d4e1f4519ed60fecdf862740e0ffdd059 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Tue, 9 Mar 2021 19:14:56 +0100 Subject: [PATCH 15/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Dongdong Tian --- examples/gallery/plot/points-categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index 084243abd25..9c7e37bb0f7 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -24,7 +24,7 @@ region = pygmt.info( table=df[["bill_length_mm", "bill_depth_mm"]], # x and y columns per_column=True, # report output as a numpy array - spacing="3/2", # rounds x and y intervals by 3 and 2 respectively + spacing=(3, 2), # rounds x and y intervals by 3 and 2 respectively ) # Make our 2D categorical scatter plot, coloring each of the 3 species differently From b99319f46ee47c01693f3a06aa1de997824c0f09 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Wed, 10 Mar 2021 17:21:39 +0100 Subject: [PATCH 16/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Yao Jiayuan --- examples/gallery/plot/points-categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index 9c7e37bb0f7..7cf35d778cb 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -36,7 +36,7 @@ projection="X10c/10c", frame=[ 'xafg+l"Bill length in mm"', - 'yafg+l"Bill depth in mm"', + 'yafg+l"Bill depth (mm)"', 'WSen+t"Penguin size at Palmer Station"', ], ) From 9a94c9026d3b6c80961eeeff81826b687ab18e94 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Wed, 10 Mar 2021 17:25:13 +0100 Subject: [PATCH 17/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Dongdong Tian --- examples/gallery/plot/points-categorical.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index 7cf35d778cb..e0c685120d5 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -49,8 +49,8 @@ x=df.bill_length_mm, # Use another feature as y data input (bill depth) y=df.bill_depth_mm, - # Vary each symbol size according to another feature (body mass) - sizes=7.5 * 10 ** -5 * df.body_mass_g, + # Vary each symbol size according to another feature (body mass, scaled by 7.5*10e-5) + sizes=df.body_mass_g * 7.5 * 10 ** -5, # Points colored by categorical number code color=df.species.cat.codes.astype(int), # Use colormap created by makecpt From a7d6db593bef28cffd9650985d04c16134e59f0e Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Wed, 10 Mar 2021 17:25:22 +0100 Subject: [PATCH 18/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Yao Jiayuan --- examples/gallery/plot/points-categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index e0c685120d5..8beb4b9759f 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -27,7 +27,7 @@ spacing=(3, 2), # rounds x and y intervals by 3 and 2 respectively ) -# Make our 2D categorical scatter plot, coloring each of the 3 species differently +# Make a 2D categorical scatter plot, coloring each of the 3 species differently fig = pygmt.Figure() # Generate basemap of 10cm x 10cm size From 571d99b57211bcfae9b5616abaa547c2ecbb1860 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Wed, 10 Mar 2021 17:25:32 +0100 Subject: [PATCH 19/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Yao Jiayuan --- examples/gallery/plot/points-categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index 8beb4b9759f..a904a10a1c9 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -30,7 +30,7 @@ # Make a 2D categorical scatter plot, coloring each of the 3 species differently fig = pygmt.Figure() -# Generate basemap of 10cm x 10cm size +# Generate a basemap of 10 cm x 10 cm size fig.basemap( region=region, projection="X10c/10c", From 7c8462c25c62058479cd867d6b779dc7ef78affb Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Wed, 10 Mar 2021 17:25:45 +0100 Subject: [PATCH 20/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Yao Jiayuan --- examples/gallery/plot/points-categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index a904a10a1c9..d6cb3eccc66 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -41,7 +41,7 @@ ], ) -# Define colormap to use for three categories +# Define a colormap to be used for three categories pygmt.makecpt(cmap="inferno", color_model="+c", series=(0, 3, 1)) fig.plot( From ee153fd726a4de017a0131d96f4456adb4bcb54f Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Wed, 10 Mar 2021 17:26:24 +0100 Subject: [PATCH 21/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Yao Jiayuan --- examples/gallery/plot/points-categorical.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index d6cb3eccc66..1b9835c30ac 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -45,9 +45,8 @@ pygmt.makecpt(cmap="inferno", color_model="+c", series=(0, 3, 1)) fig.plot( - # Use one feature as x data input (bill length) + # Use bill length and bill depth as x and y data input, respectively x=df.bill_length_mm, - # Use another feature as y data input (bill depth) y=df.bill_depth_mm, # Vary each symbol size according to another feature (body mass, scaled by 7.5*10e-5) sizes=df.body_mass_g * 7.5 * 10 ** -5, From 6a81b1b455ad616035b39155fdb8e10b6c7a775d Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Wed, 10 Mar 2021 17:26:48 +0100 Subject: [PATCH 22/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Yao Jiayuan --- examples/gallery/plot/points-categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index 1b9835c30ac..ad54aa3fe91 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -23,7 +23,7 @@ # The below example will return a numpy array like [30.0, 60.0, 12.0, 22.0] region = pygmt.info( table=df[["bill_length_mm", "bill_depth_mm"]], # x and y columns - per_column=True, # report output as a numpy array + per_column=True, # report the min/max values per column as a numpy array spacing=(3, 2), # rounds x and y intervals by 3 and 2 respectively ) From 439d544ed9daaa4f2275716890eb02bd5db294fe Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Wed, 10 Mar 2021 17:40:21 +0100 Subject: [PATCH 23/33] updates based on code review --- examples/gallery/plot/points-categorical.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index ad54aa3fe91..ed4c459391e 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -24,7 +24,9 @@ region = pygmt.info( table=df[["bill_length_mm", "bill_depth_mm"]], # x and y columns per_column=True, # report the min/max values per column as a numpy array - spacing=(3, 2), # rounds x and y intervals by 3 and 2 respectively + # round the min/max values of the first two columns to the nearest multiple + # of 3 and 2, respectively + spacing=(3, 2), ) # Make a 2D categorical scatter plot, coloring each of the 3 species differently @@ -35,13 +37,16 @@ region=region, projection="X10c/10c", frame=[ - 'xafg+l"Bill length in mm"', + 'xafg+l"Bill length (mm)"', 'yafg+l"Bill depth (mm)"', 'WSen+t"Penguin size at Palmer Station"', ], ) -# Define a colormap to be used for three categories +# Define a colormap to be used for three categories, +# use color_model="+c" to write the discrete color palette "inferno" in +# categorical format, define the range of the new CPT using the +# series parameter (lowest value, highest value, interval) pygmt.makecpt(cmap="inferno", color_model="+c", series=(0, 3, 1)) fig.plot( From 8897f7e084c19b609525309f0a20767f8973d718 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Wed, 10 Mar 2021 19:52:52 +0100 Subject: [PATCH 24/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Yao Jiayuan --- examples/gallery/plot/points-categorical.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index ed4c459391e..eab4f9173e8 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -44,10 +44,10 @@ ) # Define a colormap to be used for three categories, -# use color_model="+c" to write the discrete color palette "inferno" in -# categorical format, define the range of the new CPT using the -# series parameter (lowest value, highest value, interval) -pygmt.makecpt(cmap="inferno", color_model="+c", series=(0, 3, 1)) +# define the range of the new discrete CPT using the series parameter +# (lowest value, highest value, interval), use color_model="+c" to write +# the discrete color palette "inferno" in categorical format +pygmt.makecpt(cmap="inferno", series=(0, 3, 1), color_model="+c") fig.plot( # Use bill length and bill depth as x and y data input, respectively From 0103af4b75cd325283b4157240884d9a922b9ad0 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 11 Mar 2021 08:18:14 +0100 Subject: [PATCH 25/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Dongdong Tian --- examples/gallery/plot/points-categorical.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index eab4f9173e8..5abb8739635 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -11,7 +11,6 @@ method. """ -import numpy as np import pandas as pd import pygmt From 3d54b396d48a4b5a36b6113b6031e6b5a78fdd3c Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 11 Mar 2021 08:18:22 +0100 Subject: [PATCH 26/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Dongdong Tian --- examples/gallery/plot/points-categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index 5abb8739635..4b116a1dd8b 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -16,7 +16,7 @@ # Load sample penguins data and convert 'species' column to categorical dtype df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/penguins.csv") -df["species"] = df.species.astype(dtype="category") +df.species = df.species.astype(dtype="category") # Use pygmt.info to get region bounds (xmin, xmax, ymin, ymax) # The below example will return a numpy array like [30.0, 60.0, 12.0, 22.0] From 0164e86c7dfe1f43a9de4ab2ed1c2eeac3d03383 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 11 Mar 2021 08:18:31 +0100 Subject: [PATCH 27/33] Update examples/gallery/plot/points-categorical.py Co-authored-by: Dongdong Tian --- examples/gallery/plot/points-categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points-categorical.py index 4b116a1dd8b..73f0558e291 100644 --- a/examples/gallery/plot/points-categorical.py +++ b/examples/gallery/plot/points-categorical.py @@ -44,7 +44,7 @@ # Define a colormap to be used for three categories, # define the range of the new discrete CPT using the series parameter -# (lowest value, highest value, interval), use color_model="+c" to write +# (lowest_value, highest_value, interval), use color_model="+c" to write # the discrete color palette "inferno" in categorical format pygmt.makecpt(cmap="inferno", series=(0, 3, 1), color_model="+c") From 544f475cbbd526c1534a3ac6d0be0240713354ce Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Thu, 11 Mar 2021 08:22:39 +0100 Subject: [PATCH 28/33] use underscore in filename --- .../gallery/plot/{points-categorical.py => points_categorical.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/gallery/plot/{points-categorical.py => points_categorical.py} (100%) diff --git a/examples/gallery/plot/points-categorical.py b/examples/gallery/plot/points_categorical.py similarity index 100% rename from examples/gallery/plot/points-categorical.py rename to examples/gallery/plot/points_categorical.py From 076ad4578e31aa1ffbac2b5d01088f8dab635655 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 12 Mar 2021 00:31:21 -0500 Subject: [PATCH 29/33] Move to symbols directory --- examples/gallery/{plot => symbols}/points_categorical.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/gallery/{plot => symbols}/points_categorical.py (100%) diff --git a/examples/gallery/plot/points_categorical.py b/examples/gallery/symbols/points_categorical.py similarity index 100% rename from examples/gallery/plot/points_categorical.py rename to examples/gallery/symbols/points_categorical.py From 6c010b006bcd9b688d4cf176241f7c7a3993d970 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Fri, 12 Mar 2021 08:35:44 +0100 Subject: [PATCH 30/33] Update examples/gallery/symbols/points_categorical.py Co-authored-by: Dongdong Tian --- examples/gallery/symbols/points_categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/symbols/points_categorical.py b/examples/gallery/symbols/points_categorical.py index 73f0558e291..d6e81c675eb 100644 --- a/examples/gallery/symbols/points_categorical.py +++ b/examples/gallery/symbols/points_categorical.py @@ -5,7 +5,7 @@ color-coded by categories. In the example below, we show how the `palmerpenguins dataset `__ can be visualized. Here, we can pass the individual categories included in -the species column directly to the ``color`` parameter via +the "species" column directly to the ``color`` parameter via ``color=df.species.cat.codes.astype(int)``. Additionally, we have to set ``cmap=True``. A desired colormap can be selected via the :meth:`pygmt.makecpt` method. From a60af871b760b080518f001f5fafa656cf34d4c2 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Fri, 12 Mar 2021 08:36:07 +0100 Subject: [PATCH 31/33] Update examples/gallery/symbols/points_categorical.py Co-authored-by: Dongdong Tian --- examples/gallery/symbols/points_categorical.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/gallery/symbols/points_categorical.py b/examples/gallery/symbols/points_categorical.py index d6e81c675eb..8ce1fae0746 100644 --- a/examples/gallery/symbols/points_categorical.py +++ b/examples/gallery/symbols/points_categorical.py @@ -42,10 +42,10 @@ ], ) -# Define a colormap to be used for three categories, -# define the range of the new discrete CPT using the series parameter -# (lowest_value, highest_value, interval), use color_model="+c" to write -# the discrete color palette "inferno" in categorical format +# Define a colormap to be used for three categories, define the range of the +# new discrete CPT using series=(lowest_value, highest_value, interval), +# use color_model="+c" to write the discrete color palette "inferno" in +# categorical format pygmt.makecpt(cmap="inferno", series=(0, 3, 1), color_model="+c") fig.plot( From a178ae645571ad836fad884373741df70ce42ee2 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Fri, 12 Mar 2021 08:36:18 +0100 Subject: [PATCH 32/33] Update examples/gallery/symbols/points_categorical.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/symbols/points_categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/symbols/points_categorical.py b/examples/gallery/symbols/points_categorical.py index 8ce1fae0746..35b1ed0893b 100644 --- a/examples/gallery/symbols/points_categorical.py +++ b/examples/gallery/symbols/points_categorical.py @@ -3,7 +3,7 @@ --------------------------- The :meth:`pygmt.Figure.plot` method can be used to plot symbols which are color-coded by categories. In the example below, we show how the -`palmerpenguins dataset `__ +`Palmer Penguins dataset `__ can be visualized. Here, we can pass the individual categories included in the "species" column directly to the ``color`` parameter via ``color=df.species.cat.codes.astype(int)``. Additionally, we have to set From b06b51c820e8a70d0c7bea2ef9320e9e5dcb51b1 Mon Sep 17 00:00:00 2001 From: Michael Grund Date: Fri, 12 Mar 2021 08:54:44 +0100 Subject: [PATCH 33/33] Update examples/gallery/symbols/points_categorical.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- examples/gallery/symbols/points_categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/symbols/points_categorical.py b/examples/gallery/symbols/points_categorical.py index 35b1ed0893b..9a2a302939a 100644 --- a/examples/gallery/symbols/points_categorical.py +++ b/examples/gallery/symbols/points_categorical.py @@ -53,7 +53,7 @@ x=df.bill_length_mm, y=df.bill_depth_mm, # Vary each symbol size according to another feature (body mass, scaled by 7.5*10e-5) - sizes=df.body_mass_g * 7.5 * 10 ** -5, + sizes=df.body_mass_g * 7.5e-5, # Points colored by categorical number code color=df.species.cat.codes.astype(int), # Use colormap created by makecpt