From e783df3571174169742c7e0db67a05f68898c0b5 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 16 Oct 2022 17:37:09 +0200 Subject: [PATCH 1/4] Rework docs about scatter --- doc/user-guide/plotting.rst | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/doc/user-guide/plotting.rst b/doc/user-guide/plotting.rst index 2a4cc57f079..a64651887c3 100644 --- a/doc/user-guide/plotting.rst +++ b/doc/user-guide/plotting.rst @@ -756,7 +756,7 @@ Consider this dataset .. ipython:: python - ds = xr.tutorial.scatter_example_dataset() + ds = xr.tutorial.scatter_example_dataset(seed=42) ds @@ -779,17 +779,19 @@ The ``hue`` kwarg lets you vary the color by variable value @savefig ds_hue_scatter.png ds.plot.scatter(x="A", y="B", hue="w") -When ``hue`` is specified, a colorbar is added for numeric ``hue`` DataArrays by -default and a legend is added for non-numeric ``hue`` DataArrays (as above). -You can force a legend instead of a colorbar by setting ``hue_style='discrete'``. -Additionally, the boolean kwarg ``add_guide`` can be used to prevent the display of a legend or colorbar (as appropriate). +You can force a legend instead of a colorbar by setting ``add_legend=True, add_colorbar=False``. .. ipython:: python :okwarning: - ds = ds.assign(w=[1, 2, 3, 5]) @savefig ds_discrete_legend_hue_scatter.png - ds.plot.scatter(x="A", y="B", hue="w", hue_style="discrete") + ds.plot.scatter(x="A", y="B", hue="w", add_legend=True, add_colorbar=False) + +.. ipython:: python + :okwarning: + + @savefig ds_discrete_legend_hue_scatter.png + ds.plot.scatter(x="A", y="B", hue="w", add_legend=False, add_colorbar=True) The ``markersize`` kwarg lets you vary the point's size by variable value. You can additionally pass ``size_norm`` to control how the variable's values are mapped to point sizes. @@ -798,7 +800,15 @@ You can additionally pass ``size_norm`` to control how the variable's values are :okwarning: @savefig ds_hue_size_scatter.png - ds.plot.scatter(x="A", y="B", hue="z", hue_style="discrete", markersize="z") + ds.plot.scatter(x="A", y="B", hue="y", markersize="z") + +The ``z`` kwarg lets you plot the data along the z-axis as well. + +.. ipython:: python + :okwarning: + + @savefig ds_hue_size_scatter_z.png + ds.plot.scatter(x="A", y="B", z="z", hue="y", markersize="x", row="x", col="w") Faceting is also possible @@ -806,8 +816,15 @@ Faceting is also possible :okwarning: @savefig ds_facet_scatter.png - ds.plot.scatter(x="A", y="B", col="x", row="z", hue="w", hue_style="discrete") + ds.plot.scatter(x="A", y="B", hue="y", markersize="x", row="x", col="w") + +And adding the z-axis + +.. ipython:: python + :okwarning: + @savefig ds_facet_scatter_z.png + ds.plot.scatter(x="A", y="B", z="z", hue="y", markersize="x", row="x", col="w") For more advanced scatter plots, we recommend converting the relevant data variables to a pandas DataFrame and using the extensive plotting capabilities of ``seaborn``. From 21b349388299907e2097204445b081c67d1ba15d Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 16 Oct 2022 17:57:15 +0200 Subject: [PATCH 2/4] Update plotting.rst --- doc/user-guide/plotting.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user-guide/plotting.rst b/doc/user-guide/plotting.rst index a64651887c3..fe69f788c73 100644 --- a/doc/user-guide/plotting.rst +++ b/doc/user-guide/plotting.rst @@ -808,7 +808,7 @@ The ``z`` kwarg lets you plot the data along the z-axis as well. :okwarning: @savefig ds_hue_size_scatter_z.png - ds.plot.scatter(x="A", y="B", z="z", hue="y", markersize="x", row="x", col="w") + ds.plot.scatter(x="A", y="B", z="z", hue="y", markersize="x") Faceting is also possible From 03a189d2fc15547242c9fb0ba986e8c1bda54d24 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 16 Oct 2022 18:13:33 +0200 Subject: [PATCH 3/4] Update plotting.rst --- doc/user-guide/plotting.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user-guide/plotting.rst b/doc/user-guide/plotting.rst index fe69f788c73..9d0e25e9570 100644 --- a/doc/user-guide/plotting.rst +++ b/doc/user-guide/plotting.rst @@ -790,7 +790,7 @@ You can force a legend instead of a colorbar by setting ``add_legend=True, add_c .. ipython:: python :okwarning: - @savefig ds_discrete_legend_hue_scatter.png + @savefig ds_discrete_colorbar_hue_scatter.png ds.plot.scatter(x="A", y="B", hue="w", add_legend=False, add_colorbar=True) The ``markersize`` kwarg lets you vary the point's size by variable value. From a63a0f1e17fb3bae5f50d76b4cfbc33b5aa53fa3 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sun, 16 Oct 2022 23:34:50 +0200 Subject: [PATCH 4/4] Show that dataarray scatter also exists. --- doc/user-guide/plotting.rst | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/user-guide/plotting.rst b/doc/user-guide/plotting.rst index 9d0e25e9570..6952a018c7f 100644 --- a/doc/user-guide/plotting.rst +++ b/doc/user-guide/plotting.rst @@ -763,7 +763,25 @@ Consider this dataset Scatter ~~~~~~~ -Suppose we want to scatter ``A`` against ``B`` +Let's plot the ``A`` DataArray as a function of the ``y`` coord + +.. ipython:: python + :okwarning: + + ds.A + + @savefig da_A_y.png + ds.A.plot.scatter(x="y") + +Same plot can be displayed using the dataset: + +.. ipython:: python + :okwarning: + + @savefig ds_A_y.png + ds.plot.scatter(x="y", y="A") + +Now suppose we want to scatter the ``A`` DataArray against the ``B`` DataArray .. ipython:: python :okwarning: