當前位置: 首頁>>代碼示例>>Python>>正文


Python graph_objects.Heatmap方法代碼示例

本文整理匯總了Python中plotly.graph_objects.Heatmap方法的典型用法代碼示例。如果您正苦於以下問題:Python graph_objects.Heatmap方法的具體用法?Python graph_objects.Heatmap怎麽用?Python graph_objects.Heatmap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在plotly.graph_objects的用法示例。


在下文中一共展示了graph_objects.Heatmap方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update_data

# 需要導入模塊: from plotly import graph_objects [as 別名]
# 或者: from plotly.graph_objects import Heatmap [as 別名]
def update_data(self, data):
        """Update the data of the plot efficiently.

        Args:
            data (array_like): Data in any format that can be converted to NumPy.

                Must be of shape (any, `trace_names`).
        """
        data = reshape_fns.to_2d(np.asarray(data))
        checks.assert_same_shape(data, self._trace_names, axis=(1, 0))

        # Update traces
        with self.batch_update():
            for i, box in enumerate(self.data):
                if self._horizontal:
                    box.x = data[:, i]
                    box.y = None
                else:
                    box.x = None
                    box.y = data[:, i]


# ############# Heatmap ############# # 
開發者ID:polakowo,項目名稱:vectorbt,代碼行數:25,代碼來源:basic.py

示例2: __init__

# 需要導入模塊: from plotly import graph_objects [as 別名]
# 或者: from plotly.graph_objects import Heatmap [as 別名]
def __init__(self, x_labels, y_labels, data=None, horizontal=False, trace_kwargs={}, **layout_kwargs):
        """Create an updatable heatmap plot.

        Args:
            x_labels (list of str): X-axis labels, corresponding to columns in pandas.
            y_labels (list of str): Y-axis labels, corresponding to index in pandas.
            data (array_like): Data in any format that can be converted to NumPy.
            horizontal (bool): Plot horizontally.
            trace_kwargs (dict): Keyword arguments passed to `plotly.graph_objects.Heatmap`.
            **layout_kwargs: Keyword arguments for layout.
        Example:
            ```py
            vbt.Heatmap(['a', 'b'], ['x', 'y'], data=[[1, 2], [3, 4]])
            ```
            ![](/vectorbt/docs/img/Heatmap.png)
            """

        self._x_labels = x_labels
        self._y_labels = y_labels
        self._horizontal = horizontal

        super().__init__()
        self.update_layout(**layout_kwargs)

        # Add traces
        heatmap = go.Heatmap(
            hoverongaps=False,
            colorscale='Plasma'
        )
        if self._horizontal:
            heatmap.y = x_labels
            heatmap.x = y_labels
        else:
            heatmap.x = x_labels
            heatmap.y = y_labels
        heatmap.update(**trace_kwargs)
        self.add_trace(heatmap)

        if data is not None:
            self.update_data(data) 
開發者ID:polakowo,項目名稱:vectorbt,代碼行數:42,代碼來源:basic.py

示例3: spy

# 需要導入模塊: from plotly import graph_objects [as 別名]
# 或者: from plotly.graph_objects import Heatmap [as 別名]
def spy(
        matrix,
        show=True,
):
    """
    Plots the sparsity pattern of a matrix.
    :param matrix: The matrix to plot the sparsity pattern of. [2D ndarray or CasADi array]
    :param show: Whether or not to show the sparsity plot. [boolean]
    :return: The figure to be plotted [go.Figure]
    """
    try:
        matrix = matrix.toarray()
    except:
        pass
    abs_m = np.abs(matrix)
    sparsity_pattern = abs_m >= 1e-16
    matrix[sparsity_pattern] = np.log10(abs_m[sparsity_pattern] + 1e-16)
    j_index_map, i_index_map = np.meshgrid(np.arange(matrix.shape[1]), np.arange(matrix.shape[0]))

    i_index = i_index_map[sparsity_pattern]
    j_index = j_index_map[sparsity_pattern]
    val = matrix[sparsity_pattern]
    val = np.ones_like(i_index)
    fig = go.Figure(
        data=go.Heatmap(
            y=i_index,
            x=j_index,
            z=val,
            # type='heatmap',
            colorscale='RdBu',
            showscale=False,
        ),
    )
    fig.update_layout(
        plot_bgcolor="black",
        xaxis=dict(showgrid=False, zeroline=False),
        yaxis=dict(showgrid=False, zeroline=False, autorange="reversed", scaleanchor="x", scaleratio=1),
        width=800,
        height=800 * (matrix.shape[0] / matrix.shape[1]),
    )
    if show:
        fig.show()
    return fig 
開發者ID:peterdsharpe,項目名稱:AeroSandbox,代碼行數:45,代碼來源:visualization.py


注:本文中的plotly.graph_objects.Heatmap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。