Valueerror: the 'type' Property of Scatter Is Read-only

🌟 Introducing plotly.py 3.0.0 🌟

TLDR; You lot can download and install plotly.py iii.0.0 today with pip install plotly (or pip install plotly --upgrade if you've installed the Plotly Python library in the by).

Terminal October, at our New York City Dash Workshops, an attendee showed the states something really special. Jon Mease (@jonmmease), a data scientist and software developer from the Johns Hopkins Practical Physics Laboratory, had spent three months working on a fork of plotly.py, our open up source Python graphing library:

So Jon dug deep into plotly.js and started creating his own Pythonic interface to the library. Information technology started with typeahead support and grew and grew to include first class Jupyter widgets, fast typed arrays, deep effigy validation, offline static image consign, and more. Now, one year subsequently his first commit and nine months after our workshops, we've integrated Jon'due south fork into the official plotly.py library and are excited to denote our biggest release still: plotly.py 3.0.0 🎉

Eager to get started? Download and install plotly.py 3.0.0 today with pip install plotly (or pip install plotly --upgrade if you've installed the Plotly Python library in the past).

Starting time Grade Jupyter Widget Support

3.0.0 introduces a new Jupyter widget class: plotly.graph_objs.FigureWidget

FigureWidget has the same call signature as our existing Figure, and it's fabricated specifically for Jupyter Notebook and JupyterLab environments.

Print the widget, see the figure. Just like every other object in Jupyter. plotly.offline.init_notebook_mode and plotly.offline.iplot are no longer necessary.

This figure widget is synced up with the plotly.js JavaScript figure object, so y'all can access all of the properties of the effigy, including the dynamic default properties that were previously merely available in the JavaScript context.

Introspect all of the default backdrop of the plotly figure. Thanks to the Jupyter widget framework, these properties are accessed direct from the JavaScript context.

This widget is compatible with the rest of the widget framework and has upshot listeners for hovering, clicking, and selecting points and zooming into regions.

Tying together the Plotly FigureWidget with the Text IPywidget to display Walmart Store openings over fourth dimension.

Tying together Plotly and Datashader with the new FigureWidget's "property change" callbacks. Whenever the axes ranges change, the callback gets fired, recomputing the server-rendered image with Datashader. View the source.

An Imperative Alternative

plotly.js graphs are declarative. This means that every aspect of the charts (the colors of the bars, the axes grid lines, the position of annotations) are completely described through a prepare of attributes. This fix of attributes is the "Plotly JSON Chart Schema," and information technology describes every aspect of over 33 nautical chart types (and counting)!

Our interface to this library has ever been declarative. You lot depict what the graph should await like, not how to draw it.

plotly 3.0.0 introduces a set of imperative methods for manipulating and exploring the figure in Jupyter's interactive computing environments. It'due south easier than always to traverse the effigy structure and dispense the graph. The imperative methods are 1-to-one with the declarative attributes, and then it's easy to switch between describing your graph entirely upfront (declarative method) and editing information technology on-the-fly in Jupyter (imperative method).

Interactively editing the attributes of a rendered Plotly `GraphWidget` in Jupyter Notebook.

Tab-Complete Support

With plotly.py, it'due south easier than always to observe the attributes of your graphs without leaving the notebook. plotly.py generates rich Python classes from the chart schema with neat docstrings and perfect tab-consummate support.

For whatever instantiated figure, yous can traverse through all attributes of the effigy and view their full descriptions:

Tab complete all the way down.

And the docstrings are cute. They're pulled straight from the plotly.js schema so when plotly.js updates the underlying source code, plotly.py will automatically get the new doc strings.

          >>> fig.layout.barmode?
Determines how confined at the same location coordinate are
displayed on the graph. With *stack*, the confined are stacked on
superlative of one another With *relative*, the bars are stacked on superlative
of ane another, with negative values below the axis, positive
values above With *group*, the bars are plotted next to one
some other centered around the shared location. With *overlay*,
the confined are plotted over one some other, you might need to an
*opacity* to meet multiple bars.

The 'barmode' property is an enumeration that may be specified equally:
- Ane of the following enumeration values:
['stack', 'group', 'overlay', 'relative']

All of the traces are accessible nether the `add_*` methods of a figure. In Jupyter, blazon shift+tab to pull up the inline-documentation and shift+tab a second time to expand it.

Typeahead too works for the plotly.graph_objs, the pythonic wrappers effectually each of the chart types and groups of nested attributes.

Declarative graph objects with input argument tab consummate, all the way down!

Calling help on these objects displays rich descriptions, all of the bachelor keyword arguments, and descriptions of each statement. Consummate and explicit.

          >>> go.Carpet?          Init signature: go.Carpet(
a=None, a0=None, aaxis=None, asrc=None,
b=None, b0=None, baxis=None, bsrc=None,
carpet=None, cheaterslope=None, color=None,
customdata=None, customdatasrc=None,
da=None, db=None, font=None, hoverinfo=None,
hoverinfosrc=None, hoverlabel=None,
ids=None, idssrc=None, legendgroup=None,
proper name=None, opacity=None, selectedpoints=None,
showlegend=None, stream=None,
uid=None, visible=None, x=None, xaxis=None, xsrc=None,
y=None, yaxis=None, ysrc=None)
Construct a new Carpeting object The data describing carpet centrality layout is prepare in `y` and
(optionally) also `ten`. If but `y` is present, `x` the plot is
interpreted as a cheater plot and is filled in using the `y`
values. `ten` and `y` may either exist second arrays matching with each
dimension matching that of `a` and `b`, or they may exist 1D
arrays with total length equal to that of `a` and `b`.
Parameters
----------
a
An assortment containing values of the outset parameter value
a0
Alternate to `a`. Builds a linear space of a
coordinates. Employ with `da` where `a0` is the starting
coordinate and `da` the step.
aaxis
plotly.graph_objs.carpet.Aaxis instance or dict with
compatible properties
b
A two dimensional array of y coordinates at each carpet
point.
b0
Alternate to `b`. Builds a linear space of a
coordinates. Use with `db` where `b0` is the starting
coordinate and `db` the stride.
baxis
plotly.graph_objs.carpet.Baxis instance or dict with
compatible backdrop
rug
An identifier for this carpet, so that `scattercarpet`
and `scattercontour` traces can specify a carpet plot
on which they lie
cheaterslope
The shift applied to each successive row of data in
creating a cheater plot. Only used if `ten` is been
ommitted.
color
Sets default for all colors associated with this axis
all at once: line, font, tick, and grid colors. Filigree
color is lightened by blending this with the plot
background Individual pieces can override this.
[...]

These nice tab-complete docstrings as well work with traditional code editors like PyCharm:

Deep typeahead aspect documentation across all plotly graph properties in PyCharm.

Deep Validation and Helpful Error Letters

The plotly.js chart schema provides strict types for each attribute. There are 14 information types and plotly.py at present provides strict blazon validators and type-specific exceptions for each of them.

The validators are strict and helpful. For example, they'll raise errors if your strings aren't valid CSS color strings:

          >>> get.scatter.Marking(color='fuschia')          Invalid value of blazon 'builtins.str' received for the 'color' property of scatter.marking
Received value: 'fuschia'
The 'color' property is a color and may be specified as:
- A hex string (due east.m. '#ff0000')
- An rgb/rgba string (e.thou. 'rgb(255,0,0)')
- An hsl/hsla string (eastward.one thousand. 'hsl(0,100%,50%)')
- An hsv/hsva cord (e.g. 'hsv(0,100%,100%)')
- A named CSS color:
aliceblue, antiquewhite, aqua, aquamarine, azure,
biscuit, bisque, black, blanchedalmond, blue,
blueviolet, brown, burlywood, cadetblue,
chartreuse, chocolate, coral, cornflowerblue,
cornsilk, crimson, cyan, darkblue, darkcyan,
darkgoldenrod, darkgray, darkgrey, darkgreen,
darkkhaki, darkmagenta, darkolivegreen, darkorange,
darkorchid, darkred, darksalmon, darkseagreen,
darkslateblue, darkslategray, darkslategrey,
darkturquoise, darkviolet, deeppink, deepskyblue,
dimgray, dimgrey, dodgerblue, firebrick,
floralwhite, forestgreen, fuchsia, gainsboro,
ghostwhite, gold, goldenrod, grayness, gray, light-green,
greenyellow, honeydew, hotpink, indianred, indigo,
ivory, khaki, lavender, lavenderblush, lawngreen,
lemonchiffon, lightblue, lightcoral, lightcyan,
lightgoldenrodyellow, lightgray, lightgrey,
lightgreen, lightpink, lightsalmon, lightseagreen,
lightskyblue, lightslategray, lightslategrey,
lightsteelblue, lightyellow, lime, limegreen,
linen, magenta, maroon, mediumaquamarine,
mediumblue, mediumorchid, mediumpurple,
mediumseagreen, mediumslateblue, mediumspringgreen,
mediumturquoise, mediumvioletred, midnightblue,
mintcream, mistyrose, moccasin, navajowhite, navy,
oldlace, olive, olivedrab, orangish, orangered,
orchid, palegoldenrod, palegreen, paleturquoise,
palevioletred, papayawhip, peachpuff, peru, pink,
plum, powderblue, purple, crimson, rosybrown,
royalblue, saddlebrown, salmon, sandybrown,
seagreen, seashell, sienna, silver, skyblue,
slateblue, slategray, slategrey, snowfall, springgreen,
steelblue, tan, teal, thistle, love apple, turquoise,
violet, wheat, white, whitesmoke, xanthous,
yellowgreen
- A number that will exist interpreted every bit a color
according to scatter.mark.colorscale
- A list or array of any of the above

Or if a number is exterior of the valid range:

          >>> go.scatter.Marking(size=-1)          ValueError:            
Invalid value of type 'builtins.int' received for the 'size' property of scatter.marker
Received value: -one

The 'size' belongings is a number and may exist specified equally:
- An int or float in the interval [0, inf]
- A tuple, list, or one-dimensional numpy array of the above

Or if the cord isn't i of the enumerated values:

          >>> go.Besprinkle(mode='mark')          Invalid value of type 'builtins.str' received for the 'mode' property of besprinkle
Received value: 'marker'
The 'style' property is a flaglist and may be specified
as a cord containing:
- Any combination of ['lines', 'markers', 'text'] joined with '+' characters
(e.g. 'lines+markers')
OR exactly ane of ['none'] (e.chiliad. 'none')

Functioning Improvements

Plotting large data interactively is now faster than ever:

  • plotly.py effigy specifications are now serialized and transferred to plotly.js using the Widget Message Protocol over the Jupyter Comms infrastructure.
  • Thanks to the great work of the ipywidgets team, Python numpy arrays are now transferred into JavaScript TypedArrays without any intermediate UTF-eight encoding. We'd especially similar to thank Maarten Breddels, Sylvain Corlay, and Jason Grout for laying very thoughtful foundations for this. We're continuing on the shoulders of giants!
  • plotly.js provides direct back up for TypedArrays (added in v0.35.0) and information technology provides a super fast WebGL pathway for many trace types.

Plotting 1M points in Jupyter used to take 35 seconds. Now it takes merely three. And the result is a responsive, completely interactive chart. 🚀

Plotting an interactive chart with 1M information points in 1… 2… 3! seconds 🐎

Fast client-side interactivity with 1M scatter points cheers to plotly.js's WebGL renderer.

Context Manager for Animations

Two years ago, we introduced an animation interface in plotly.js. Previously, it's been possible to create animations in plotly.py by defining a set of transitions upwardly-front (frames). Now, in plotly.py 3.0.0, you tin define the animation transitions on-the-fly with a new ContextManager.

For example, here'south how to animate polish transitions of a line chart with ipywidgets.IntSlider.

          def animate_figure(change):
with fig.batch_animate(duration=500):
trace.y = np.sin(ten) * modify['new']
slider.observe(animate_figure, names='value')

Using the animation context manager to provide smooth transitions of updates in plotly.js. plotly.py animations use plotly.js's underlying Plotly.breathing method.

JupyterLab Back up

plotly.py iii.0.0's FigureWidget is completely compatible with the new JupyterLab surround.

Interactive coding in the new JupyterLab environs with the FigureWidget. The FigureWidget is within an output jail cell of a notebook, pulled out equally a separate view in the pane on the right. The `fig.add_histogram2dcontour` method is 1 of the new imperative API interfaces, designed specifically for the interactive Jupyter computing environments.

Static Image Export

plotly.js graphs are rendered with JavaScript in a browser context. In guild to create static images of these charts, without opening a browser, we needed a manner to return the graphs in some type of headless browser.

In May, nosotros open-sourced Orca, a command-line application that generates static images of plotly graphs. Orca has been used in production at Plotly for about nine months, creating images for tens of millions of charts.

Orca is the engineering science for creating static images of Plotly graphs. We're working on bundling Orca as an optional dependency in the official plotly.py package. For at present, follow the instructions in the Orca repository.

Backwards Compatibility

At Plotly, nosotros take backwards compatibility pretty seriously.

Over the last five years of developing plotly.js, we've published over 100 releases, all without a single breaking change to the API.

plotly.py graphs are rendered with plotly.js, so this release does not change the way that your graphs are rendered. The attributes of the graphs remain one-to-one with plotly.js, and so the declarative interface to the figures (data, layout, and all of the nested properties within) has not changed either.

What has changed is the structure of the Python classes that wrap these attributes: plotly.graph_objs ("go"). We're at present placing our nested backdrop, similar become.Marker, in a namespace underneath their parent attribute. That is, get.Marker is now attainable as get.scatter.Marking or go.bar.Marker or whatever trace information technology is nested within. By providing unique objects nether the parent-trace namespace, we tin can provide better validation (the properties for a mark object within a scatter trace may exist different than the backdrop of a marker object inside a bar trace). Although deprecated, the previous objects are still supported, they just won't provide the same level of validation as our new objects.

Of course, yous're not required to employ these college level objects. Yous can nevertheless write your graphs as straight dictionaries and lists. Or, you can mix-and-lucifer. Here are four equivalent representations of a trace:

          # New method
go.Scatter(
x=[ane, 2, three],
y=[iii, i, two],
marker=go.scatter.Marker(color='blue')
)
# Old method - deprecated go.Marker object
go.Scatter(
x=[1, two, 3],
y=[three, 1, two],
mark=go.Marker(color='blue')
)
# Mix-and-lucifer dicts and lists
become.Scatter(
x=[1, 2, 3],
y=[3, 1, 2],
marker={'colour': 'blue'}
)
# Or use primitive types all the way downwards
{
'x': [i, 2, 3],
'y': [3, i, 2],
'type': 'scatter',
'marker': {'color': 'blue'}
}

We take a more detailed certificate in our plotly 3.0.0 migration guide. Please let us know if nosotros've missed anything in a GitHub event!

Looking Forrard and Further Resources

  • iii.0.0 is a major release which means in that location are some breaking changes. Get alee of the release by trying out our release candidate with our migration guide. Questions, problems? Delight make an effect 🙇
  • Jon volition be speaking most v3.0.0 at SciPy 2018 in Austin. If you're at that place, come say hello! 👋
  • Jon also wrote a paper for SciPy 2018 outlining these features and, more technically, the underlying architecture of the code. Bank check out the SciPy abstract online.
  • Can't make information technology to SciPy? Jon will be giving a webinar about plotly.py three.0.0 on July 25. Sign up here.
  • Dash, our open source Python library for standalone analytic apps, uses plotly.py and is uniform with plotly.py v3.0.0.
  • The underlying graphing library that powers plotly.py (and other libraries like Dash) is plotly.js. This library is in agile evolution. View our latest releases on GitHub.
  • More than of an R person? Carson has been making a lot of fantastic improvements in the Plotly R library lately.
  • Follow our latest work with Twitter: @plotlygraphs
  • Much of our open up source work is funded directly from organizations that accept budgets for software. Many thank you to everyone that has supported u.s. so far ❤️. Interested in sponsoring a particular characteristic? Delight get in touch.
  • Plotly, Inc. also provides public, private, and on-premise platforms for publishing graphs, datasets, and interactive Dash applications. More than than half of our revenue straight funds open source libraries like these. Learn more about our commercial products.

Much love —

Squad Plotly

mayesplacceiven.blogspot.com

Source: https://medium.com/plotly/introducing-plotly-py-3-0-0-7bb1333f69c6

0 Response to "Valueerror: the 'type' Property of Scatter Is Read-only"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel