|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "#### Basic Ribbon Plot" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": 1, |
| 13 | + "metadata": { |
| 14 | + "collapsed": false |
| 15 | + }, |
| 16 | + "outputs": [ |
| 17 | + { |
| 18 | + "data": { |
| 19 | + "text/html": [ |
| 20 | + "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~demo_account/28.embed\" height=\"525px\" width=\"100%\"></iframe>" |
| 21 | + ], |
| 22 | + "text/plain": [ |
| 23 | + "<plotly.tools.PlotlyDisplay object>" |
| 24 | + ] |
| 25 | + }, |
| 26 | + "execution_count": 1, |
| 27 | + "metadata": {}, |
| 28 | + "output_type": "execute_result" |
| 29 | + } |
| 30 | + ], |
| 31 | + "source": [ |
| 32 | + "import plotly.plotly as py\n", |
| 33 | + "import plotly.graph_objs as go\n", |
| 34 | + "import urllib\n", |
| 35 | + "\n", |
| 36 | + "import numpy as np\n", |
| 37 | + "\n", |
| 38 | + "url = \"https://raw.githubusercontent.com/plotly/datasets/master/spectral.csv\"\n", |
| 39 | + "f = urllib.urlopen(url)\n", |
| 40 | + "spectra=np.loadtxt(f, delimiter=',')\n", |
| 41 | + "\n", |
| 42 | + "traces = []\n", |
| 43 | + "y_raw = spectra[:, 0] # wavelength\n", |
| 44 | + "sample_size = spectra.shape[1]-1 \n", |
| 45 | + "for i in range(1, sample_size):\n", |
| 46 | + " z_raw = spectra[:, i]\n", |
| 47 | + " x = []\n", |
| 48 | + " y = []\n", |
| 49 | + " z = []\n", |
| 50 | + " ci = int(255/sample_size*i) # ci = \"color index\"\n", |
| 51 | + " for j in range(0, len(z_raw)):\n", |
| 52 | + " z.append([z_raw[j], z_raw[j]])\n", |
| 53 | + " y.append([y_raw[j], y_raw[j]])\n", |
| 54 | + " x.append([i*2, i*2+1])\n", |
| 55 | + " traces.append(dict(\n", |
| 56 | + " z=z,\n", |
| 57 | + " x=x,\n", |
| 58 | + " y=y,\n", |
| 59 | + " colorscale=[ [i, 'rgb(%d,%d,255)'%(ci, ci)] for i in np.arange(0,1.1,0.1) ],\n", |
| 60 | + " showscale=False,\n", |
| 61 | + " type='surface',\n", |
| 62 | + " ))\n", |
| 63 | + "\n", |
| 64 | + "fig = { 'data':traces, 'layout':{'title':'Ribbon Plot'} }\n", |
| 65 | + "py.iplot(fig, filename='ribbon-plot-python')" |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "cell_type": "markdown", |
| 70 | + "metadata": {}, |
| 71 | + "source": [ |
| 72 | + "#### Reference" |
| 73 | + ] |
| 74 | + }, |
| 75 | + { |
| 76 | + "cell_type": "markdown", |
| 77 | + "metadata": {}, |
| 78 | + "source": [ |
| 79 | + "See https://plot.ly/python/reference/ for more information!" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": 2, |
| 85 | + "metadata": { |
| 86 | + "collapsed": false |
| 87 | + }, |
| 88 | + "outputs": [ |
| 89 | + { |
| 90 | + "data": { |
| 91 | + "text/html": [ |
| 92 | + "<link href=\"//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700\" rel=\"stylesheet\" type=\"text/css\" />" |
| 93 | + ], |
| 94 | + "text/plain": [ |
| 95 | + "<IPython.core.display.HTML object>" |
| 96 | + ] |
| 97 | + }, |
| 98 | + "metadata": {}, |
| 99 | + "output_type": "display_data" |
| 100 | + }, |
| 101 | + { |
| 102 | + "data": { |
| 103 | + "text/html": [ |
| 104 | + "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css\">" |
| 105 | + ], |
| 106 | + "text/plain": [ |
| 107 | + "<IPython.core.display.HTML object>" |
| 108 | + ] |
| 109 | + }, |
| 110 | + "metadata": {}, |
| 111 | + "output_type": "display_data" |
| 112 | + }, |
| 113 | + { |
| 114 | + "name": "stdout", |
| 115 | + "output_type": "stream", |
| 116 | + "text": [ |
| 117 | + "Collecting git+https://github.com/plotly/publisher.git\n", |
| 118 | + " Cloning https://github.com/plotly/publisher.git to /var/folders/j3/gt_q6y096cjfts4q8zq2dm2c0000gn/T/pip-mVwKTQ-build\n", |
| 119 | + "Installing collected packages: publisher\n", |
| 120 | + " Found existing installation: publisher 0.10\n", |
| 121 | + " Uninstalling publisher-0.10:\n", |
| 122 | + " Successfully uninstalled publisher-0.10\n", |
| 123 | + " Running setup.py install for publisher\n", |
| 124 | + "Successfully installed publisher-0.10\n" |
| 125 | + ] |
| 126 | + } |
| 127 | + ], |
| 128 | + "source": [ |
| 129 | + "from IPython.display import display, HTML\n", |
| 130 | + "\n", |
| 131 | + "display(HTML('<link href=\"//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700\" rel=\"stylesheet\" type=\"text/css\" />'))\n", |
| 132 | + "display(HTML('<link rel=\"stylesheet\" type=\"text/css\" href=\"http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css\">'))\n", |
| 133 | + "\n", |
| 134 | + "! pip install git+https://github.com/plotly/publisher.git --upgrade\n", |
| 135 | + "import publisher\n", |
| 136 | + "publisher.publish(\n", |
| 137 | + " 'ribbon.ipynb', 'python/ribbon-plots/', 'Python Ribbon Plots | plotly',\n", |
| 138 | + " 'How to make ribbon plots in Python. ',\n", |
| 139 | + " title = 'Python Ribbon Plots | plotly',\n", |
| 140 | + " name = 'Ribbon Plots',\n", |
| 141 | + " has_thumbnail='true', thumbnail='thumbnail/ribbon-plot.jpg', \n", |
| 142 | + " language='python', page_type='example_index', \n", |
| 143 | + " display_as='3d_charts', order=5)" |
| 144 | + ] |
| 145 | + }, |
| 146 | + { |
| 147 | + "cell_type": "code", |
| 148 | + "execution_count": null, |
| 149 | + "metadata": { |
| 150 | + "collapsed": true |
| 151 | + }, |
| 152 | + "outputs": [], |
| 153 | + "source": [] |
| 154 | + } |
| 155 | + ], |
| 156 | + "metadata": { |
| 157 | + "kernelspec": { |
| 158 | + "display_name": "Python 2", |
| 159 | + "language": "python", |
| 160 | + "name": "python2" |
| 161 | + }, |
| 162 | + "language_info": { |
| 163 | + "codemirror_mode": { |
| 164 | + "name": "ipython", |
| 165 | + "version": 2 |
| 166 | + }, |
| 167 | + "file_extension": ".py", |
| 168 | + "mimetype": "text/x-python", |
| 169 | + "name": "python", |
| 170 | + "nbconvert_exporter": "python", |
| 171 | + "pygments_lexer": "ipython2", |
| 172 | + "version": "2.7.9" |
| 173 | + } |
| 174 | + }, |
| 175 | + "nbformat": 4, |
| 176 | + "nbformat_minor": 0 |
| 177 | +} |
0 commit comments