Subplots in Plotly - Cufflinks: How to put two subplots in the same plot

2.8k views Asked by At

I have two different dataframes, with the same columns and I want to create an interactive plot and put both subplots in the same figure.

avg1 = (flowData_AR.pivot_table(index=flowData_AR['TimeStamp'].dt.month.rename('month'),
                            values='Value', aggfunc=np.mean))

avg2 = (flowData_OIJ.pivot_table(index=flowData_OIJ['TimeStamp'].dt.month.rename('month'),
                            values='Value', aggfunc=np.mean))

avg1.iplot(kind='line', subplots=True,xTitle='Month', yTitle='Average', title='aaa')
avg2.iplot(kind='line',subplots=True, xTitle='Month', yTitle='Average', title='bbb')

I have been trying, and seeing the examples at: https://plot.ly/ipython-notebooks/cufflinks/#dataframes but I`m not able to do this with Cufflinks.

Could you please help me?

1

There are 1 answers

1
uaqro On

Although there's documentation on the matter in plotly, I've had a lot of trouble in getting the information right to make subplots. Here's the solution I've got so far:

The first part matters, I've had lots of issues importing the modules described in the docs, so 'tools' is the submodule which apparently does the job:

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

#This generates the traces for the subplots:

trace1 = pol_part_corr_1.corr().iplot(kind='heatmap',colorscale="Reds")
trace2 = pol_part_corr_2.corr().iplot(kind='heatmap',colorscale="Reds")

#Create the plot matrix:
fig = tools.make_subplots(rows=2, cols=1)

#Add traces, in this case is a hitmap so the method used is 'add_traces', for other plots it might be 'append_trace'.

fig.add_traces(trace1)
fig.add_traces(trace2)

fig['layout'].update(height=600, width=600, title='PARTICLES CORRELATION')
py.plot(fig, filename='subplots-shared-xaxes')