#!/usr/bin/env python
# coding: utf-8
# #### New to Plotly?
# Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/).
# You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online).
# We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (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])
traces.append(dict(
z=z,
x=x,
y=y,
colorscale=[ [i, 'rgb(%d,%d,255)'%(ci, ci)] for i in np.arange(0,1.1,0.1) ],
showscale=False,
type='surface',
))
fig = { 'data':traces, 'layout':{'title':'Ribbon Plot'} }
py.iplot(fig, filename='ribbon-plot-python')
# #### Reference
# See https://plotly.com/python/reference/#surface for more information and chart attribute options!
# In[1]:
from IPython.display import display, HTML
display(HTML(''))
display(HTML(''))
get_ipython().system(' pip install git+https://github.com/plotly/publisher.git --upgrade')
import publisher
publisher.publish(
'ribbon.ipynb', 'python/ribbon-plots/', 'Python Ribbon Plots | plotly',
'How to make ribbon plots in Python. ',
title = 'Python Ribbon Plots | plotly',
name = 'Ribbon Plots',
has_thumbnail='true', thumbnail='thumbnail/ribbon-plot.jpg',
language='python',
display_as='3d_charts', order=4,
ipynb= '~notebook_demo/64')
# In[ ]: