Is there a way to save metadata along with a plotly json object?

@StephenP
Any trace type has a property meta. Example:

help(go.Heatmap.meta) #or help(go.Histogram.meta), etc

displays:


1
help(go.Contour.meta
2
    )
Help on property:

    Assigns extra meta information associated with this trace that
    can be used in various text attributes. Attributes such as
    trace `name`, graph, axis and colorbar `title.text`, annotation
    `text` `rangeselector`, `updatemenues` and `sliders` `label`
    text all support `meta`. To access the trace `meta` values in
    an attribute in the same trace, simply use `%{meta[i]}` where
    `i` is the index or key of the `meta` item in question. To
    access trace `meta` in layout attributes, use
    `%{data[n[.meta[i]}` where `i` is the index or key of the
    `meta` and `n` is the trace index.
    
    The 'meta' property accepts values of any type
    
    Returns
    -------
    Any|numpy.ndarray

LE: If you don’t intend to use data from meta in setting trace or layout attributes, but just for information, then the better way to define it is as an array of dicts:

import plotly.graph_objects as go

fig=go.Figure(go.Scatter(x=[1,2], y=[3, 1.5], 
                         meta=[{"author": "Stephen P"}, {"team": "Xyz"}]))

fig.to_json(pretty=True)

But you can insert such an information in go.Layout.meta, as well.

1 Like