MCPcopy Index your code
hub / github.com/plotly/plotly.py / plotly_restyle

Method plotly_restyle

plotly/basedatatypes.py:1641–1708  ·  view source on GitHub ↗

Perform a Plotly restyle operation on the figure's traces Parameters ---------- restyle_data : dict Dict of trace style updates. Keys are strings that specify the properties to be updated. Nested properties are expressed by joini

(self, restyle_data, trace_indexes=None, **kwargs)

Source from the content-addressed store, hash-verified

1639 # Restyle
1640 # -------
1641 def plotly_restyle(self, restyle_data, trace_indexes=None, **kwargs):
1642 """
1643 Perform a Plotly restyle operation on the figure's traces
1644
1645 Parameters
1646 ----------
1647 restyle_data : dict
1648 Dict of trace style updates.
1649
1650 Keys are strings that specify the properties to be updated.
1651 Nested properties are expressed by joining successive keys on
1652 '.' characters (e.g. 'marker.color').
1653
1654 Values may be scalars or lists. When values are scalars,
1655 that scalar value is applied to all traces specified by the
1656 `trace_indexes` parameter. When values are lists,
1657 the restyle operation will cycle through the elements
1658 of the list as it cycles through the traces specified by the
1659 `trace_indexes` parameter.
1660
1661 Caution: To use plotly_restyle to update a list property (e.g.
1662 the `x` property of the scatter trace), the property value
1663 should be a scalar list containing the list to update with. For
1664 example, the following command would be used to update the 'x'
1665 property of the first trace to the list [1, 2, 3]
1666
1667 >>> import plotly.graph_objects as go
1668 >>> fig = go.Figure(go.Scatter(x=[2, 4, 6]))
1669 >>> fig.plotly_restyle({'x': [[1, 2, 3]]}, 0)
1670
1671 trace_indexes : int or list of int
1672 Trace index, or list of trace indexes, that the restyle operation
1673 applies to. Defaults to all trace indexes.
1674
1675 Returns
1676 -------
1677 None
1678 """
1679
1680 # Normalize trace indexes
1681 # -----------------------
1682 trace_indexes = self._normalize_trace_indexes(trace_indexes)
1683
1684 # Handle source_view_id
1685 # ---------------------
1686 # If not None, the source_view_id is the UID of the frontend
1687 # Plotly.js view that initially triggered this restyle operation
1688 # (e.g. the user clicked on the legend to hide a trace). We pass
1689 # this UID along so that the frontend views can determine whether
1690 # they need to apply the restyle operation on themselves.
1691 source_view_id = kwargs.get("source_view_id", None)
1692
1693 # Perform restyle on trace dicts
1694 # ------------------------------
1695 restyle_changes = self._perform_plotly_restyle(restyle_data, trace_indexes)
1696 if restyle_changes:
1697 # The restyle operation resulted in a change to some trace
1698 # properties, so we dispatch change callbacks and send the

Calls 5

_send_restyle_msgMethod · 0.95
getMethod · 0.45