Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Square Contour Plots

I am quite new to Plotly so bear with me if these are simple questions, the first is that I cannot seem to get square contour plots. My code is the following;

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='Reflection')

data = [
    scaleratio = 0,
py.iplot(data, filename='Absorption Contour')

But the graph I get looks like this;

FYI n and k and both ndarrays with dimensions 31 and A is a ndarray with dimensions (31x31)

Also I can’t seem to change the colours of the plot, as you can see I have tried to use colourscale=‘plasma’ but I am getting the same as the default.


  1. The Plotly contour trace has no attribute scaleratio. Choosing an adequate layout width and height you can adjust the size of plot as you want. When you experiment a new trace just check
    and choose from the left menu the corresponding trace to see its attributes.

  2. Plotly has no ‘plasma’ colorscale. Here you can find the Plotly colors and colorscales.

To convert a matplotlib (like plasma) or cmocean colormap to a Plotly colorscale

use this function:

import cmocean
import numpy as np
import as cm

def mpl_to_plotly(cmap, pl_entries):
    for k in range(pl_entries):
        C=map(np.uint8, np.array(cmap(k*h)[:3])*255)
        pl_colorscale.append([round(k*h,2), 'rgb'+str((C[0], C[1], C[2]))])
return pl_colorscale

plotly_plasma=mpl_to_plotly(cm.plasma, 11)
1 Like