#!/usr/bin/env python # coding: utf-8 # #### New to Plotly? # Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/). #
You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online). #
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (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__ # #### 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') # #### 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') # #### 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') # #### 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') # #### 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') # #### 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') # #### 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') # #### 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') # #### 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') # #### Reference # In[11]: help(ff.create_scatterplotmatrix) # In[1]: from IPython.display import display, HTML display(HTML('')) display(HTML('')) get_ipython().system(' pip install git+https://github.com/plotly/publisher.git --upgrade') import publisher publisher.publish( 'scatterplot-matrix.ipynb', 'python/legacy/scatterplot-matrix/', 'Scatterplot Matrix', 'How to make scatterplot-matrix plots in Python with Plotly.', title = 'Python Scatterplot Matrix | plotly', name = 'Scatterplot Matrix', has_thumbnail='true', thumbnail='thumbnail/scatterplot-matrix.jpg', language='python', display_as='legacy_charts', order=10.1, ipynb= '~notebook_demo/27') # In[ ]: