plotly.io package

plotly.io.from_json(value, output_type='Figure', skip_invalid=False, engine=None)

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_objects.Figure, ‘Figure’, graph_objects.FigureWidget, ‘FigureWidget’

  • skip_invalid (bool (default False)) – False if invalid figure properties should result in an exception. True if invalid figure properties should be silently ignored.

  • engine (str (default None)) –

    The JSON decoding engine to use. One of:
    • if “json”, parse JSON using built in json module

    • if “orjson”, parse using the faster orjson module, requires the orjson package

    • if “auto” use orjson module if available, otherwise use the json module

    If not specified, the default engine is set to the current value of plotly.io.json.config.default_engine.

Raises

ValueError – if value is not a string, or if skip_invalid=False and value contains invalid figure properties

Returns

Return type

Figure or FigureWidget

plotly.io.full_figure_for_development(fig: Union[dict, plotly.graph_objects._figure.Figure], warn: bool = True, as_dict: bool = False)Union[plotly.graph_objects._figure.Figure, dict]

Compute default values for all attributes not specified in the input figure and returns the output as a “full” figure. This function calls Plotly.js via Kaleido to populate unspecified attributes. This function is intended for interactive use during development to learn more about how Plotly.js computes default values and is not generally necessary or recommended for production use.

Parameters
  • fig – Figure object or dict representing a figure

  • warn (bool) – If False, suppress warnings about not using this in production.

  • as_dict (bool) – If True, output is a dict with some keys that go.Figure can’t parse. If False, output is a go.Figure with unparseable keys skipped.

Returns

The full figure

Return type

plotly.graph_objects.Figure or dict

plotly.io.get_chrome(path: Optional[Union[str, pathlib.Path]] = None)pathlib.Path

Get the path to the Chrome executable for Kaleido. This function is used by the plotly_get_chrome command line utility.

Parameters

path (str or Path or None) – The path to the directory where Chrome should be installed. If None, the default download path will be used.

plotly.io.read_json(file, output_type='Figure', skip_invalid=False, engine=None)

Construct a figure from the JSON contents of a local file or readable Python object.

Note: A figure converted to JSON with one version of Plotly.py may not be compatible with another version.

Parameters
  • file (str or readable) – A string containing the path to a local file or a read-able Python object (e.g. a pathlib.Path object or an open file descriptor)

  • output_type (type or str (default 'Figure')) – The output figure type or type name. One of: graph_objects.Figure, ‘Figure’, graph_objects.FigureWidget, ‘FigureWidget’

  • skip_invalid (bool (default False)) – False if invalid figure properties should result in an exception. True if invalid figure properties should be silently ignored.

  • engine (str (default None)) –

    The JSON decoding engine to use. One of:
    • if “json”, parse JSON using built in json module

    • if “orjson”, parse using the faster orjson module, requires the orjson package

    • if “auto” use orjson module if available, otherwise use the json module

    If not specified, the default engine is set to the current value of plotly.io.json.config.default_engine.

Returns

Return type

Figure or FigureWidget

plotly.io.show(fig, renderer=None, validate=True, **kwargs)

Show a figure using either the default renderer(s) or the renderer(s) specified by the renderer argument

Parameters
  • fig (dict of Figure) – The Figure object or figure dict to display

  • renderer (str or None (default None)) – A string containing the names of one or more registered renderers (separated by ‘+’ characters) or None. If None, then the default renderers specified in plotly.io.renderers.default are used.

  • validate (bool (default True)) – True if the figure should be validated before being shown, False otherwise.

  • width (int or float) – An integer or float that determines the number of pixels wide the plot is. The default is set in plotly.js.

  • height (int or float) – An integer or float specifying the height of the plot in pixels. The default is set in plotly.js.

  • config (dict) – A dict of parameters to configure the figure. The defaults are set in plotly.js.

Returns

Return type

None

plotly.io.to_html(fig, config=None, auto_play=True, include_plotlyjs=True, include_mathjax=False, post_script=None, full_html=True, animation_opts=None, default_width='100%', default_height='100%', validate=True, div_id=None)

Convert a figure to an HTML string representation.

Parameters
  • fig – Figure object or dict representing a figure

  • config (dict or None (default None)) – Plotly.js figure config options

  • auto_play (bool (default=True)) – Whether to automatically start the animation sequence on page load if the figure contains frames. Has no effect if the figure does not contain frames.

  • include_plotlyjs (bool or string (default True)) –

    Specifies how the plotly.js library is included/loaded in the output div string.

    If True, a script tag containing the plotly.js source code (~3MB) is included in the output. HTML files generated with this option are fully self-contained and can be used offline.

    If ‘cdn’, a script tag that references the plotly.js CDN is included in the output. The url used is versioned to match the bundled plotly.js. HTML files generated with this option are about 3MB smaller than those generated with include_plotlyjs=True, but they require an active internet connection in order to load the plotly.js library.

    If ‘directory’, a script tag is included that references an external plotly.min.js bundle that is assumed to reside in the same directory as the HTML file.

    If a string that ends in ‘.js’, a script tag is included that references the specified path. This approach can be used to point the resulting HTML file to an alternative CDN or local bundle.

    If False, no script tag referencing plotly.js is included. This is useful when the resulting div string will be placed inside an HTML document that already loads plotly.js. This option is not advised when full_html=True as it will result in a non-functional html file.

  • include_mathjax (bool or string (default False)) –

    Specifies how the MathJax.js library is included in the output html div string. MathJax is required in order to display labels with LaTeX typesetting.

    If False, no script tag referencing MathJax.js will be included in the output.

    If ‘cdn’, a script tag that references a MathJax CDN location will be included in the output. HTML div strings generated with this option will be able to display LaTeX typesetting as long as internet access is available.

    If a string that ends in ‘.js’, a script tag is included that references the specified path. This approach can be used to point the resulting HTML div string to an alternative CDN.

  • post_script (str or list or None (default None)) – JavaScript snippet(s) to be included in the resulting div just after plot creation. The string(s) may include ‘{plot_id}’ placeholders that will then be replaced by the id of the div element that the plotly.js figure is associated with. One application for this script is to install custom plotly.js event handlers.

  • full_html (bool (default True)) – If True, produce a string containing a complete HTML document starting with an <html> tag. If False, produce a string containing a single <div> element.

  • animation_opts (dict or None (default None)) – dict of custom animation parameters to be passed to the function Plotly.animate in Plotly.js. See https://github.com/plotly/plotly.js/blob/master/src/plots/animation_attributes.js for available options. Has no effect if the figure does not contain frames, or auto_play is False.

  • default_width (number or str (default '100%')) – The default figure width/height to use if the provided figure does not specify its own layout.width/layout.height property. May be specified in pixels as an integer (e.g. 500), or as a css width style string (e.g. ‘500px’, ‘100%’).

  • default_height (number or str (default '100%')) – The default figure width/height to use if the provided figure does not specify its own layout.width/layout.height property. May be specified in pixels as an integer (e.g. 500), or as a css width style string (e.g. ‘500px’, ‘100%’).

  • validate (bool (default True)) – True if the figure should be validated before being converted to JSON, False otherwise.

  • div_id (str (default None)) – If provided, this is the value of the id attribute of the div tag. If None, the id attribute is a UUID.

Returns

Representation of figure as an HTML div string

Return type

str

plotly.io.to_image(fig: Union[dict, plotly.graph_objects._figure.Figure], format: Optional[str] = None, width: Optional[int] = None, height: Optional[int] = None, scale: Optional[Union[int, float]] = None, validate: bool = True, engine: Optional[str] = None)bytes

Convert a figure to a static image bytes string

Parameters
  • fig – Figure object or dict representing a figure

  • format (str or None) –

    The desired image format. One of
    • ’png’

    • ’jpg’ or ‘jpeg’

    • ’webp’

    • ’svg’

    • ’pdf’

    • ’eps’ (deprecated) (Requires the poppler library to be installed and on the PATH)

    If not specified, will default to:
    • plotly.io.defaults.default_format if engine is “kaleido”

    • plotly.io.orca.config.default_format if engine is “orca” (deprecated)

  • width (int or None) –

    The width of the exported image in layout pixels. If the scale property is 1.0, this will also be the width of the exported image in physical pixels.

    If not specified, will default to:
    • plotly.io.defaults.default_width if engine is “kaleido”

    • plotly.io.orca.config.default_width if engine is “orca” (deprecated)

  • height (int or None) –

    The height of the exported image in layout pixels. If the