{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#### New to Plotly?\n", "Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).\n", "
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/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", "Note: Subplots with multiple chart types (i.e. cartesian and 3D) are available in version 1.12.11+
\n", "Run `pip install plotly --upgrade` to update your Plotly version" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'2.4.1'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly\n", "plotly.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Mixed Subplot" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "\n", "import pandas as pd\n", "\n", "# read in volcano database data\n", "df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/volcano_db.csv')\n", "\n", "# frequency of Country\n", "freq = df\n", "freq = freq.Country.value_counts().reset_index().rename(columns={'index': 'x'})\n", "\n", "# plot(1) top 10 countries by total volcanoes\n", "locations = go.Bar(x=freq['x'][0:10],y=freq['Country'][0:10], marker=dict(color='#CF1020'))\n", "\n", "# read in 3d volcano surface data\n", "df_v = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/volcano.csv')\n", "\n", "# plot(2) 3d surface of volcano\n", "threed = go.Surface(z=df_v.values.tolist(), colorscale='Reds', showscale=False)\n", "\n", "# plot(3) scattergeo map of volcano locations\n", "trace3 = {\n", " \"geo\": \"geo3\", \n", " \"lon\": df['Longitude'],\n", " \"lat\": df['Latitude'],\n", " \"hoverinfo\": 'text',\n", " \"marker\": {\n", " \"size\": 4,\n", " \"opacity\": 0.8,\n", " \"color\": '#CF1020',\n", " \"colorscale\": 'Viridis'\n", " }, \n", " \"mode\": \"markers\", \n", " \"type\": \"scattergeo\"\n", "}\n", "\n", "data = [locations, threed, trace3]\n", "\n", "# control the subplot below using domain in 'geo', 'scene', and 'axis'\n", "layout = {\n", " \"plot_bgcolor\": 'black',\n", " \"paper_bgcolor\": 'black',\n", " \"titlefont\": {\n", " \"size\": 20,\n", " \"family\": \"Raleway\"\n", " },\n", " \"font\": {\n", " \"color\": 'white'\n", " },\n", " \"dragmode\": \"zoom\", \n", " \"geo3\": {\n", " \"domain\": {\n", " \"x\": [0, 0.55], \n", " \"y\": [0, 0.9]\n", " }, \n", " \"lakecolor\": \"rgba(127,205,255,1)\",\n", " \"oceancolor\": \"rgb(6,66,115)\",\n", " \"landcolor\": 'white',\n", " \"projection\": {\"type\": \"orthographic\"}, \n", " \"scope\": \"world\", \n", " \"showlakes\": True,\n", " \"showocean\": True,\n", " \"showland\": True,\n", " \"bgcolor\": 'black'\n", " }, \n", " \"margin\": {\n", " \"r\": 10, \n", " \"t\": 25, \n", " \"b\": 40, \n", " \"l\": 60\n", " }, \n", " \"scene\": {\"domain\": {\n", " \"x\": [0.5, 1], \n", " \"y\": [0, 0.55]\n", " },\n", " \"xaxis\": {\"gridcolor\": 'white'},\n", " \"yaxis\": {\"gridcolor\": 'white'},\n", " \"zaxis\": {\"gridcolor\": 'white'}\n", " }, \n", " \"showlegend\": False, \n", " \"title\": \"
Volcano Database\", \n", " \"xaxis\": {\n", " \"anchor\": \"y\", \n", " \"domain\": [0.6, 0.95]\n", " }, \n", " \"yaxis\": {\n", " \"anchor\": \"x\", \n", " \"domain\": [0.65, 0.95],\n", " \"showgrid\": False\n", " }\n", "}\n", "\n", "annotations = { \"text\": \"Source: NOAA\",\n", " \"showarrow\": False,\n", " \"xref\": \"paper\",\n", " \"yref\": \"paper\",\n", " \"x\": 0,\n", " \"y\": 0}\n", "\n", "layout['annotations'] = [annotations]\n", "\n", "fig = go.Figure(data=data, layout=layout)\n", "py.iplot(fig, filename = \"Mixed Subplots Volcano\")" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "#### Reference\n", "See https://plot.ly/python/reference/ for more information and chart attribute options!" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Python27\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning:\n", "\n", "The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", "\n", "C:\\Python27\\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", " 'mixed-subplots.ipynb', 'python/mixed-subplots/', 'Mixed Subplots',\n", " 'How to make mixed subplots in Python with Plotly.',\n", " title = 'Mixed Subplots | plotly',\n", " name = 'Mixed Subplots',\n", " has_thumbnail='true', thumbnail='thumbnail/mixed_subplot.JPG', \n", " language='python', page_type='example_index',\n", " display_as='multiple_axes', order=5,\n", " ipynb= '~notebook_demo/132')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "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.14" } }, "nbformat": 4, "nbformat_minor": 2 }