Problem with scatterplot matrix objects in subplots

Hi all,

I am unable to resolve the issue below which deals with a graph_objs.go.Splom() argument for tools.make_subplots.append_trace().

I am using plotly version 3.3.0.

import pandas as pd

import plotly
import plotly.graph_objs as go
from plotly import tools

from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)


df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/iris-data.csv')

trace = go.Splom(dimensions=[dict(label='sepal length',
                                 values=df['sepal length']),
                            dict(label='sepal width',
                                 values=df['sepal width']),
                            dict(label='petal length',
                                 values=df['petal length']),
                            dict(label='petal width',
                                 values=df['petal width'])],
                )

# fig = dict(data=[trace])
# iplot(fig, filename='splom-iris1')

fig = tools.make_subplots(rows=2, cols=2, subplot_titles=('Plot 1', 'Plot 2',
                                                            'Plot 3', 'Plot 4'))
fig.append_trace(trace, 1, 1)

I get the following error :

ValueError: Invalid property specified for object of type plotly.graph_objs.Splom: 'xaxis'

I can however do an iplot of the Splom object (see commented code). Any help appreciated.

P.S. I read this bit on appending trace objects and also tried a go.FigureWidget solution but none of it worked.

@champost The splom is a special Plotly trace. It doesn’t work with tools.make_subplots. Perhaps your intention was to insert each splom in a subplot, but this operation is forbidden.

Download this code https://plot.ly/python/splom/ and read the introduction to understand what is plotted in each cell.

Notice in the layout definition that xaxes, respectively yaxes 1,2,3,4 , define the reference system for each cell in the scatter plot matrix.
Only gridcolor='#fff' in axis definition is obsolete in the above code. Change it to
gridcolor='#ffffff' and you’ll get a splom.

Hi @empet, thank you for your prompt reply. Indeed, I should have made my intention more clear.

I do want a “subplot of sploms” and my Iris data example was inspired by https://plot.ly/python/splom/ (all of which I could reproduce).

So could you suggest an alternative for plotting a “subplot of sploms” ?

If not possible in plotly currently, I was mulling about inserting pandas.plotting.scatter_matrix objects into a standard matplotlib subplot.

Thanks in advance!

@champost I found this solution to your requirements:

Define the four sploms as go.FigureWidget instances and insert them in a dashboard
as follows:

import ipywidgets as ipw
ipw.VBox([ipw.HBox([fig1, fig2]), ipw.HBox([fig3, fig4])])

Instead of vertical_spacing, horizontal_spacing keys from the usual plotly subplots definition,
here you have to tune the margins such that two horizontally/vertically stacked figures to be sufficiently close:
https://plot.ly/~empet/14994.

1 Like

I think you could also use the (relatively) new ipywidgets GridBox layout (See https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Styling.html#The-Grid-layout). This may work a little better for controlling spacing than combining HBox and VBox.

-Jon

2 Likes

Thanks a ton @empet and @jmmease.

Everything works like a charm now.

PS. For anyone having difficulty (like I had) with no output when using go.FigureWidget, make sure to update your notebook version (>= 5.3) with this command sudo pip install --upgrade --ignore-installed notebook (i.e. if you have admin rights).

Cheers!

1 Like