# imports
import numpy as np
import pandas as pd
from plotly import tools
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot, plot
init_notebook_mode(connected=True)
# setup some data
density = 25
grid_x1 = np.linspace(-1, 1, density)
grid_x2 = np.linspace(-1, 1, density)
grid2_x1, grid2_x2 = np.meshgrid(grid_x1, grid_x2)
X = {'x1': grid2_x1.flatten(), 'x2': grid2_x2.flatten()}
df = pd.DataFrame(X)
df['sd'] = 1 + 0.5 * df['x1']
df['y'] = df['x1'] - 0.5 * df['x2']
df['lb'] = df['y'] - 1.96 * df['sd']
df['ub'] = df['y'] + 1.96 * df['sd']
# plot
fig = tools.make_subplots(
rows=1,
cols=2,
print_grid=True,
#shared_xaxes=True,
shared_yaxes=False,
horizontal_spacing=0.06,
)
print fig
This is the format of your plot grid: [ (1,1) x1,y1 ] [ (1,2) x2,y2 ] {'data': [], 'layout': {'yaxis1': {'domain': [0.0, 1.0], 'anchor': 'x1'}, 'yaxis2': {'domain': [0.0, 1.0], 'anchor': 'x2'}, 'xaxis2': {'domain': [0.53, 1.0], 'anchor': 'y2'}, 'xaxis1': {'domain': [0.0, 0.47], 'anchor': 'y1'}}}
fig.append_trace(
go.Contour(
z=df['y'].values.reshape((density, density)),
x=grid_x1,
y=grid_x2,
contours=dict(coloring='heatmap'),
ncontours=density,
legendgroup='mean',
showscale=False,
), 1, 1
)
fig.append_trace(
go.Contour(
z=df['sd'].values.reshape((density, density)),
x=grid_x1,
y=grid_x2,
contours=dict(coloring='heatmap'),
ncontours=density,
colorscale='Jet',
legendgroup='sd',
showscale=False,
), 1, 2
)
fig['layout'].update(
xaxis1=dict(title='x1', zeroline=True),
yaxis1=dict(title='x2', zeroline=True),
xaxis2=dict(title='x1', zeroline=True),
#yaxis2=dict(title='x2', zeroline=True),
hovermode='closest',
legend=dict(orientation="h"),
height=500,
width=900
)
iplot(fig)