Skip to content

Commit 4780440

Browse files
committed
Update _scatterplot.py
1 parent 8748940 commit 4780440

File tree

1 file changed

+45
-66
lines changed

1 file changed

+45
-66
lines changed

packages/python/plotly/plotly/figure_factory/_scatterplot.py

Lines changed: 45 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -851,136 +851,121 @@ def create_scatterplotmatrix(
851851
):
852852
"""
853853
Returns data for a scatterplot matrix;
854-
**deprecated**,
855-
use instead the plotly.graph_objects trace
856-
:class:`plotly.graph_objects.Splom`.
857-
858-
:param (array) df: array of the data with column headers
859-
:param (str) index: name of the index column in data array
860-
:param (list|tuple) endpts: takes an increasing sequece of numbers
861-
that defines intervals on the real line. They are used to group
862-
the entries in an index of numbers into their corresponding
863-
interval and therefore can be treated as categorical data
864-
:param (str) diag: sets the chart type for the main diagonal plots.
865-
The options are 'scatter', 'histogram' and 'box'.
866-
:param (int|float) height: sets the height of the chart
867-
:param (int|float) width: sets the width of the chart
868-
:param (float) size: sets the marker size (in px)
869-
:param (str) title: the title label of the scatterplot matrix
870-
:param (str|tuple|list|dict) colormap: either a plotly scale name,
871-
an rgb or hex color, a color tuple, a list of colors or a
872-
dictionary. An rgb color is of the form 'rgb(x, y, z)' where
873-
x, y and z belong to the interval [0, 255] and a color tuple is a
874-
tuple of the form (a, b, c) where a, b and c belong to [0, 1].
875-
If colormap is a list, it must contain valid color types as its
876-
members.
877-
If colormap is a dictionary, all the string entries in
878-
the index column must be a key in colormap. In this case, the
879-
colormap_type is forced to 'cat' or categorical
880-
:param (str) colormap_type: determines how colormap is interpreted.
881-
Valid choices are 'seq' (sequential) and 'cat' (categorical). If
882-
'seq' is selected, only the first two colors in colormap will be
883-
considered (when colormap is a list) and the index values will be
884-
linearly interpolated between those two colors. This option is
885-
forced if all index values are numeric.
886-
If 'cat' is selected, a color from colormap will be assigned to
887-
each category from index, including the intervals if endpts is
888-
being used
889-
:param (dict) **kwargs: a dictionary of scatterplot arguments
890-
The only forbidden parameters are 'size', 'color' and
891-
'colorscale' in 'marker'
892-
854+
**deprecated**. Use [`plotly.graph_objects.Splom`][plotly.graph_objects.Splom] instead.
855+
856+
Parameters
857+
----------
858+
df : array-like
859+
Array of the data with column headers.
860+
index : str
861+
Name of the index column in data array.
862+
endpts : list or tuple
863+
Takes an increasing sequence of numbers that defines intervals on the real line.
864+
They are used to group the entries in an index of numbers into their corresponding
865+
interval and therefore can be treated as categorical data.
866+
diag : str
867+
Sets the chart type for the main diagonal plots. The options are 'scatter', 'histogram' and 'box'.
868+
height : int or float
869+
Sets the height of the chart.
870+
width : int or float
871+
Sets the width of the chart.
872+
size : float
873+
Sets the marker size (in px).
874+
title : str
875+
The title label of the scatterplot matrix.
876+
colormap : str, tuple, list, or dict
877+
Either a plotly scale name, an rgb or hex color, a color tuple, a list of colors or a dictionary.
878+
An rgb color is of the form 'rgb(x, y, z)' where x, y and z belong to the interval [0, 255] and a color tuple is a
879+
tuple of the form (a, b, c) where a, b and c belong to [0, 1]. If colormap is a list, it must contain valid color types as its
880+
members. If colormap is a dictionary, all the string entries in the index column must be a key in colormap. In this case, the
881+
colormap_type is forced to 'cat' or categorical.
882+
colormap_type : str
883+
Determines how colormap is interpreted. Valid choices are 'seq' (sequential) and 'cat' (categorical). If
884+
'seq' is selected, only the first two colors in colormap will be considered (when colormap is a list) and the index values will be
885+
linearly interpolated between those two colors. This option is forced if all index values are numeric.
886+
If 'cat' is selected, a color from colormap will be assigned to each category from index, including the intervals if endpts is
887+
being used.
888+
**kwargs : dict
889+
A dictionary of scatterplot arguments. The only forbidden parameters are 'size', 'color' and
890+
'colorscale' in 'marker'.
891+
892+
Returns
893+
-------
894+
plotly.graph_objs._figure.Figure
895+
A Plotly figure object representing the scatterplot matrix.
896+
897+
Examples
898+
--------
893899
Example 1: Vanilla Scatterplot Matrix
894900
895901
>>> from plotly.graph_objs import graph_objs
896902
>>> from plotly.figure_factory import create_scatterplotmatrix
897-
898903
>>> import numpy as np
899904
>>> import pandas as pd
900-
901905
>>> # Create dataframe
902906
>>> df = pd.DataFrame(np.random.randn(10, 2),
903907
... columns=['Column 1', 'Column 2'])
904-
905908
>>> # Create scatterplot matrix
906909
>>> fig = create_scatterplotmatrix(df)
907910
>>> fig.show()
908911
909-
910912
Example 2: Indexing a Column
911913
912914
>>> from plotly.graph_objs import graph_objs
913915
>>> from plotly.figure_factory import create_scatterplotmatrix
914-
915916
>>> import numpy as np
916917
>>> import pandas as pd
917-
918918
>>> # Create dataframe with index
919919
>>> df = pd.DataFrame(np.random.randn(10, 2),
920920
... columns=['A', 'B'])
921-
922921
>>> # Add another column of strings to the dataframe
923922
>>> df['Fruit'] = pd.Series(['apple', 'apple', 'grape', 'apple', 'apple',
924923
... 'grape', 'pear', 'pear', 'apple', 'pear'])
925-
926924
>>> # Create scatterplot matrix
927925
>>> fig = create_scatterplotmatrix(df, index='Fruit', size=10)
928926
>>> fig.show()
929927
930-
931928
Example 3: Styling the Diagonal Subplots
932929
933930
>>> from plotly.graph_objs import graph_objs
934931
>>> from plotly.figure_factory import create_scatterplotmatrix
935-
936932
>>> import numpy as np
937933
>>> import pandas as pd
938-
939934
>>> # Create dataframe with index
940935
>>> df = pd.DataFrame(np.random.randn(10, 4),
941936
... columns=['A', 'B', 'C', 'D'])
942-
943937
>>> # Add another column of strings to the dataframe
944938
>>> df['Fruit'] = pd.Series(['apple', 'apple', 'grape', 'apple', 'apple',
945939
... 'grape', 'pear', 'pear', 'apple', 'pear'])
946-
947940
>>> # Create scatterplot matrix
948941
>>> fig = create_scatterplotmatrix(df, diag='box', index='Fruit', height=1000,
949942
... width=1000)
950943
>>> fig.show()
951944
952-
953945
Example 4: Use a Theme to Style the Subplots
954946
955947
>>> from plotly.graph_objs import graph_objs
956948
>>> from plotly.figure_factory import create_scatterplotmatrix
957-
958949
>>> import numpy as np
959950
>>> import pandas as pd
960-
961951
>>> # Create dataframe with random data
962952
>>> df = pd.DataFrame(np.random.randn(100, 3),
963953
... columns=['A', 'B', 'C'])
964-
965954
>>> # Create scatterplot matrix using a built-in
966955
>>> # Plotly palette scale and indexing column 'A'
967956
>>> fig = create_scatterplotmatrix(df, diag='histogram', index='A',
968957
... colormap='Blues', height=800, width=800)
969958
>>> fig.show()
970959
971-
972960
Example 5: Example 4 with Interval Factoring
973961
974962
>>> from plotly.graph_objs import graph_objs
975963
>>> from plotly.figure_factory import create_scatterplotmatrix
976-
977964
>>> import numpy as np
978965
>>> import pandas as pd
979-
980966
>>> # Create dataframe with random data
981967
>>> df = pd.DataFrame(np.random.randn(100, 3),
982968
... columns=['A', 'B', 'C'])
983-
984969
>>> # Create scatterplot matrix using a list of 2 rgb tuples
985970
>>> # and endpoints at -1, 0 and 1
986971
>>> fig = create_scatterplotmatrix(df, diag='histogram', index='A',
@@ -990,30 +975,24 @@ def create_scatterplotmatrix(
990975
... endpts=[-1, 0, 1], height=800, width=800)
991976
>>> fig.show()
992977
993-
994978
Example 6: Using the colormap as a Dictionary
995979
996980
>>> from plotly.graph_objs import graph_objs
997981
>>> from plotly.figure_factory import create_scatterplotmatrix
998-
999982
>>> import numpy as np
1000983
>>> import pandas as pd
1001984
>>> import random
1002-
1003985
>>> # Create dataframe with random data
1004986
>>> df = pd.DataFrame(np.random.randn(100, 3),
1005987
... columns=['Column A',
1006988
... 'Column B',
1007989
... 'Column C'])
1008-
1009990
>>> # Add new color column to dataframe
1010991
>>> new_column = []
1011992
>>> strange_colors = ['turquoise', 'limegreen', 'goldenrod']
1012-
1013993
>>> for j in range(100):
1014994
... new_column.append(random.choice(strange_colors))
1015995
>>> df['Colors'] = pd.Series(new_column, index=df.index)
1016-
1017996
>>> # Create scatterplot matrix using a dictionary of hex color values
1018997
>>> # which correspond to actual color names in 'Colors' column
1019998
>>> fig = create_scatterplotmatrix(

0 commit comments

Comments
 (0)