Reputation: 472
I'm trying to get the cbrewer Reds colormap, which I generated in advance. However, when I try to use it, I still get some default colormap. What am I doing wrong? Here is plot: https://plot.ly/~smirnod1/54/confusion-matrix/
Here is a code example:
import plotly.plotly as py
from plotly.graph_objs import *
py.sign_in('username', 'api_key')
data = Data([
Heatmap(
x=['Not Churned', 'Churned'],
y=['Churned', 'Not Churned'],
z=[[128, 355], [2827, 23]],
autocolorscale=False,
colorscale=[[1, 'rgb(255,245,240)'], [417, 'rgb(254,224,210)'], [834, 'rgb(252,187,161)'], [1250, 'rgb(252,146,114)'], [1667, 'rgb(251,106,74)'], [2083, 'rgb(239,59,44)'], [2500, 'rgb(203,24,29)'], [2916, 'rgb(165,15,21)'], [3333, 'rgb(103,0,13)']],
name='y',
xsrc='smirnod1:55:b1dfa9',
ysrc='smirnod1:55:b2cd71',
zsrc='smirnod1:55:a9af99,9984f6'
)
])
layout = Layout(
barmode='overlay',
height=400,
title='Confusion Matrix',
width=400,
xaxis=XAxis(
title='Predicted value',
titlefont=dict(
color='#7f7f7f',
size=18
)
),
yaxis=YAxis(
title='True Value',
titlefont=dict(
color='#7f7f7f',
size=18
)
)
)
fig = Figure(data=data, layout=layout)
plot_url = py.plot(fig)
Upvotes: 3
Views: 4774
Reputation: 5011
The colorscale domain items must be in scaled coordinates between 0
and 1
.
To control the colorscale domain use zmin
and zmax
.
For example,
data = Data([
Heatmap(
x=['Not Churned', 'Churned'],
y=['Churned', 'Not Churned'],
z=[[128, 355], [2827, 23]],
zmin=1,
zmax=3333,
colorscale=[[0, 'rgb(255,245,240)'], [0.2, 'rgb(254,224,210)'], [0.4, 'rgb(252,187,161)'], [0.5, 'rgb(252,146,114)'], [0.6, 'rgb(251,106,74)'], [0.7, 'rgb(239,59,44)'], [0.8, 'rgb(203,24,29)'], [0.9, 'rgb(165,15,21)'], [1, 'rgb(103,0,13)']],
name='y',
xsrc='smirnod1:55:b1dfa9',
ysrc='smirnod1:55:b2cd71',
zsrc='smirnod1:55:a9af99,9984f6'
)
])
should work.
Upvotes: 4