Heatmap example in the doc is not working for me!

Bokeh 1.0.1

Here are my pandas dataframe(s):

cdf.head()

Year
Month
Rating
0
2002
Jul
0.829429
1
2002
Aug
0.772742
2
2002
Sep
0.859048
3
2002
Oct
0.826250
4
2002
Nov
0.780417

acdf.head()

Month
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Year

2002
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.829429
0.772742
0.859048
0.826250
0.780417
0.766739
2003
0.794586
0.788333
0.812756
0.758246
0.798598
0.800460
0.840994
0.810782
0.839610
0.821250
0.827163
0.799866
2004
0.810332
0.825000
0.812195
0.821558
0.815828
0.803860
0.817981
0.791423
0.812903
0.808825
0.813662
0.808625
2005
0.822619
0.801692
0.826941
0.810052
0.829125
0.817249
0.817197
0.829545
0.806301
0.811946
0.796417
0.831208
2006
0.818533
0.813261
0.769806
0.814383
0.819020
0.809942
0.819776
0.802465
0.801928
0.817741
0.817387
0.817363

And now my code following the EXACT same format as the heatmap example in the doc:

source = ColumnDataSource(cdf)
mapper = LinearColorMapper(palette=Inferno256, low=0.0, high=acdf.max().max())
color_bar = ColorBar(color_mapper=mapper, location=(0, 0),
ticker=BasicTicker(desired_num_ticks=256//12),
formatter=NumeralTickFormatter(format="%f"))

p = figure(plot_width=1000, plot_height=600, toolbar_location=None,
x_range=list(acdf.index), y_range=list(reversed(acdf.columns)),
tools="", x_axis_location=“above”)
p.rect(x=“Year”, y=“Month”, width=1, height=1, source=source,
line_color=None, fill_color=transform(‘Rating’, mapper))
p.add_layout(color_bar, ‘right’)
p.axis.axis_line_color = None
p.axis.major_tick_line_color = None
p.axis.major_label_standoff = 0
p.xaxis.major_label_orientation = 1.0

show§

``

I get the rectangle with the color bar and bokeh recognizes them as percentages correctly! Great!

Only problem is the whole rectangle is blank (white) and I have not a clue why. The dataframes look fine to me.

Help!

-aps

From your data and your code I can produce the expected results cf html file attached.

bokeh_forum.html (315 KB)

···

Le mardi 27 novembre 2018 06:52:50 UTC+1, pisymbol a écrit :

Bokeh 1.0.1

Here are my pandas dataframe(s):

cdf.head()

Year
Month
Rating
0
2002
Jul
0.829429
1
2002
Aug
0.772742
2
2002
Sep
0.859048
3
2002
Oct
0.826250
4
2002
Nov
0.780417

acdf.head()

Month
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Year

2002
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.829429
0.772742
0.859048
0.826250
0.780417
0.766739
2003
0.794586
0.788333
0.812756
0.758246
0.798598
0.800460
0.840994
0.810782
0.839610
0.821250
0.827163
0.799866
2004
0.810332
0.825000
0.812195
0.821558
0.815828
0.803860
0.817981
0.791423
0.812903
0.808825
0.813662
0.808625
2005
0.822619
0.801692
0.826941
0.810052
0.829125
0.817249
0.817197
0.829545
0.806301
0.811946
0.796417
0.831208
2006
0.818533
0.813261
0.769806
0.814383
0.819020
0.809942
0.819776
0.802465
0.801928
0.817741
0.817387
0.817363

And now my code following the EXACT same format as the heatmap example in the doc:

source = ColumnDataSource(cdf)
mapper = LinearColorMapper(palette=Inferno256, low=0.0, high=acdf.max().max())
color_bar = ColorBar(color_mapper=mapper, location=(0, 0),
ticker=BasicTicker(desired_num_ticks=256//12),
formatter=NumeralTickFormatter(format="%f"))

p = figure(plot_width=1000, plot_height=600, toolbar_location=None,
x_range=list(acdf.index), y_range=list(reversed(acdf.columns)),
tools="", x_axis_location=“above”)
p.rect(x=“Year”, y=“Month”, width=1, height=1, source=source,
line_color=None, fill_color=transform(‘Rating’, mapper))
p.add_layout(color_bar, ‘right’)
p.axis.axis_line_color = None
p.axis.major_tick_line_color = None
p.axis.major_label_standoff = 0
p.xaxis.major_label_orientation = 1.0

show§

``

I get the rectangle with the color bar and bokeh recognizes them as percentages correctly! Great!

Only problem is the whole rectangle is blank (white) and I have not a clue why. The dataframes look fine to me.

Help!

-aps

Here is what I see. What’s the difference? Here are my indexes and columns for both dataframes:

acdf:

        (Index(['2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010',
'2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018'],
dtype='object', name='Year'),
Index(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
'Nov', 'Dec'],
dtype='object', name='Month'))

 (RangeIndex(start=0, stop=197, step=1),
Index(['Year', 'Month', 'Rating'], dtype='object'))

And here is the output (attached). I was up for 2 hours late last night trying to figure out what the heck I'm doing wrong.

-aps

···

On Tuesday, November 27, 2018 at 8:00:18 AM UTC-5, Xavier Artusi wrote:

From your data and your code I can produce the expected results cf html file attached.

I just want to point out that I changed my LinearMap at some point to this line:

mapper = LinearColorMapper(palette=Inferno256, low=cdf[‘Rating’].min(), high=cdf[‘Rating’].max())

Which is why the ColorBar() looks a tad different than yours.

However, I don’t think that is the source of my issue as going back to low as zero gives me the same result.

Note that ‘lab’ vs ‘tree’ makes no difference.

-aps

Oh, and I had my months sorted vs non-sorted and that made no difference (again, it shouldn’t).

        (Index(['2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010',
'2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018'],
dtype='object', name='Year'),
Index(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
'Nov', 'Dec'],
dtype='object', name='Month'))

