{ "cells": [ { "cell_type": "markdown", "metadata": {}, "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": [ "### Range of axes" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "import numpy as np\n", "\n", "N = 70\n", "trace1 = go.Mesh3d(x=(70*np.random.randn(N)),\n", " y=(55*np.random.randn(N)),\n", " z=(40*np.random.randn(N)),\n", " opacity=0.5,\n", " color='rgba(244,22,100,0.6)'\n", " )\n", "\n", "layout = go.Layout(\n", " scene = dict(\n", " xaxis = dict(\n", " nticks=4, range = [-100,100],),\n", " yaxis = dict(\n", " nticks=4, range = [-50,100],),\n", " zaxis = dict(\n", " nticks=4, range = [-100,100],),),\n", " width=700,\n", " margin=dict(\n", " r=20, l=10,\n", " b=10, t=10)\n", " )\n", "fig = go.Figure(data=[trace1], layout=layout)\n", "py.iplot(fig, filename='3d-axis-range')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Fixed Ratio Axes" ] }, { "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", "import plotly.tools as tls\n", "import numpy as np\n", "\n", "N = 50\n", "\n", "fig = tls.make_subplots(\n", " rows=2, cols=2,\n", " specs=[\n", " [{'is_3d': True}, {'is_3d': True}],\n", " [{'is_3d': True}, {'is_3d': True}]\n", " ],\n", " print_grid=False\n", ")\n", "for i in [1,2]:\n", " for j in [1,2]:\n", " fig.append_trace(\n", " go.Mesh3d(\n", " x=(60*np.random.randn(N)),\n", " y=(25*np.random.randn(N)),\n", " z=(40*np.random.randn(N)),\n", " opacity=0.5,\n", " ), \n", " row=i, col=j)\n", "\n", "fig['layout'].update(go.Layout(\n", " width=700,\n", " margin=dict(\n", " r=10, l=10,\n", " b=10, t=10)\n", " ))\n", "\n", "# fix the ratio in the top left subplot to be a cube\n", "fig['layout'][].update(go.Layout(\n", " go.layout.Scene(aspectmode='cube')),\n", " \n", "\n", "# manually force the z-axis to appear twice as big as the other two\n", "fig['layout']['scene2'].update(go.layout.Scene(\n", " aspectmode='manual',\n", " aspectratio=go.layout.scene.Aspectratio(\n", " x=1, y=1, z=2\n", " )\n", "))\n", "\n", "# draw axes in proportion to the proportion of their ranges\n", "fig['layout']['scene3'].update(go.layout.Scene(aspectmode='data'))\n", "\n", "# automatically produce something that is well proportioned using 'data' as the default\n", "fig['layout']['scene4'].update(go.layout.Scene(aspectmode='auto'))\n", "\n", "py.iplot(fig, filename='3d-axis-fixed-ratio-axes')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set Axes Title" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "import numpy as np\n", "\n", "N = 50\n", "trace1 = go.Mesh3d(x=(60*np.random.randn(N)),\n", " y=(25*np.random.randn(N)),\n", " z=(40*np.random.randn(N)),\n", " opacity=0.5,\n", " color='yellow'\n", " )\n", "trace2 = go.Mesh3d(x=(70*np.random.randn(N)),\n", " y=(55*np.random.randn(N)),\n", " z=(30*np.random.randn(N)),\n", " opacity=0.5,\n", " color='pink'\n", " )\n", "layout = go.Layout(\n", " scene = dict(\n", " xaxis = dict(\n", " title='X AXIS TITLE'),\n", " yaxis = dict(\n", " title='Y AXIS TITLE'),\n", " zaxis = dict(\n", " title='Z AXIS TITLE'),),\n", " width=700,\n", " margin=dict(\n", " r=20, b=10,\n", " l=10, t=10)\n", " )\n", "fig = go.Figure(data=[trace1,trace2], layout=layout)\n", "py.iplot(fig, filename='3d-axis-titles')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Ticks Formatting" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "import numpy as np\n", "\n", "N = 50\n", "trace1 = go.Mesh3d(x=(60*np.random.randn(N)),\n", " y=(25*np.random.randn(N)),\n", " z=(40*np.random.randn(N)),\n", " opacity=0.5,\n", " color='rgba(100,22,200,0.5)'\n", " )\n", "\n", "layout = go.Layout(\n", " scene = dict(\n", " xaxis = dict(\n", " ticktext= ['TICKS','MESH','PLOTLY','PYTHON'],\n", " tickvals= [0,50,75,-50]),\n", " yaxis = dict(\n", " nticks=5, tickfont=dict(\n", " color='green',\n", " size=12,\n", " family='Old Standard TT, serif',),\n", " ticksuffix='#'),\n", " zaxis = dict(\n", " nticks=4, ticks='outside',\n", " tick0=0, tickwidth=4),),\n", " width=700,\n", " margin=dict(\n", " r=10, l=10,\n", " b=10, t=10)\n", " )\n", "fig = go.Figure(data=[trace1], layout=layout)\n", "py.iplot(fig, filename='3d-axis-tick-formatting')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Background and Grid Color" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "import numpy as np\n", "\n", "N = 50\n", "trace1 = go.Mesh3d(x=(30*np.random.randn(N)),\n", " y=(25*np.random.randn(N)),\n", " z=(30*np.random.randn(N)),\n", " opacity=0.5,)\n", "\n", "\n", "layout = go.Layout(\n", " scene = dict(\n", " xaxis = dict(\n", " backgroundcolor=\"rgb(200, 200, 230)\",\n", " gridcolor=\"rgb(255, 255, 255)\",\n", " showbackground=True,\n", " zerolinecolor=\"rgb(255, 255, 255)\",),\n", " yaxis = dict(\n", " backgroundcolor=\"rgb(230, 200,230)\",\n", " gridcolor=\"rgb(255, 255, 255)\",\n", " showbackground=True,\n", " zerolinecolor=\"rgb(255, 255, 255)\"),\n", " zaxis = dict(\n", " backgroundcolor=\"rgb(230, 230,200)\",\n", " gridcolor=\"rgb(255, 255, 255)\",\n", " showbackground=True,\n", " zerolinecolor=\"rgb(255, 255, 255)\",),),\n", " width=700,\n", " margin=dict(\n", " r=10, l=10,\n", " b=10, t=10)\n", " )\n", "fig = go.Figure(data=[trace1], layout=layout)\n", "py.iplot(fig, filename='3d-axis-background-and-grid-color')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "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 /tmp/pip-req-build-B_WbM3\n", "Building wheels for collected packages: publisher\n", " Running setup.py bdist_wheel for publisher ... \u001b[?25ldone\n", "\u001b[?25h Stored in directory: /tmp/pip-ephem-wheel-cache-iIz9AA/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.11\n", " Uninstalling publisher-0.11:\n", " Successfully uninstalled publisher-0.11\n", "Successfully installed publisher-0.11\n", "\u001b[33mYou are using pip version 10.0.1, however version 18.1 is available.\n", "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\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", " '3d-axes.ipynb', 'python/3d-axes/', 'Axes Formatting in 3d Plots | plotly',\n", " 'How to format axes of 3d plots in Python with Plotly.',\n", " title = 'Format 3d Axes | plotly',\n", " name = '3D Axes',\n", " has_thumbnail='true', thumbnail='thumbnail/3d-axes.png', \n", " language='python', page_type='example_index',\n", " display_as='3d_charts', order=0.101,\n", " ipynb= '~notebook_demo/96') " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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.15rc1" } }, "nbformat": 4, "nbformat_minor": 2 }