Construct a figure from a JSON string Parameters ---------- value: str or bytes String or bytes object containing the JSON representation of a figure output_type: type or str (default 'Figure') The output figure type or type name. One of: graph_objs.Fi
(value, output_type="Figure", skip_invalid=False, engine=None)
| 362 | |
| 363 | |
| 364 | def from_json(value, output_type="Figure", skip_invalid=False, engine=None): |
| 365 | """ |
| 366 | Construct a figure from a JSON string |
| 367 | |
| 368 | Parameters |
| 369 | ---------- |
| 370 | value: str or bytes |
| 371 | String or bytes object containing the JSON representation of a figure |
| 372 | |
| 373 | output_type: type or str (default 'Figure') |
| 374 | The output figure type or type name. |
| 375 | One of: graph_objs.Figure, 'Figure', graph_objs.FigureWidget, 'FigureWidget' |
| 376 | |
| 377 | skip_invalid: bool (default False) |
| 378 | False if invalid figure properties should result in an exception. |
| 379 | True if invalid figure properties should be silently ignored. |
| 380 | |
| 381 | engine: str (default None) |
| 382 | The JSON decoding engine to use. One of: |
| 383 | - if "json", parse JSON using built in json module |
| 384 | - if "orjson", parse using the faster orjson module, requires the orjson |
| 385 | package |
| 386 | - if "auto" use orjson module if available, otherwise use the json module |
| 387 | |
| 388 | If not specified, the default engine is set to the current value of |
| 389 | plotly.io.json.config.default_engine. |
| 390 | |
| 391 | Raises |
| 392 | ------ |
| 393 | ValueError |
| 394 | if value is not a string, or if skip_invalid=False and value contains |
| 395 | invalid figure properties |
| 396 | |
| 397 | Returns |
| 398 | ------- |
| 399 | Figure or FigureWidget |
| 400 | """ |
| 401 | |
| 402 | # Decode JSON |
| 403 | # ----------- |
| 404 | fig_dict = from_json_plotly(value, engine=engine) |
| 405 | |
| 406 | # Validate coerce output type |
| 407 | # --------------------------- |
| 408 | cls = validate_coerce_output_type(output_type) |
| 409 | |
| 410 | # Create and return figure |
| 411 | # ------------------------ |
| 412 | fig = cls(fig_dict, skip_invalid=skip_invalid) |
| 413 | return fig |
| 414 | |
| 415 | |
| 416 | def read_json(file, output_type="Figure", skip_invalid=False, engine=None): |
no test coverage detected