1

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: enter image description here

rpanai
  • 12,515
  • 2
  • 42
  • 64
  • Do you mind to provide a [mcve](/help/mcve) in particular sharing a sample of the data you want to plot. – rpanai Jun 04 '20 at 19:34
  • I need to collect the heatmaps from wav files as an input for Convolutional neural networks... I could only make it with matplotlib.pyplot not with plotly :/ The code for matplotlib heatmaps was found here https://stackoverflow.com/questions/47147146/save-an-image-only-content-without-axes-or-anything-else-to-a-file-using-matl – hellfireworld Jun 04 '20 at 19:51
  • I just need the parameters to disable the axis and the colorbar and collect only the image content! @rpanai i updated the post – hellfireworld Jun 04 '20 at 20:01

1 Answers1

2

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.

rpanai
  • 12,515
  • 2
  • 42
  • 64
  • Yes thank you very much :D I couldn't find `showscale=False and xaxis_showticklabels=False, yaxis_showticklabels=False` ! – hellfireworld Jun 04 '20 at 20:46
  • we forgot something very important this does the job but there is a white border behind the picture, is there a way to get rid of it, it's very important to have only the image? – hellfireworld Jun 04 '20 at 20:54
  • Do you mean when you save as image? – rpanai Jun 04 '20 at 20:56
  • Yes, because we removed all the other features axis and bars the background is still white we need only the picture! – hellfireworld Jun 04 '20 at 20:57
  • Also you applied a nice filter called Viridis because I need to have the values of the FFT on the spectrogram/heatmap will viridis filter will lose info of the wav signal or it is still ok? – hellfireworld Jun 04 '20 at 21:00
  • You can make it transparent following this [answer](https://stackoverflow.com/a/29969848/4819376) – rpanai Jun 04 '20 at 21:00
  • regarding the colorscale it's going to be ok. – rpanai Jun 04 '20 at 21:01
  • Updated. You can now get rid of margins. – rpanai Jun 04 '20 at 21:05
  • I applied the solution you sent from the link but it's not working good with iplot it still has white border and I try to save the file..with plotly.orca it is raising an error... let's try your other solution! – hellfireworld Jun 04 '20 at 21:20