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 = [
    go.Contour(
        z=A,
    x=n,
    y=k,
    colorscale='plasma',
    scaleratio = 0,
    ),
]
py.iplot(data, filename='Absorption Contour')

But the graph I get looks like this;

https://plot.ly/~luka.j.v/18.embed

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.

@luka.j.v

  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 https://plot.ly/python/reference
    and choose from the left menu the corresponding trace to see its attributes.

  2. Plotly has no β€˜plasma’ colorscale. Here https://github.com/plotly/plotly.py/blob/f52c5dbaa8c0084f2ada5e444aecbcd321db30db/plotly/colors.py 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 matplotlib.cm as cm

def mpl_to_plotly(cmap, pl_entries):
    h=1.0/(pl_entries-1)
    pl_colorscale=[]
    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