from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
init_notebook_mode(connected=True)
import numpy as np
tr1=dict(type='scatter',
x=np.random.uniform(0,30, size=40),
y=np.random.uniform(0,10, size=40),
mode='markers',
xaxis='x1',
yaxis='y1')
tr2=dict(type='scatter',
x=np.random.uniform(0,30, size=40),
y=np.random.uniform(0,10, size=40),
mode='markers',
xaxis='x2',
yaxis='y1')
barcolor='rgb(170,170,170)'
gridcolor='rgb(255,255,255)'
anno_fontcolor='rgb(50,50,50)'
domain_x=[[0, 0.494], [0.506, 1.]]
layout=dict(width=600, height=400,
autosize=False,
plot_bgcolor='rgb(230,230,230)',
showlegend=False,
hovermode='closest',
xaxis1=dict (anchor='y1',
domain=domain_x[0],
gridcolor= gridcolor,
gridwidth= 1,
zeroline= False
),
xaxis2=dict (anchor='free',
domain= domain_x[1],
gridcolor=gridcolor,
gridwidth= 1,
zeroline= False
),
yaxis1= dict(anchor= "x1",
domain= [0.0, 1.0],
gridcolor= gridcolor,
gridwidth=1,
title= "y_title",
zeroline= False
),
shapes=[ # filled rectangles
dict(
type= 'rect',
xref='paper',
yref='paper',
layer='below',
x0=0,
y0=1,
x1=domain_x[0][1],
y1=1.078,
fillcolor=barcolor,
line=dict(color=barcolor,
width=1,
)
),
dict(type= 'rect',
xref='paper',
yref='paper',
layer='below',
x0=domain_x[1][0],
y0=1,
x1=domain_x[1][1],
y1=1.078,
fillcolor=barcolor,
line=dict(color=barcolor,
width=1,
)
)
],
annotations= [dict(x= 0.5*(domain_x[0][0]+domain_x[0][1]),
y= 1.08, #THIS VALUE is ABOVE the grey BAR that extends between [1, 1.078]
bgcolor=barcolor,
bordercolor=barcolor,
font=dict(color=anno_fontcolor,
size=11
),
showarrow= False,
text='Female',
xanchor= 'center',
xref= 'paper',
yref= 'paper'
),
dict(x= 0.5*(domain_x[1][0]+domain_x[1][1]),
y= 1.08,
bgcolor=barcolor,
bordercolor=barcolor,
font=dict(color=anno_fontcolor,
size=11
),
showarrow= False,
text='Male',
xanchor= 'center',
xref= 'paper',
yref= 'paper'
),
dict(x= 0.5,
y= -0.25,
showarrow= False,
text='Age',
xanchor= 'center',
xref= 'paper',
yref= 'paper'
)
]
)
fig=dict(data=[tr1,tr2], layout=layout)
iplot(fig)