本文整理汇总了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 ############# #
示例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)
示例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