{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Linked Matching Axes\n", "Different cartesian axes may now be linked together so that their ranges remain the same across pan and zoom operations" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3.7.0\n" ] }, { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "import plotly\n", "print(plotly.__version__)\n", "\n", "from plotly.offline import init_notebook_mode, iplot\n", "from plotly.tools import make_subplots\n", "init_notebook_mode()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": false }, "data": [ { "type": "scatter", "uid": "f144037d-c8ea-47f7-8043-ee882fcd4a82", "xaxis": "x", "y": [ 2, 3, 1 ], "yaxis": "y" }, { "type": "bar", "uid": "9c29c2dc-ee75-42c1-8285-92696697e199", "xaxis": "x2", "y": [ 2, 1, 3 ], "yaxis": "y2" } ], "layout": { "dragmode": "pan", "title": { "text": "Non-matching axes" }, "xaxis": { "anchor": "y", "domain": [ 0, 0.45 ] }, "xaxis2": { "anchor": "y2", "domain": [ 0.55, 1 ] }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ] }, "yaxis2": { "anchor": "x2", "domain": [ 0, 1 ] } } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = make_subplots(1, 2, print_grid=False)\n", "scatt1 = fig.add_scatter(y=[2, 3, 1], row=1, col=1)\n", "scatt2 = fig.add_bar(y=[2, 1, 3], row=1, col=2)\n", "fig.layout.dragmode = 'pan'\n", "fig.layout.title.text = 'Non-matching axes'\n", "iplot(fig)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": false }, "data": [ { "type": "scatter", "uid": "f144037d-c8ea-47f7-8043-ee882fcd4a82", "xaxis": "x", "y": [ 2, 3, 1 ], "yaxis": "y" }, { "type": "bar", "uid": "9c29c2dc-ee75-42c1-8285-92696697e199", "xaxis": "x2", "y": [ 2, 1, 3 ], "yaxis": "y2" } ], "layout": { "dragmode": "pan", "title": { "text": "Matching axes" }, "xaxis": { "anchor": "y", "domain": [ 0, 0.45 ], "matches": "x2" }, "xaxis2": { "anchor": "y2", "domain": [ 0.55, 1 ] }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "matches": "y2" }, "yaxis2": { "anchor": "x2", "domain": [ 0, 1 ] } } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig.layout.xaxis.matches = 'x2'\n", "fig.layout.yaxis.matches = 'y2' \n", "fig.layout.title.text = 'Matching axes'\n", "iplot(fig)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.2" } }, "nbformat": 4, "nbformat_minor": 2 }