Interactive scatter plots
@flying-sheep is already working on this.
Since Aug 4, 2026.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 779
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 27
Description
Hi @ivirshup!
We've discussed this in Aptos a couple of months ago. Adding an interactive parameter to all the scatter plots would be really useful for working with notebooks. Would you consider adding that functionality as you have a lot of experience with it? Importantly, it should be based on the restructured plotting code that @fidelram is currently working on in https://github.com/theislab/scanpy/pull/244 (we could move that branch to the scanpy repo?). Hence, this would be for post-Scanpy 1.3 and there is no great hurry.
A solution that takes an AnnData and creates an interactive plot but totally ignores the current way scatter plots are generated and Fidel's restructured way would be what follows below (due to @NDKoehler). Hence, the task is to think about a good way of integrating this with how scatter plots are done in Scanpy (after Fidel's changes).
from bokeh.plotting import figure, show, output_notebook, save#, output_file
from bokeh.models import HoverTool, value, LabelSet, Legend, ColumnDataSource
from bokeh.palettes import viridis
output_notebook()
import matplotlib as mpl
def plot_interactive(data):
colors = [
"#%02x%02x%02x" % (int(r), int(g), int(b)) for r, g, b, _ in 255*mpl.cm.viridis(mpl.colors.Normalize()(data.obs['CCS'].values))
]
source = ColumnDataSource(dict(
x=data.obsm['X_umap'][:,0],
y=data.obsm['X_umap'][:,1],
color=colors,#data.obs['CCS'],
label=data.obs['Charge'],
#msize= p_df['marker_size'],
#topic_key= p_df['clusters'],
#title= p_df[u'Title'],
#content = p_df['Text_Rep']
seq=data.obs['seq'],
ccs=data.obs['CCS'],
charge=data.obs['Charge'],
))
#ax = sc.pl.umap(data, color=['Charge','CCS'])
#sc.pl.umap(data, color=['CCS'], save='ccs')
title = 'T-SNE visualization of sequences'
plot_lda = figure(plot_width=800, plot_height=600,
title=title, tools="pan,wheel_zoom,box_zoom,reset,hover,previewsave",
x_axis_type=None, y_axis_type=None, min_border=1)
plot_lda.scatter(x='x', y='y', legend='label', source=source, color='color',
alpha=0.8, size=5)#'msize', )
# hover tools
hover = plot_lda.select(dict(type=HoverTool))
hover.tooltips = {"content": "Sequence: @seq, CCS: @ccs, Charge: @charge "}
plot_lda.legend.location = "top_left"
show(plot_lda)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.