Show Sidebar Hide Sidebar

WebGL Text and Annotations in Python

How to add webGL based text labels and annotations to plots in python

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!!

Heatmap with Annotations

In [1]:
import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.figure_factory import create_annotated_heatmap


y = [[i]*n for i in range(12)]
y = [item for sublist in y for item in sublist]

trace = dict(type='heatmap', z=np.random.randint(1, 10,(12, n)), colorscale = 'Viridis')

# Here's the key part - Scattergl text! 

data.append({'type': 'scattergl', 
                    'mode': 'text', 
                    'x': list(range(n))*12,
                    'y': y, 
                    'text': np.random.choice(list('ATGC'), 12*250),
                    'textfont': {
                        'size': 20

steps = [{'args': ['xaxis', {'range': [-0.5 + e, 30.5 + e]}], 'method': 'relayout'} for e in range(n-30)]

sliders = [dict(
    active = 0,
    steps = steps

layout = dict(sliders=sliders)
layout['xaxis'] = {'range': [-0.5, 30.5]}

fig = dict(data=data, layout=layout)

py.iplot(fig, validate=False)


See for more information and chart attribute options!