VincFort
VincFort

Reputation: 1180

Plotly contour plot colour scale granularity not matching custom colorscale

I am trying to create a contour plot with colours from black at a value of -1 to light grey at 0 to red at a value of 1.

I created a custom colorscale that looks like this, where I specified colours for each increment of 0.1 (20 increments from -1 to 1)

[ # Black -> Light grey
        [0, 'rgb(0, 0, 0)'],[0.05, 'rgb(0, 0, 0)'],
        [0.05, 'rgb(20, 20, 20)'],[0.1, 'rgb(20, 20, 20)'],
        [0.1, 'rgb(40, 40, 40)'],[0.15, 'rgb(40, 40, 40)'],
        [0.15, 'rgb(60, 60, 60)'],[0.2, 'rgb(60, 60, 60)'],
        ...
        [0.4, 'rgb(160, 160, 160)'],[0.45, 'rgb(160, 160, 160)'],
        [0.45, 'rgb(180, 180, 180)'],[0.5, 'rgb(180, 180, 180)'],
         # Ligt Grey -> Red
        [0.5, 'rgb(187, 162, 162)'],[0.55, 'rgb(187, 162, 162)'],
        [0.55, 'rgb(194, 144, 144)'],[0.6, 'rgb(194, 144, 144)'],
        [0.6, 'rgb(201, 126, 126)'],[0.65, 'rgb(201, 126, 126)'],
        ...
        [0.9, 'rgb(243, 18, 18)'],[0.95, 'rgb(243, 18, 18)'],
        [0.95, 'rgb(255, 0, 0)'],[1, 'rgb(255, 0, 0)']]

However, when I output the plot, my colorscale has increments of 0.2 and so it seems that not all of the colours I specified are shown. Here is what I get

enter image description here

This is part of the code to display plot, I am not sure what would be needed to have more information.

data = [go.Contour(z=df.values.tolist(),x=list(df.columns),y=list(df.index),colorscale = colScale,zmin=-1,zmax=1)]
fig = go.Figure(data=data,layout=layout)
py.iplot(fig,contours= contour,filename='contPlot'+column)

I am looking for a way to have more colors displayed. Is there a way to display how many "splits" you want in the colour scale where it will interpolate between colours that have been specified ? Thanks

Upvotes: 0

Views: 853

Answers (2)

vlizana
vlizana

Reputation: 3242

Those are parameters related to the contours attribute:

go.Contour(
    z=df.values.tolist(),
    x=list(df.columns),
    y=list(df.index),
    colorscale=colScale,
    contours=dict(
        size=0.1,
        start=-1,
        end=1
    )
)

also you don't need to graduate the color scale yourself, you should only use the base colors:

[
  [0, 'rgb(0, 0, 0)'],[0.5, 'rgb(187, 162, 162)'],
  [0.5, 'rgb(187, 162, 162)'],[1, 'rgb(255, 0, 0)']
]

Upvotes: 1

VincFort
VincFort

Reputation: 1180

I finally used ncontours to change the number of colour in the colour scale.

data = go.Contour(
    z=df.values.tolist(),
    x=list(df.columns),
    y=list(df.index),
    colorscale = colScale,
    zmin=-1,
    zmax=1,
    ncontours=25)

Upvotes: 1

Related Questions