# Heatmap issue

**URL:** <https://discourse.bokeh.org/t/heatmap-issue/3171>\
**Category:** Community Support\
**Created:** [September 5, 2018, 8:10am UTC](https://discourse.bokeh.org/t/heatmap-issue/3171 "2018-09-05T08:10:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zana](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/zana/32/1671_2.png) [@Zana](https://discourse.bokeh.org/u/Zana)\
**Post date:** [September 5, 2018, 8:10am UTC](https://discourse.bokeh.org/t/heatmap-issue/3171/1 "2018-09-05T08:10:33Z")

</div>

Hi,

I am plotting a heat map which has a dataset of 0 and 1. I followed an example I found on bokeh. I dont understand why one of the tracks on the heatmap is not showing up (see plot below).

This is the dataset (csv file):

Date,Zone5\_test,Zone4\_test,Zone3\_test,Zone2\_test,Zone1\_test,Zone5\_test2,Zone4\_test2,Zone3\_test2,Zone2\_test2,Zone1\_test2

01.01.2016 05:15:20,0,0,1,1,1,0,1,1,0,1

01.02.2016 05:15:20,0,1,0,1,1,1,0,1,1,1

01.03.2016 05:15:20,0,0,0,1,0,1,1,0,0,0

01.04.2016 05:15:20,0,0,1,1,0,1,1,0,0,0

01.05.2016 05:15:20,1,1,1,0,0,1,1,0,1,0

01.06.2016 05:15:20,0,0,0,0,1,0,0,1,1,0

01.07.2016 05:15:20,0,0,0,0,1,0,1,0,0,1

01.08.2016 05:15:20,0,1,1,0,1,0,1,0,1,1

01.09.2016 05:15:20,1,0,1,0,0,0,1,0,0,1

01.10.2016 05:15:20,0,0,0,1,0,1,0,1,0,1

01.11.2016 05:15:20,0,1,1,0,0,0,0,1,0,0

01.12.2016 05:15:20,1,1,0,1,1,0,1,0,1,1

01.13.2016 05:15:20,1,1,0,1,1,0,1,1,1,1

01.14.2016 05:15:20,0,0,1,0,0,0,1,0,1,1

01.15.2016 05:15:20,1,0,1,0,1,1,1,0,0,0

01.16.2016 05:15:20,1,1,0,0,1,1,0,0,1,1

01.17.2016 05:15:20,0,1,1,0,1,0,0,1,1,1

01.18.2016 05:15:20,0,0,0,0,0,1,1,1,1,0

01.19.2016 05:15:20,1,1,0,0,1,0,0,1,1,0

01.20.2016 05:15:20,1,1,1,1,1,0,1,0,0,1

def testoverview(doc):

df = pd.read\_csv(‘data\testfile.csv’))

df = df.set\_index(‘Date’).astype(str)

df.columns.name = ‘Zones’

dftest = pd.DataFrame(df.stack(), columns=[‘Binary’]).reset\_index()

colorstest = ["#F21010", “#1D9A32”]

mappertest = LinearColorMapper(palette = colorstest, low = 0, high = 1)

colorstest2 = ["#F21010", “#1036F2”]

mappertest2 = LinearColorMapper(palette = colorstest2, low = 0, high = 1)

testdf = df[list(df.columns[:5])]

test2df = df[list(df.columns[5:len(df.columns)])]

p = figure(plot\_width = 800, plot\_height = 12000, title = “test1”,

y\_range = list(df.index), x\_range = list(reversed(testdf.columns)),

toolbar\_location=None, tools="", x\_axis\_location=“above”)

p2 = figure(plot\_width = 800, plot\_height = 12000, title = “test2”,

y\_range = list(df.index), x\_range = list(reversed(test2df.columns)),

toolbar\_location=None, tools="", x\_axis\_location=“above”)

p.rect(x=“Zones”, y = “Date”, width = 1, height = 1, source = dftest,

line\_color = None, fill\_color = transform(‘Binary’, mappertest))

p2.rect(x=“Zones”, y = “Date”, width = 1, height = 1, source = dftest,

line\_color = None, fill\_color = transform(‘Binary’, mappertest2))

p.xaxis.axis\_label = ‘Zones’

p.yaxis.axis\_label = ‘Time’

p2.xaxis.axis\_label = ‘Zones’

p2.yaxis.axis\_label = ‘Time’

doc.add\_root(row(p, p2))

``

First heatmap looks fine, is plotting all 5 columns. The second one isnt showing the last column Zone1\_test2. I dont understand why, plots are identical and I have checked numerous times the data is there.

![test2.PNG](https://discourse-uploads.bokeh.org/original/1X/31652b224ba3caa5503d5578b99baaed3a26c429.png)

What am I doing wrong? 😛

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [September 5, 2018, 10:09pm UTC](https://discourse.bokeh.org/t/heatmap-issue/3171/2 "2018-09-05T22:09:40Z")

</div>

Hi,

The root of the issue seems to be that you are sending too much data to each plot, i.e. plot1 has a factor range for [A, B, C] and plot2 has a factor range for [D, E, F] but the the data source for each plot you are creating has values for all of [A, B, C, D, E, F]. Ideally Bokeh should just ignore categorical coordinates that are not part of the categorical range for the plot. But there seems to be some issue with that.

Things work if you pare down the data frame before plotting. Note that the second plot did not plot correctly even if the first plot was left out, so I have pared the example down to be minimal:

&nbsp;&nbsp;&nbsp;&nbsp;from bokeh.plotting import figure, curdoc  
&nbsp;&nbsp;&nbsp;&nbsp;from bokeh.transform import linear\_cmap

&nbsp;&nbsp;&nbsp;&nbsp;import pandas as pd

&nbsp;&nbsp;&nbsp;&nbsp;df = pd.read\_csv('testfile.csv')  
&nbsp;&nbsp;&nbsp;&nbsp;df = df.set\_index('Date').astype(str)  
&nbsp;&nbsp;&nbsp;&nbsp;df.columns.name = 'Zones'  
&nbsp;&nbsp;&nbsp;&nbsp;dftest = pd.DataFrame(df.stack(), columns=['Binary']).reset\_index()

&nbsp;&nbsp;&nbsp;&nbsp;factors = list(reversed(df.columns[5:len(df.columns)]))

&nbsp;&nbsp;&nbsp;&nbsp;# NOTE: remove this line and things will break as before  
&nbsp;&nbsp;&nbsp;&nbsp;dftest = dftest[dftest.Zones.isin(factors)]

&nbsp;&nbsp;&nbsp;&nbsp;p = figure(plot\_width = 800, plot\_height = 1200, title = "test2",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y\_range = list(df.index), x\_range = factors,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;toolbar\_location=None, tools="pan", x\_axis\_location="above")

&nbsp;&nbsp;&nbsp;&nbsp;p.rect(x="Zones", y = "Date", width = 1, height = 1, source = dftest,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line\_color = None, fill\_color = linear\_cmap('Binary', ["#F21010", "#1036F2"], 0, 1))

&nbsp;&nbsp;&nbsp;&nbsp;curdoc().add\_root℗

TLDR; Best practice: don't send data with unknown factors to a plot.

Thanks,

Bryan

> **···**
>
> > On Sep 5, 2018, at 01:10, Zana \<zanapepaj@gmail.com\> wrote:
> > 
> > Hi,
> > 
> > I am plotting a heat map which has a dataset of 0 and 1. I followed an example I found on bokeh. I dont understand why one of the tracks on the heatmap is not showing up (see plot below).
> > 
> > This is the dataset (csv file):
> > 
> > Date,Zone5\_test,Zone4\_test,Zone3\_test,Zone2\_test,Zone1\_test,Zone5\_test2,Zone4\_test2,Zone3\_test2,Zone2\_test2,Zone1\_test2  
> > 01.01.2016 05:15:20,0,0,1,1,1,0,1,1,0,1  
> > 01.02.2016 05:15:20,0,1,0,1,1,1,0,1,1,1  
> > 01.03.2016 05:15:20,0,0,0,1,0,1,1,0,0,0  
> > 01.04.2016 05:15:20,0,0,1,1,0,1,1,0,0,0  
> > 01.05.2016 05:15:20,1,1,1,0,0,1,1,0,1,0  
> > 01.06.2016 05:15:20,0,0,0,0,1,0,0,1,1,0  
> > 01.07.2016 05:15:20,0,0,0,0,1,0,1,0,0,1  
> > 01.08.2016 05:15:20,0,1,1,0,1,0,1,0,1,1  
> > 01.09.2016 05:15:20,1,0,1,0,0,0,1,0,0,1  
> > 01.10.2016 05:15:20,0,0,0,1,0,1,0,1,0,1  
> > 01.11.2016 05:15:20,0,1,1,0,0,0,0,1,0,0  
> > 01.12.2016 05:15:20,1,1,0,1,1,0,1,0,1,1  
> > 01.13.2016 05:15:20,1,1,0,1,1,0,1,1,1,1  
> > 01.14.2016 05:15:20,0,0,1,0,0,0,1,0,1,1  
> > 01.15.2016 05:15:20,1,0,1,0,1,1,1,0,0,0  
> > 01.16.2016 05:15:20,1,1,0,0,1,1,0,0,1,1  
> > 01.17.2016 05:15:20,0,1,1,0,1,0,0,1,1,1  
> > 01.18.2016 05:15:20,0,0,0,0,0,1,1,1,1,0  
> > 01.19.2016 05:15:20,1,1,0,0,1,0,0,1,1,0  
> > 01.20.2016 05:15:20,1,1,1,1,1,0,1,0,0,1
> > 
> > def testoverview(doc):
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;df = pd.read\_csv('data\testfile.csv'))  
> > &nbsp;&nbsp;&nbsp;&nbsp;df = df.set\_index('Date').astype(str)  
> > &nbsp;&nbsp;&nbsp;&nbsp;df.columns.name = 'Zones'  
> > &nbsp;&nbsp;&nbsp;&nbsp;dftest = pd.DataFrame(df.stack(), columns=['Binary']).reset\_index()  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
> > &nbsp;&nbsp;&nbsp;&nbsp;colorstest = ["#F21010", "#1D9A32"]  
> > &nbsp;&nbsp;&nbsp;&nbsp;mappertest = LinearColorMapper(palette = colorstest, low = 0, high = 1)
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;colorstest2 = ["#F21010", "#1036F2"]  
> > &nbsp;&nbsp;&nbsp;&nbsp;mappertest2 = LinearColorMapper(palette = colorstest2, low = 0, high = 1)
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;testdf = df[list(df.columns[:5])]  
> > &nbsp;&nbsp;&nbsp;&nbsp;test2df = df[list(df.columns[5:len(df.columns)])]
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;p = figure(plot\_width = 800, plot\_height = 12000, title = "test1",  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y\_range = list(df.index), x\_range = list(reversed(testdf.columns)),  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;toolbar\_location=None, tools="", x\_axis\_location="above")  
> > &nbsp;&nbsp;&nbsp;&nbsp;  
> > &nbsp;&nbsp;&nbsp;&nbsp;p2 = figure(plot\_width = 800, plot\_height = 12000, title = "test2",  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y\_range = list(df.index), x\_range = list(reversed(test2df.columns)),  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;toolbar\_location=None, tools="", x\_axis\_location="above")
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;p.rect(x="Zones", y = "Date", width = 1, height = 1, source = dftest,  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line\_color = None, fill\_color = transform('Binary', mappertest))  
> > &nbsp;&nbsp;&nbsp;&nbsp;  
> > &nbsp;&nbsp;&nbsp;&nbsp;p2.rect(x="Zones", y = "Date", width = 1, height = 1, source = dftest,  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line\_color = None, fill\_color = transform('Binary', mappertest2))
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;p.xaxis.axis\_label = 'Zones'  
> > &nbsp;&nbsp;&nbsp;&nbsp;p.yaxis.axis\_label = 'Time'
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;p2.xaxis.axis\_label = 'Zones'  
> > &nbsp;&nbsp;&nbsp;&nbsp;p2.yaxis.axis\_label = 'Time'
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;doc.add\_root(row(p, p2))
> > 
> > First heatmap looks fine, is plotting all 5 columns. The second one isnt showing the last column Zone1\_test2. I dont understand why, plots are identical and I have checked numerous times the data is there.
> > 
> > \<test2.PNG\>
> > 
> > What am I doing wrong? 😛
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.  
> > To post to this group, send email to bokeh@continuum.io.  
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/8a514033-6b0d-4bb3-9d78-c85f0754cab3%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/8a514033-6b0d-4bb3-9d78-c85f0754cab3%40continuum.io%5C).  
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).  
> > \<test2.PNG\>

---

<div class="post-metadata">

**Author:** ![Zana](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/zana/32/1671_2.png) [@Zana](https://discourse.bokeh.org/u/Zana)\
**Post date:** [October 5, 2018, 7:35am UTC](https://discourse.bokeh.org/t/heatmap-issue/3171/3 "2018-10-05T07:35:09Z")

</div>

Sorry for late reply. That helped Bryan:)!

> **···**
>
> On Wednesday, September 5, 2018 at 10:10:33 AM UTC+2, Zana wrote:
> 
> > Hi,
> 
> > I am plotting a heat map which has a dataset of 0 and 1. I followed an example I found on bokeh. I dont understand why one of the tracks on the heatmap is not showing up (see plot below).
> 
> > 
> 
> > This is the dataset (csv file):
> 
> > 
> 
> > Date,Zone5\_test,Zone4\_test,Zone3\_test,Zone2\_test,Zone1\_test,Zone5\_test2,Zone4\_test2,Zone3\_test2,Zone2\_test2,Zone1\_test2
> 
> > 01.01.2016 05:15:20,0,0,1,1,1,0,1,1,0,1
> 
> > 01.02.2016 05:15:20,0,1,0,1,1,1,0,1,1,1
> 
> > 01.03.2016 05:15:20,0,0,0,1,0,1,1,0,0,0
> 
> > 01.04.2016 05:15:20,0,0,1,1,0,1,1,0,0,0
> 
> > 01.05.2016 05:15:20,1,1,1,0,0,1,1,0,1,0
> 
> > 01.06.2016 05:15:20,0,0,0,0,1,0,0,1,1,0
> 
> > 01.07.2016 05:15:20,0,0,0,0,1,0,1,0,0,1
> 
> > 01.08.2016 05:15:20,0,1,1,0,1,0,1,0,1,1
> 
> > 01.09.2016 05:15:20,1,0,1,0,0,0,1,0,0,1
> 
> > 01.10.2016 05:15:20,0,0,0,1,0,1,0,1,0,1
> 
> > 01.11.2016 05:15:20,0,1,1,0,0,0,0,1,0,0
> 
> > 01.12.2016 05:15:20,1,1,0,1,1,0,1,0,1,1
> 
> > 01.13.2016 05:15:20,1,1,0,1,1,0,1,1,1,1
> 
> > 01.14.2016 05:15:20,0,0,1,0,0,0,1,0,1,1
> 
> > 01.15.2016 05:15:20,1,0,1,0,1,1,1,0,0,0
> 
> > 01.16.2016 05:15:20,1,1,0,0,1,1,0,0,1,1
> 
> > 01.17.2016 05:15:20,0,1,1,0,1,0,0,1,1,1
> 
> > 01.18.2016 05:15:20,0,0,0,0,0,1,1,1,1,0
> 
> > 01.19.2016 05:15:20,1,1,0,0,1,0,0,1,1,0
> 
> > 01.20.2016 05:15:20,1,1,1,1,1,0,1,0,0,1
> 
> > 
> 
> > 
> 
> > def testoverview(doc):
> 
> > 
> 
> > df = pd.read\_csv(‘data\testfile.csv’))
> 
> > df = df.set\_index(‘Date’).astype(str)
> 
> > [df.columns.name](http://df.columns.name) = ‘Zones’
> 
> > dftest = pd.DataFrame(df.stack(), columns=[‘Binary’]).reset\_index()
> 
> > colorstest = [“#F21010”, “#1D9A32”]
> 
> > mappertest = LinearColorMapper(palette = colorstest, low = 0, high = 1)
> 
> > 
> 
> > colorstest2 = [“#F21010”, “#1036F2”]
> 
> > mappertest2 = LinearColorMapper(palette = colorstest2, low = 0, high = 1)
> 
> > 
> 
> > testdf = df[list(df.columns[:5])]
> 
> > test2df = df[list(df.columns[5:len(df.columns)])]
> 
> > 
> 
> > p = figure(plot\_width = 800, plot\_height = 12000, title = “test1”,
> 
> > y\_range = list(df.index), x\_range = list(reversed(testdf.columns)),
> 
> > toolbar\_location=None, tools=“”, x\_axis\_location=“above”)
> 
> > p2 = figure(plot\_width = 800, plot\_height = 12000, title = “test2”,
> 
> > y\_range = list(df.index), x\_range = list(reversed(test2df.columns)),
> 
> > toolbar\_location=None, tools=“”, x\_axis\_location=“above”)
> 
> > 
> 
> > p.rect(x=“Zones”, y = “Date”, width = 1, height = 1, source = dftest,
> 
> > line\_color = None, fill\_color = transform(‘Binary’, mappertest))
> 
> > p2.rect(x=“Zones”, y = “Date”, width = 1, height = 1, source = dftest,
> 
> > line\_color = None, fill\_color = transform(‘Binary’, mappertest2))
> 
> > 
> 
> > p.xaxis.axis\_label = ‘Zones’
> 
> > p.yaxis.axis\_label = ‘Time’
> 
> > 
> 
> > p2.xaxis.axis\_label = ‘Zones’
> 
> > p2.yaxis.axis\_label = ‘Time’
> 
> > 
> 
> > doc.add\_root(row(p, p2))
> 
> > ``
> 
> > First heatmap looks fine, is plotting all 5 columns. The second one isnt showing the last column Zone1\_test2. I dont understand why, plots are identical and I have checked numerous times the data is there.
> 
> > 
> 
> > ![test2.PNG](https://discourse-uploads.bokeh.org/original/2X/8/8b15015b808d43bd42ee1cd2a4c30755d2923a85.png)
> 
> > 
> 
> > What am I doing wrong? 😛
> 
> > 
> 
> >

---

<div class="post-metadata">

**Author:** ![system](https://discourse-uploads.bokeh.org/original/2X/1/14eb24f9e10e4e9b78e3f10f66c04ffa96446e5a.svg) [@system](https://discourse.bokeh.org/u/system)\
**Post date:** [July 21, 2021, 9:15pm UTC](https://discourse.bokeh.org/t/heatmap-issue/3171/4 "2021-07-21T21:15:46Z")

</div>


