Skip to content

Instantly share code, notes, and snippets.

@flying-sheep

flying-sheep/plot.py

Last active Nov 6, 2018
Embed
What would you like to do?
Plotly python offline click events in notebook
title = 'blah'
iplot(dict(
data=[dict(
type='scatter',
mode='markers',
x=sorted_info.Submission,
y=sorted_info.NSamples,
text=sorted_info.Series.map(lambda s: s.accession),
transforms=[dict(
type='groupby',
groups=sorted_info.Protocol,
)],
)],
layout=dict(
title=title,
hovermode='closest',
width=800,
height=600,
xaxis=dict(title='Submission date', dtick='M12'),
yaxis=dict(title='# Cells', type='log'),
),
), validate=False, show_link=False)
display(Javascript(rf'''
const [cellplot] = Array.from(document.querySelectorAll('.js-plotly-plot'))
.filter(n => n.querySelector('text.gtitle').textContent === '{title}')
cellplot.on('plotly_click', (data) => {{
if (data.points.length > 1) return
const series = data.points[0].text
window.open(`https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=${{series}}`,'_blank')
}})
'''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment