{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Overview\n", "This notebook will contain a running set of examples of backward compatibility considerations." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Imports\n", "from plotly.offline import init_notebook_mode, plot, iplot\n", "import plotly.graph_objs as go\n", "\n", "# Initialize notebook mode (Needed by iplot)\n", "init_notebook_mode(connected=True)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'file:///Users/adamkulidjian/Desktop/Adam/plotly/plotly.py/specs/ipyplotly_integration/exports/tmp.html'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# The graph_obj constructors (inluding Figure) are now pretty compatible with legacy code\n", "fig = go.Figure([go.Scatter(x=[1, 2, 3], y=[3, 1, 6], marker=go.scatter.Marker(color='green'))])\n", "plot(fig, filename='exports/tmp.html')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/graph_objs/_deprecations.py:426: DeprecationWarning:\n", "\n", "plotly.graph_objs.Marker is deprecated.\n", "Please replace it with one of the following more specific types\n", " - plotly.graph_objs.scatter.Marker\n", " - plotly.graph_objs.histogram.selected.Marker\n", " - etc.\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "marker": { "color": "green" }, "type": "scatter", "uid": "83f88c0c-7589-11e8-857f-c869cda04ed6", "x": [ 1, 2, 3 ], "y": [ 3, 1, 6 ] } ], "layout": {} }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "iplot(fig)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "89e3be80b4bc48b5bda9115d75bb90db", "version_major": 2, "version_minor": 0 }, "text/html": [ "Failed to display Jupyter Widget of type FigureWidget.
\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "
\n", "\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "
\n" ], "text/plain": [ "FigureWidget()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Instead of using iplot, we can construct a FigureWidget and it will be displayed in the notebook automatically\n", "fig_widget = go.FigureWidget([go.Scatter(x=[1, 2, 3], y=[3, 1, 6], marker=go.Marker(color='green'))])\n", "fig_widget" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Now we can update x-axis range in-place and see the updates reflected in the already displayed figure above\n", "fig_widget.layout.xaxis.range = [0, 5]" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Trace properties can be modified in place as well\n", "scatt = fig_widget.data[0]\n", "scatt.line.dash = 'longdash'" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "\n Invalid value of type 'builtins.str' received for the 'mode' property of trace.scatter\n Received value: 'marker'\n\n The 'mode' property is a flaglist and may be specified as a string containing:\n - Any combination of ['lines', 'markers', 'text'] joined with '+' characters (e.g. 'lines+markers')\n OR exactly one of ['none'] (e.g. 'none')\n", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m