简体   繁体   中英

Plotly Heatmap Show only the image and save it

Firstly I checked this post 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)

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: 在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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