Skip to content

Interactive scatter plots #253

@falexwolf

Description

@falexwolf

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 #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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions