简体   繁体   English

Plotly 热图 仅显示图像并保存

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

Firstly I checked this post https://github.com/plotly/plotly.py/issues/1736首先我检查了这篇文章https://github.com/plotly/plotly.py/issues/1736

But I couldn't disable everything from my figure of heatmap, so if I want to remove everything and keep only the image what can I do, what extra parameters do I need to set?但是我无法从我的热图中禁用所有内容,所以如果我想删除所有内容并只保留图像我能做什么,我需要设置哪些额外的参数? I am working on google colab notebook, I tried some things in my Python code I plot with iplot... Before iplot I need to save with plotly-orca the file.(Basically I need to remove x_axis numbers, y_axis numbers and the color_bar on the right)我正在使用 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)

This is the plot with the axis and the bar on the right:这是 plot,右侧有轴和条: 在此处输入图像描述

Are you looking for something like the following?您是否正在寻找类似以下的内容?

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()

Update更新

In case you want to get rid of margin you could add margin=dict(t=0,b=0,l=0,r=0) to layout.如果您想摆脱边距,可以将margin=dict(t=0,b=0,l=0,r=0)添加到布局中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM