Ribbon Plots in Python/v3

How to make ribbon plots in Python.

Note: this page is part of the documentation for version 3 of Plotly.py, which is not the most recent version.
See our Version 4 Migration Guide for information about how to upgrade.

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!

Basic Ribbon Plot

In [2]:
import plotly.plotly as py
import plotly.graph_objs as go

import urllib
import numpy as np

url = "https://raw.githubusercontent.com/plotly/datasets/master/spectral.csv"
f = urllib.urlopen(url)
spectra=np.loadtxt(f, delimiter=',')

traces = []
y_raw = spectra[:, 0] # wavelength
sample_size = spectra.shape[1]-1
for i in range(1, sample_size):
    z_raw = spectra[:, i]
    x = []
    y = []
    z = []
    ci = int(255/sample_size*i) # ci = "color index"
    for j in range(0, len(z_raw)):
        z.append([z_raw[j], z_raw[j]])
        y.append([y_raw[j], y_raw[j]])
        x.append([i*2, i*2+1])
        colorscale=[ [i, 'rgb(%d,%d,255)'%(ci, ci)] for i in np.arange(0,1.1,0.1) ],

fig = { 'data':traces, 'layout':{'title':'Ribbon Plot'} }
py.iplot(fig, filename='ribbon-plot-python')


See https://plotly.com/python/reference/#surface for more information and chart attribute options!