Iām trying to make a heatmap using different colors for discreet ranges of data, using Plotly in python/pandas. My colleague sent me an image of the color ranges she would like used for the data.
I used the āCustom Discretized Heatmap Colorscaleā example at https://plot.ly/python/colorscales/ but rather than discrete bars, the heatmap has a range of colors.
Here is the script I am using:
def makePlotlyHeatmap(input_df, output_file):
āāāmake a Plotly heatmap from a dataframeāāā
# initialize for offline use
offline.init_notebook_mode(connected=True)
# set layout options
layout = go.Layout(
autosize=True,
height=1200,
width=1200,
margin=go.Margin(
l=500,
r=200,
b=100,
t=100,
pad=4
))
# create heatmap file
heatmap = input_df.iplot(kind='heatmap',
layout=layout,
colors=[
# Let 0-10.0 fold change be white:
[10.0, 'cmyk(0,0,0,0)'],
# Let 10.0-50.0 fold change be orange:
[10.0, 'cmyk(0,61,100,0)'],
[50.0, 'cmyk(0,61,100,0)'],
# Let 50.0-100.0 fold change be red:
[50.0, 'cmyk(88,77,0,0)'],
[100.0, 'cmyk(88,77,0,0)'],
# Let 100.0 and greater fold change be blue:
[100, 'cmyk(24,100,100,22)']],
asFigure=True)
# write heatmap to file
offline.plot(heatmap, filename=output_file, auto_open=True)
makePlotlyHeatmap(df_data, "output.html")
The data frame (df_data) contains a read-in csv.
I have tried ācolorscaleā in place of ācolorsā but that gives the error āAttributeError: ālistā object has no attribute ālowerāā.
Thanks for your assistance!