@@ -756,14 +756,32 @@ Consider this dataset
756
756
757
757
.. ipython :: python
758
758
759
- ds = xr.tutorial.scatter_example_dataset()
759
+ ds = xr.tutorial.scatter_example_dataset(seed = 42 )
760
760
ds
761
761
762
762
763
763
Scatter
764
764
~~~~~~~
765
765
766
- Suppose we want to scatter ``A `` against ``B ``
766
+ Let's plot the ``A `` DataArray as a function of the ``y `` coord
767
+
768
+ .. ipython :: python
769
+ :okwarning:
770
+
771
+ ds.A
772
+
773
+ @savefig da_A_y.png
774
+ ds.A.plot.scatter(x = " y" )
775
+
776
+ Same plot can be displayed using the dataset:
777
+
778
+ .. ipython :: python
779
+ :okwarning:
780
+
781
+ @savefig ds_A_y.png
782
+ ds.plot.scatter(x = " y" , y = " A" )
783
+
784
+ Now suppose we want to scatter the ``A `` DataArray against the ``B `` DataArray
767
785
768
786
.. ipython :: python
769
787
:okwarning:
@@ -779,17 +797,19 @@ The ``hue`` kwarg lets you vary the color by variable value
779
797
@savefig ds_hue_scatter.png
780
798
ds.plot.scatter(x = " A" , y = " B" , hue = " w" )
781
799
782
- When ``hue `` is specified, a colorbar is added for numeric ``hue `` DataArrays by
783
- default and a legend is added for non-numeric ``hue `` DataArrays (as above).
784
- You can force a legend instead of a colorbar by setting ``hue_style='discrete' ``.
785
- Additionally, the boolean kwarg ``add_guide `` can be used to prevent the display of a legend or colorbar (as appropriate).
800
+ You can force a legend instead of a colorbar by setting ``add_legend=True, add_colorbar=False ``.
786
801
787
802
.. ipython :: python
788
803
:okwarning:
789
804
790
- ds = ds.assign(w = [1 , 2 , 3 , 5 ])
791
805
@savefig ds_discrete_legend_hue_scatter.png
792
- ds.plot.scatter(x = " A" , y = " B" , hue = " w" , hue_style = " discrete" )
806
+ ds.plot.scatter(x = " A" , y = " B" , hue = " w" , add_legend = True , add_colorbar = False )
807
+
808
+ .. ipython :: python
809
+ :okwarning:
810
+
811
+ @savefig ds_discrete_colorbar_hue_scatter.png
812
+ ds.plot.scatter(x = " A" , y = " B" , hue = " w" , add_legend = False , add_colorbar = True )
793
813
794
814
The ``markersize `` kwarg lets you vary the point's size by variable value.
795
815
You can additionally pass ``size_norm `` to control how the variable's values are mapped to point sizes.
@@ -798,16 +818,31 @@ You can additionally pass ``size_norm`` to control how the variable's values are
798
818
:okwarning:
799
819
800
820
@savefig ds_hue_size_scatter.png
801
- ds.plot.scatter(x = " A" , y = " B" , hue = " z" , hue_style = " discrete" , markersize = " z" )
821
+ ds.plot.scatter(x = " A" , y = " B" , hue = " y" , markersize = " z" )
822
+
823
+ The ``z `` kwarg lets you plot the data along the z-axis as well.
824
+
825
+ .. ipython :: python
826
+ :okwarning:
827
+
828
+ @savefig ds_hue_size_scatter_z.png
829
+ ds.plot.scatter(x = " A" , y = " B" , z = " z" , hue = " y" , markersize = " x" )
802
830
803
831
Faceting is also possible
804
832
805
833
.. ipython :: python
806
834
:okwarning:
807
835
808
836
@savefig ds_facet_scatter.png
809
- ds.plot.scatter(x = " A" , y = " B" , col = " x" , row = " z" , hue = " w" , hue_style = " discrete" )
837
+ ds.plot.scatter(x = " A" , y = " B" , hue = " y" , markersize = " x" , row = " x" , col = " w" )
838
+
839
+ And adding the z-axis
840
+
841
+ .. ipython :: python
842
+ :okwarning:
810
843
844
+ @savefig ds_facet_scatter_z.png
845
+ ds.plot.scatter(x = " A" , y = " B" , z = " z" , hue = " y" , markersize = " x" , row = " x" , col = " w" )
811
846
812
847
For more advanced scatter plots, we recommend converting the relevant data variables
813
848
to a pandas DataFrame and using the extensive plotting capabilities of ``seaborn ``.
0 commit comments