I'm a going nuts over here!

-aps

···

On Tuesday, November 27, 2018 at 9:56:18 AM UTC-5, pisymbol wrote:

I just want to point out that I changed my LinearMap at some point to this line:

mapper = LinearColorMapper(palette=Inferno256, low=cdf[‘Rating’].min(), high=cdf[‘Rating’].max())

can you print you datasource data?
Mine are :

        {'index': array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59], dtype=int64),
'Year': array(['2002', '2003', '2004', '2005', '2006', '2002', '2003', '2004',
'2005', '2006', '2002', '2003', '2004', '2005', '2006', '2002',
'2003', '2004', '2005', '2006', '2002', '2003', '2004', '2005',
'2006', '2002', '2003', '2004', '2005', '2006', '2002', '2003',
'2004', '2005', '2006', '2002', '2003', '2004', '2005', '2006',
'2002', '2003', '2004', '2005', '2006', '2002', '2003', '2004',
'2005', '2006', '2002', '2003', '2004', '2005', '2006', '2002',
'2003', '2004', '2005', '2006'], dtype=object),
'Month': array(['Jan', 'Jan', 'Jan', 'Jan', 'Jan', 'Feb', 'Feb', 'Feb', 'Feb',
'Feb', 'Mar', 'Mar', 'Mar', 'Mar', 'Mar', 'Apr', 'Apr', 'Apr',
'Apr', 'Apr', 'May', 'May', 'May', 'May', 'May', 'Jun', 'Jun',
'Jun', 'Jun', 'Jun', 'Jul', 'Jul', 'Jul', 'Jul', 'Jul', 'Aug',
'Aug', 'Aug', 'Aug', 'Aug', 'Sep', 'Sep', 'Sep', 'Sep', 'Sep',
'Oct', 'Oct', 'Oct', 'Oct', 'Oct', 'Nov', 'Nov', 'Nov', 'Nov',
'Nov', 'Dec', 'Dec', 'Dec', 'Dec', 'Dec'], dtype=object),
'Rating': array([0. , 0.794586, 0.810332, 0.822619, 0.818533, 0. ,
0.788333, 0.825 , 0.801692, 0.813261, 0. , 0.812756,
0.812195, 0.826941, 0.769806, 0. , 0.758246, 0.821558,
0.810052, 0.814383, 0. , 0.798598, 0.815828, 0.829125,
0.81902 , 0. , 0.80046 , 0.80386 , 0.817249, 0.809942,
0.829429, 0.840994, 0.817981, 0.817197, 0.819776, 0.772742,
0.810782, 0.791423, 0.829545, 0.802465, 0.859048, 0.83961 ,
0.812903, 0.806301, 0.801928, 0.82625 , 0.82125 , 0.808825,
0.811946, 0.817741, 0.780417, 0.827163, 0.813662, 0.796417,
0.817387, 0.766739, 0.799866, 0.808625, 0.831208, 0.817363])}
···

Le mardi 27 novembre 2018 16:04:24 UTC+1, pisymbol a écrit :

On Tuesday, November 27, 2018 at 9:56:18 AM UTC-5, pisymbol wrote:

I just want to point out that I changed my LinearMap at some point to this line:

mapper = LinearColorMapper(palette=Inferno256, low=cdf[‘Rating’].min(), high=cdf[‘Rating’].max())

Oh, and I had my months sorted vs non-sorted and that made no difference (again, it shouldn’t).

        (Index(['2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010',
'2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018'],
dtype='object', name='Year'),
Index(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
'Nov', 'Dec'],
dtype='object', name='Month'))

I'm a going nuts over here!

-aps

Xavier, I really owe you a beer and maybe a hug (up to you).

The problem was the original datasource had the year as an integer instead of a string. Holy mother…of … :-(!

I really do try to read the docs. I swear I do.

-aps

···

On Tue, Nov 27, 2018 at 10:32 AM Xavier Artusi [email protected] wrote:

can you print you datasource data?
Mine are :

        'Year': array(['2002', '2003', '2004', '2005', '2006', '2002', '2003', '2004',
'2005', '2006', '2002', '2003', '2004', '2005', '2006', '2002',
'2003', '2004', '2005', '2006', '2002', '2003', '2004', '2005',
'2006', '2002', '2003', '2004', '2005', '2006', '2002', '2003',
'2004', '2005', '2006', '2002', '2003', '2004', '2005', '2006',
'2002', '2003', '2004', '2005', '2006', '2002', '2003', '2004',
'2005', '2006', '2002', '2003', '2004', '2005', '2006', '2002',
'2003', '2004', '2005', '2006'], dtype=object),