{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": false, "inputHidden": false, "outputHidden": false }, "source": [ "#### New to Plotly?\n", "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/).\n", "
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).\n", "
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Version Check\n", "Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "inputHidden": false, "outputHidden": false }, "outputs": [ { "data": { "text/plain": [ "'2.0.8'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly\n", "plotly.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Basic Carpet Plot" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "inputHidden": false, "outputHidden": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.graph_objs as go\n", "import plotly.plotly as py\n", "\n", "trace1 = go.Carpet(\n", " a = [4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6],\n", " b = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],\n", " y = [2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10],\n", " aaxis = dict(\n", " tickprefix = 'a = ',\n", " ticksuffix = 'm',\n", " smoothing = 1,\n", " minorgridcount = 9\n", " ),\n", " baxis = dict(\n", " tickprefix = 'b = ',\n", " ticksuffix = 'Pa',\n", " smoothing = 1,\n", " minorgridcount = 9\n", " )\n", " )\n", "\n", "data = [trace1]\n", "\n", "fig = go.Figure(data = data)\n", "py.iplot(fig, filename = \"scattercarpet/basic\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add Carpet Scatter Trace" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "inputHidden": false, "outputHidden": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.graph_objs as go\n", "import plotly.plotly as py\n", "\n", "trace1 = go.Carpet(\n", " a = [4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6],\n", " b = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],\n", " y = [2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10],\n", " aaxis = dict(\n", " tickprefix = 'a = ',\n", " ticksuffix = 'm',\n", " smoothing = 1,\n", " minorgridcount = 9\n", " ),\n", " baxis = dict(\n", " tickprefix = 'b = ',\n", " ticksuffix = 'Pa',\n", " smoothing = 1,\n", " minorgridcount = 9\n", " )\n", " )\n", "\n", "trace2 = go.Scattercarpet(\n", " a = [4, 4.5, 5, 6],\n", " b = [2.5, 2.5, 2.5, 2.5],\n", " line = dict(\n", " shape = 'spline',\n", " smoothing = 1,\n", " color = 'blue'\n", " )\n", " )\n", "\n", "data = [trace1,trace2]\n", "\n", "fig = go.Figure(data = data)\n", "py.iplot(fig, filename = \"scattercarpet/add-scattercarpet\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add Multiple Scatter Traces" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "inputHidden": false, "outputHidden": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.graph_objs as go\n", "import plotly.plotly as py\n", "\n", "trace1 = go.Carpet(\n", " a = [0.1,0.2,0.3],\n", " b = [1,2,3],\n", " y = [[1,2.2,3],[1.5,2.7,3.5],[1.7,2.9,3.7]],\n", " cheaterslope = 1,\n", " aaxis = dict(\n", " title = \"a\",\n", " tickmode = \"linear\",\n", " dtick = 0.05\n", " ),\n", " baxis = dict(\n", " title = \"b\",\n", " tickmode = \"linear\",\n", " dtick = 0.05\n", " )\n", ")\n", "\n", "trace2 = go.Scattercarpet(\n", " name = \"b = 1.5\",\n", " a = [0.05, 0.15, 0.25, 0.35],\n", " b = [1.5, 1.5, 1.5, 1.5]\n", ")\n", "\n", "trace3 = go.Scattercarpet(\n", " name = \"b = 2\",\n", " a = [0.05, 0.15, 0.25, 0.35],\n", " b = [2, 2, 2, 2]\n", ")\n", "\n", "trace4 = go.Scattercarpet(\n", " name = \"b = 2.5\",\n", " a = [0.05, 0.15, 0.25, 0.35],\n", " b = [2.5, 2.5, 2.5, 2.5]\n", ")\n", "\n", "trace5 = go.Scattercarpet(\n", " name = \"a = 0.15\",\n", " a = [0.15, 0.15, 0.15, 0.15],\n", " b = [0.5, 1.5, 2.5, 3.5],\n", " line = dict(\n", " smoothing = 1,\n", " shape = \"spline\"\n", " )\n", ")\n", "\n", "trace6 = go.Scattercarpet(\n", " name = \"a = 0.2\",\n", " a = [0.2, 0.2, 0.2, 0.2],\n", " b = [0.5, 1.5, 2.5, 3.5],\n", " line = dict(\n", " smoothing = 1,\n", " shape = \"spline\"\n", " ),\n", " marker = dict(\n", " size = [10, 20, 30, 40],\n", " color = [\"#000\", \"#f00\", \"#ff0\", \"#fff\"]\n", " )\n", ")\n", "\n", "trace7 = go.Scattercarpet(\n", " name = \"a = 0.25\",\n", " a = [0.25, 0.25, 0.25, 0.25],\n", " b = [0.5, 1.5, 2.5, 3.5],\n", " line = dict(\n", " smoothing = 1,\n", " shape = \"spline\"\n", " )\n", ")\n", "\n", "layout = go.Layout(\n", " title = \"scattercarpet extrapolation, clipping, and smoothing\",\n", " hovermode = \"closest\"\n", ")\n", "\n", "data = [trace1,trace2,trace3,trace4,trace5,trace6,trace7]\n", "\n", "fig = go.Figure(data = data, layout = layout)\n", "py.iplot(fig, filename = \"scattercarpet/multiple\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Reference" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "See https://plotly.com/python/reference/#scattercarpet for more information and chart attribute options!" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", " Cloning https://github.com/plotly/publisher.git to c:\\users\\branden\\appdata\\local\\temp\\pip-e86sgrmk-build\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.10\n", " Uninstalling publisher-0.10:\n", " Successfully uninstalled publisher-0.10\n", " Running setup.py install for publisher: started\n", " Running setup.py install for publisher: finished with status 'done'\n", "Successfully installed publisher-0.10\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\Branden\\Anaconda3\\envs\\ipykernel_py2\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning:\n", "\n", "The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead.\n", "\n", "C:\\Users\\Branden\\Anaconda3\\envs\\ipykernel_py2\\lib\\site-packages\\publisher\\publisher.py:53: UserWarning:\n", "\n", "Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", "\n" ] } ], "source": [ "from IPython.display import display, HTML\n", "\n", "display(HTML(''))\n", "display(HTML(''))\n", "\n", "! pip install git+https://github.com/plotly/publisher.git --upgrade\n", "import publisher\n", "publisher.publish(\n", " 'scattercarpet.ipynb', 'python/carpet-scatter/', 'Carpet Scatter Plot',\n", " 'How to make carpet scatter plots in Python with Plotly.',\n", " title = 'Carpet Scatter Plots | Plotly',\n", " has_thumbnail='true', thumbnail='thumbnail/scattercarpet.jpg', \n", " language='python', \n", " # page_type='example_index', // note this is only if you want the tutorial to appear on the main page: plot.ly/python\n", " display_as='scientific', order=28,\n", " ipynb= '~notebook_demo/146')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernel_info": { "name": "python3" }, "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.12" } }, "nbformat": 4, "nbformat_minor": 4 }