Scatterplot Matrix in Python/v3
How to make scatterplot-matrix plots in Python with Plotly.
Note: this page is part of the documentation for version 3 of Plotly.py, which is not the most recent version.
See our Version 4 Migration Guide for information about how to upgrade.
See our Version 4 Migration Guide for information about how to upgrade.
New to Plotly?¶
Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!
Version Check¶
Note: Scatterplot Matrix is available in version 1.9.11+
Run pip install plotly --upgrade
to update your Plotly version
In [1]:
import plotly
plotly.__version__
Out[1]:
Basic Scatterplot Matrix¶
In [2]:
import plotly.plotly as py
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
dataframe = pd.DataFrame(np.random.randn(10, 2),
columns=['Column A', 'Column B'])
fig = ff.create_scatterplotmatrix(dataframe, height=800, width=800)
py.iplot(fig, filename='Basic Scatterplot Matrix')
Out[2]:
Index a Column¶
In [3]:
import plotly.plotly as py
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
dataframe = pd.DataFrame(np.random.randn(10, 2),
columns=['Column A', 'Column B'])
dataframe['Fruit'] = pd.Series(['apple', 'apple', 'grape', 'apple', 'apple',
'grape', 'pear', 'pear', 'apple', 'pear'])
fig = ff.create_scatterplotmatrix(dataframe, index='Fruit', size=10, height=800, width=800)
py.iplot(fig, filename = 'Index a Column')
Out[3]:
Box Plots along Diagonal¶
In [4]:
import plotly.plotly as py
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
dataframe = pd.DataFrame(np.random.randn(10, 4),
columns=['Column A', 'Column B', 'Column C', 'Column D'])
dataframe['Fruit'] = pd.Series(['apple', 'apple', 'grape', 'apple', 'apple',
'grape', 'pear', 'pear', 'apple', 'pear'])
fig = ff.create_scatterplotmatrix(dataframe, diag='box', index='Fruit',
height=800, width=800)
py.iplot(fig, filename='Box plots along Diagonal Subplots')
Out[4]:
Histograms along Diagonal¶
In [5]:
import plotly.plotly as py
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
dataframe = pd.DataFrame(np.random.randn(20, 4),
columns=['Column A', 'Column B', 'Column C', 'Column D'])
dataframe['Fruit'] = pd.Series(['apple', 'apple', 'grape', 'apple', 'apple',
'grape', 'pear', 'pear', 'apple', 'pear',
'apple', 'apple', 'grape', 'apple', 'apple',
'grape', 'pear', 'pear', 'apple', 'pear'])
fig = ff.create_scatterplotmatrix(dataframe, diag='histogram', index='Fruit',
height=800, width=800)
py.iplot(fig, filename='Histograms along Diagonal Subplots')
Out[5]:
Sequential Colormap¶
In [6]:
import plotly.plotly as py
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
dataframe = pd.DataFrame(np.random.randn(100, 3),
columns=['Column A', 'Column B', 'Column C'])
fig = ff.create_scatterplotmatrix(dataframe, diag='histogram',index='Column A',
colormap='Blues', height=800, width=800)
py.iplot(fig, filename = 'Use a Sequential Colormap')
Out[6]:
Custom Sequential Colormap¶
In [7]:
import plotly.plotly as py
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
dataframe = pd.DataFrame(np.random.randn(100, 3),
columns=['Column A', 'Column B', 'Column C'])
fig = ff.create_scatterplotmatrix(dataframe, diag='histogram', index='Column A',
colormap=['rgb(100, 150, 255)', '#F0963C', 'rgb(51, 255, 153)'],
colormap_type='seq', height=800, width=800)
py.iplot(fig, filename = 'Custom Sequential Colormap')
Out[7]:
Partition Numeric Data into Intervals¶
In [8]:
import plotly.plotly as py
import plotly.figure_factory as FF
import numpy as np
import pandas as pd
dataframe = pd.DataFrame(np.random.randn(100, 3),
columns=['Column A', 'Column B', 'Column C'])
fig = FF.create_scatterplotmatrix(dataframe, diag='box', index='Column A',
colormap='Portland', colormap_type='seq',
endpts=[-1, 0, 1],
height=800, width=800, size=12,
marker=dict(symbol=25))
py.iplot(fig, filename = 'Partition Numeric Data into Intervals')
Out[8]:
Categorical Colormap¶
In [9]:
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
import random
dataframe = pd.DataFrame(np.random.randn(100, 2),
columns=['Column A', 'Column B'])
new_column = []
fruits = ['apple', 'blueberry', 'banana', 'orange', 'raspberry']
for j in range(100):
new_column.append(random.choice(fruits))
dataframe['Fruits'] = pd.Series(new_column, index=dataframe.index)
fig = ff.create_scatterplotmatrix(dataframe, index='Fruits', diag='histogram',
colormap= ['#d95f0e', (0.2, 0.6, 1), 'rgb(230,247,188)', '#bcbddc', (0.8, 0.7, 0.65)],
colormap_type='cat',
height=800, width=800,
size=15, marker=dict(symbol='square-open'))
py.iplot(fig, filename = 'Use a Categorical Colormap')
Out[9]:
Colormap as a Dictionary¶
In [10]:
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
import random
dataframe = pd.DataFrame(np.random.randn(100, 3),
columns=['Column A', 'Column B', 'Column C'])
new_column = []
strange_colors = ['turquoise', 'limegreen', 'goldenrod']
for j in range(100):
new_column.append(random.choice(strange_colors))
dataframe['Colors'] = pd.Series(new_column, index=dataframe.index)
fig = ff.create_scatterplotmatrix(dataframe, diag='box', index='Colors',
colormap= dict(
turquoise = '#00F5FF',
limegreen = '#32CD32',
goldenrod = '#DAA520'
),
colormap_type='cat',
height=800, width=800)
py.iplot(fig, filename = 'Colormap as a Dictionary')
Out[10]:
Reference¶
In [11]:
help(ff.create_scatterplotmatrix)
