This notebook will contain a running set of examples of backward compatibility considerations.
# Imports
from plotly.offline import init_notebook_mode, plot, iplot
import plotly.graph_objs as go
# Initialize notebook mode (Needed by iplot)
init_notebook_mode(connected=True)
# The graph_obj constructors (inluding Figure) are now pretty compatible with legacy code
fig = go.Figure([go.Scatter(x=[1, 2, 3], y=[3, 1, 6], marker=go.scatter.Marker(color='green'))])
plot(fig, filename='exports/tmp.html')
'file:///Users/adamkulidjian/Desktop/Adam/plotly/plotly.py/specs/ipyplotly_integration/exports/tmp.html'
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/graph_objs/_deprecations.py:426: DeprecationWarning:
plotly.graph_objs.Marker is deprecated. Please replace it with one of the following more specific types
iplot(fig)
# Instead of using iplot, we can construct a FigureWidget and it will be displayed in the notebook automatically
fig_widget = go.FigureWidget([go.Scatter(x=[1, 2, 3], y=[3, 1, 6], marker=go.Marker(color='green'))])
fig_widget
Failed to display Jupyter Widget of type FigureWidget.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
# Now we can update x-axis range in-place and see the updates reflected in the already displayed figure above
fig_widget.layout.xaxis.range = [0, 5]
# Trace properties can be modified in place as well
scatt = fig_widget.data[0]
scatt.line.dash = 'longdash'
# Detailed value validation is performed on parameters passed to the Figure constructor
# Here we set 'moded to 'marker' instead of 'markers'
go.Figure([go.Scatter(x=[1, 2, 3], y=[3, 1, 6], marker=go.Marker(color='green'), mode='marker')])
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-14-b71738a94b50> in <module>() 1 # Detailed value validation is performed on parameters passed to the Figure constructor 2 # Here we set 'moded to 'marker' instead of 'markers' ----> 3 go.Figure([go.Scatter(x=[1, 2, 3], y=[3, 1, 6], marker=go.Marker(color='green'), mode='marker')]) ~/Programming/PyDataStack/repos/plotly.py/plotly/datatypes/trace/__init__.py in __init__(self, cliponaxis, connectgaps, customdata, customdatasrc, dx, dy, error_x, error_y, fill, fillcolor, hoverinfo, hoverinfosrc, hoverlabel, hoveron, hovertext, hovertextsrc, ids, idssrc, legendgroup, line, marker, mode, name, opacity, r, rsrc, selected, selectedpoints, showlegend, stream, t, text, textfont, textposition, textpositionsrc, textsrc, tsrc, uid, unselected, visible, x, x0, xaxis, xcalendar, xsrc, y, y0, yaxis, ycalendar, ysrc, **kwargs) 26269 self.line = line 26270 self.marker = marker > 26271 self.mode = mode 26272 self.name = name 26273 self.opacity = opacity ~/Programming/PyDataStack/repos/plotly.py/plotly/basedatatypes.py in __setattr__(self, prop, value) 1250 if prop.startswith('_') or hasattr(self, prop): 1251 # Let known properties and private properties through -> 1252 super().__setattr__(prop, value) 1253 else: 1254 # Raise error on unknown public properties ~/Programming/PyDataStack/repos/plotly.py/plotly/datatypes/trace/__init__.py in mode(self, val) 25235 @mode.setter 25236 def mode(self, val): > 25237 self['mode'] = val 25238 25239 # name ~/Programming/PyDataStack/repos/plotly.py/plotly/basedatatypes.py in __setitem__(self, key, value) 1405 else: 1406 # Simple property -> 1407 self._set_prop(key, value) 1408 1409 @property ~/Programming/PyDataStack/repos/plotly.py/plotly/basedatatypes.py in _set_prop(self, prop, val) 1424 1425 validator = self._validators.get(prop) -> 1426 val = validator.validate_coerce(val) 1427 1428 if val is None: ~/Programming/PyDataStack/repos/plotly.py/plotly/basevalidators.py in validate_coerce(self, v) 925 validated_v = self.perform_validate_coerce(v) 926 if validated_v is None: --> 927 self.raise_invalid_val(v) 928 929 v = validated_v ~/Programming/PyDataStack/repos/plotly.py/plotly/basevalidators.py in raise_invalid_val(self, v) 104 typ=type_str(v), 105 v=repr(v), --> 106 vald_clr_desc=self.description())) 107 108 def raise_invalid_elements(self, invalid_els): ValueError: Invalid value of type 'builtins.str' received for the 'mode' property of trace.scatter Received value: 'marker' The 'mode' property is a flaglist and may be specified as a string containing: - Any combination of ['lines', 'markers', 'text'] joined with '+' characters (e.g. 'lines+markers') OR exactly one of ['none'] (e.g. 'none')
# The same validation is performed on property assignment
scatt.mode = 'marker'
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-15-a4e78fce530e> in <module>() 1 # The same validation is performed on property assignment ----> 2 scatt.mode = 'marker' ~/Programming/PyDataStack/repos/plotly.py/plotly/basedatatypes.py in __setattr__(self, prop, value) 1250 if prop.startswith('_') or hasattr(self, prop): 1251 # Let known properties and private properties through -> 1252 super().__setattr__(prop, value) 1253 else: 1254 # Raise error on unknown public properties ~/Programming/PyDataStack/repos/plotly.py/plotly/datatypes/trace/__init__.py in mode(self, val) 25235 @mode.setter 25236 def mode(self, val): > 25237 self['mode'] = val 25238 25239 # name ~/Programming/PyDataStack/repos/plotly.py/plotly/basedatatypes.py in __setitem__(self, key, value) 1405 else: 1406 # Simple property -> 1407 self._set_prop(key, value) 1408 1409 @property ~/Programming/PyDataStack/repos/plotly.py/plotly/basedatatypes.py in _set_prop(self, prop, val) 1424 1425 validator = self._validators.get(prop) -> 1426 val = validator.validate_coerce(val) 1427 1428 if val is None: ~/Programming/PyDataStack/repos/plotly.py/plotly/basevalidators.py in validate_coerce(self, v) 925 validated_v = self.perform_validate_coerce(v) 926 if validated_v is None: --> 927 self.raise_invalid_val(v) 928 929 v = validated_v ~/Programming/PyDataStack/repos/plotly.py/plotly/basevalidators.py in raise_invalid_val(self, v) 104 typ=type_str(v), 105 v=repr(v), --> 106 vald_clr_desc=self.description())) 107 108 def raise_invalid_elements(self, invalid_els): ValueError: Invalid value of type 'builtins.str' received for the 'mode' property of trace.scatter Received value: 'marker' The 'mode' property is a flaglist and may be specified as a string containing: - Any combination of ['lines', 'markers', 'text'] joined with '+' characters (e.g. 'lines+markers') OR exactly one of ['none'] (e.g. 'none')