Hello,
I have a problem when I try to return a scatter plot from a function. I plot 3 scatters plots in jupyter notebook and I write specifically the three in one cell I have no issue to have the selection synchronised among all of them.
But when I write every figure as the output of a function and then I try to use the gridplot I have the result with the three plots but not the linked behaviour. How to force the synchronisation?
Function
def volcanoplot(df, x, y, category_a, category_b, title='Volcano Plot', logy=True):
df = df.copy().dropna()
if logy==True:
df['log_y'] = np.log10(df[y]) * -1
y = 'log_y'
#Legend
df[category_a] = df[category_a].astype(str)
df[category_b] = df[category_b].astype(str)
Col = ['True', 'False']
Mar = ['circle_x', 'triangle']
tooltips = """
<div style="width:200px;">
<b>@mgi_symbol</b> </br>
$x </br>
@description
</div>
"""
TOOLS = "crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select"
source = ColumnDataSource(df)
p = figure(title=title, tools=TOOLS, tooltips=tooltips, height= 500, width=500, output_backend="webgl")
p.scatter(x=x, y=y,
source=source,
size=10,
fill_alpha=0.4,
legend=category_a,
marker=factor_mark(category_b, Mar, Col),
color=factor_cmap(category_a, 'Category10_3', Col))
p.legend.title = category_a
p.yaxis.axis_label = '-log10\(FDR\)'
p.xaxis.axis_label = 'log2 FC'
limit_x_a = Span(location=-1,
dimension='height', line_color='red',
line_dash='dashed', line_width=1)
p.add_layout(limit_x_a)
limit_x_b = Span(location=1,
dimension='height', line_color='red',
line_dash='dashed', line_width=1)
p.add_layout(limit_x_b)
limit_y = Span(location=np.log10(0.01) * -1,
dimension='width', line_color='red',
line_dash='dashed', line_width=1)
p.add_layout(limit_y)
return p
Cell.
v1 = volcanoplot(sakers_df, 'a', 'b', 'c', 'd')
v2 = volcanoplot(sakers_df, 'a', 'b', 'c', 'd')
v3 = volcanoplot(sakers_df, 'a', 'b', 'c', 'd')
v = gridplot([[v1, v2, v3]])
show(v)
Thanks!