簡體   English   中英

Plotly 熱圖 僅顯示圖像並保存

[英]Plotly Heatmap Show only the image and save it

首先我檢查了這篇文章https://github.com/plotly/plotly.py/issues/1736

但是我無法從我的熱圖中禁用所有內容,所以如果我想刪除所有內容並只保留圖像我能做什么,我需要設置哪些額外的參數? 我正在使用 google colab notebook,我在我的 Python 代碼中嘗試了一些東西 I plot 與 iplot ...在 iplot 之前,我需要使用 plotly-orca 保存文件。(基本上我需要刪除 x_axis 數字、y_axis 數字和 color_bar在右側)

import scipy.io.wavfile as wavfile
import plotly
import plotly.graph_objs as go
[Fs, s] = wavfile.read('wavfile.wav')
# here there is a function that exports the data for the heatmap
layout = go.Layout(xaxis_showgrid=False, yaxis_showgrid=False, xaxis_zeroline=False, yaxis_zeroline=False)
...
heatmap = go.Heatmap(z=S, y=f, x=t)
figure = go.Figure(data=[heatmap],layout=layout)
figure.write_image(str(name)+'.png')

figure = {'data': [heatmap],
          'layout': {'xaxis_showgrid':False,
                     'yaxis_showgrid':False, 
                     'xaxis_zeroline':False, 
                     'yaxis_zeroline':False}}
iplot(figure)

這是 plot,右側有軸和條: 在此處輸入圖像描述

您是否正在尋找類似以下的內容?

import numpy as np
import plotly.graph_objs as go
matrix = np.random.randn(10, 10)
ticks = ["tick %i" % i for i in range(10)]
trace = go.Heatmap(z=matrix,
                   x=ticks,
                   y=ticks,
                   colorscale='Viridis',
                   showscale=False)

layout = dict(xaxis_showgrid=False,
              xaxis_zeroline=False,
              xaxis_showticklabels=False,
              yaxis_showgrid=False, 
              yaxis_zeroline=False,
              yaxis_showticklabels=False)

fig = go.Figure(data=trace, layout=layout)
fig.show()

更新

如果您想擺脫邊距,可以將margin=dict(t=0,b=0,l=0,r=0)添加到布局中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM