{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plotly shapes\n", "\n", "

" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import plotly.plotly as py" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "gvallverdu306 = py.get_figure('https://plot.ly/~gvallverdu/249/bands-diagram-of-silicon.py')\n", "gvallverdu306['data'] = gvallverdu306['data'][0:8]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### tickmode array" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "gvallverdu306['layout']['xaxis']['tickmode'] = 'array'\n", "gvallverdu306['layout']['xaxis']['showticklabels'] = True\n", "\n", "gvallverdu306['layout']['xaxis']['tickvals'] = [\n", " 0, 20, 40, 60, 80, 120, 140, 159\n", "]\n", "\n", "gvallverdu306['layout']['xaxis']['ticktext'] = [\n", " \"L\", \"Λ\", \"Γ\", \"Δk\",\n", " \"X\", \"K\", \"Σ\", \"Γ\"\n", "]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**N.B.** This is a new plotly feature that hasn't made it into the python-api yet.\n", "\n", "We must turn off validatation in order to use it." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "py.iplot(\n", " gvallverdu306,\n", " validate=False,\n", " filename='tickvals-ticktext'\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Shapes " ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "vals = [0, 20, 40, 60, 80, 120, 140, 159]\n", "\n", "gvallverdu306['layout']['shapes'] = []\n", "\n", "for val in vals:\n", " gvallverdu306['layout']['shapes'].append({\n", " 'type': 'line',\n", " 'xref': 'x',\n", " 'x0': val,\n", " 'x1': val,\n", " 'yref': 'paper',\n", " 'y0': 0,\n", " 'y1': 1,\n", " 'opacity': 0.6 \n", " })" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "py.iplot(\n", " gvallverdu306,\n", " validate=False,\n", " filename='tickvals-ticktext-shapes'\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import display, HTML\n", "import urllib2\n", "url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css'\n", "display(HTML(urllib2.urlopen(url).read()))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }