question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bokeh docs heatmap example broken

See original GitHub issue

When running the example at http://bokeh.pydata.org/en/0.12.0/docs/reference/charts.html#heatmap with bokeh 0.12.0, an error occurs, e.g.

Traceback (most recent call last):
  File "heatmap.py", line 16, in <module>
    p = HeatMap(df, title='Fruits')
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/builders/heatmap_builder.py", line 92, in HeatMap
    chart = create_and_build(HeatMapBuilder, data, xgrid=xgrid, ygrid=ygrid, **kw)
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/builder.py", line 73, in create_and_build
    chart.add_builder(builder)
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/chart.py", line 171, in add_builder
    builder.create(self)
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/builder.py", line 531, in create
    self.process_data()
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/builders/heatmap_builder.py", line 172, in process_data
    columns=self.values.selection)
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/attributes.py", line 198, in setup
    self.attr_map = self._create_attr_map(self.data.to_df(), self.columns)
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/attributes.py", line 168, in _create_attr_map
    self._generate_items(df, columns)
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/attributes.py", line 249, in _generate_items
    bins=len(self.iterable), aggregate=False)
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/stats.py", line 311, in __init__
    super(BinnedStat, self).__init__(**properties)
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/stats.py", line 56, in __init__
    self._refresh()
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/stats.py", line 62, in _refresh
    self.calculate()
  File "/usr/local/lib/python2.7/dist-packages/bokeh/charts/stats.py", line 365, in calculate
    self.source.add(binned.tolist(), name=self.bin_column)
AttributeError: 'Categorical' object has no attribute 'tolist'

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Jun 7, 2017

@duncangh bokeh.charts has moved to a new separate repo and project all issues for it should go here https://github.com/bokeh/bkcharts

0reactions
duncanghcommented, Jun 7, 2017

I have a similar issue running Jupyter Notebook heat map example.

pandas=‘0.20.1’ bokeh=‘0.12.5’

from bokeh.charts import HeatMap, output_file, show

# (dict, OrderedDict, lists, arrays and DataFrames are valid inputs)
dataa = {'fruit': ['apples']*3 + ['bananas']*3 + ['pears']*3,
        'fruit_count': [4, 5, 8, 1, 2, 4, 6, 5, 4],
        'sample': [1, 2, 3]*3}

hm = HeatMap(dataa, x='fruit', y='sample', values='fruit_count',
             title='Fruits', stat=None)

output_file('heatmap.html')
show(hm)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-56-e2abcb05d9e4> in <module>()
      7 
      8 hm = HeatMap(dataa, x='fruit', y='sample', values='fruit_count',
----> 9              title='Fruits', stat=None)
     10 
     11 output_file('heatmap.html')

/usr/local/lib/python3.5/site-packages/bokeh/charts/builders/heatmap_builder.py in HeatMap(data, x, y, values, stat, xgrid, ygrid, hover_tool, hover_text, **kw)
     90     kw['values'] = values
     91     kw['stat'] = stat
---> 92     chart = create_and_build(HeatMapBuilder, data, xgrid=xgrid, ygrid=ygrid, **kw)
     93 
     94     if hover_tool:

/usr/local/lib/python3.5/site-packages/bokeh/charts/builder.py in create_and_build(builder_class, *data, **kws)
     54     chart_kws = {k: v for k, v in kws.items() if k not in builder_props}
     55     chart = Chart(**chart_kws)
---> 56     chart.add_builder(builder)
     57     chart.start_plot()
     58 

/usr/local/lib/python3.5/site-packages/bokeh/charts/chart.py in add_builder(self, builder)
    151     def add_builder(self, builder):
    152         self._builders.append(builder)
--> 153         builder.create(self)
    154 
    155     def add_ranges(self, dim, range):

/usr/local/lib/python3.5/site-packages/bokeh/charts/builder.py in create(self, chart)
    504         # call methods that allow customized setup by subclasses
    505         self.setup()
--> 506         self.process_data()
    507 
    508         # create and add renderers to chart

/usr/local/lib/python3.5/site-packages/bokeh/charts/builders/heatmap_builder.py in process_data(self)
    170         # color by the values selection
    171         self.attributes['color'].setup(data=self._data.source,
--> 172                                        columns=self.values.selection)
    173         self.attributes['color'].add_bin_labels(self._data)
    174 

/usr/local/lib/python3.5/site-packages/bokeh/charts/attributes.py in setup(self, data, columns)
    200 
    201         if self.columns is not None and self.data is not None:
--> 202             self.attr_map = self._create_attr_map(self.data.to_df(), self.columns)
    203 
    204     def update_data(self, data):

/usr/local/lib/python3.5/site-packages/bokeh/charts/attributes.py in _create_attr_map(self, df, columns)
    170 
    171         if df is not None and columns is not None:
--> 172             self._generate_items(df, columns)
    173 
    174         iterable = self._setup_iterable()

/usr/local/lib/python3.5/site-packages/bokeh/charts/attributes.py in _generate_items(self, df, columns)
    251 
    252                 self.bins = Bins(source=ColumnDataSource(df), column=columns[0],
--> 253                                  bins=len(self.iterable), aggregate=False)
    254 
    255                 if self.sort:

/usr/local/lib/python3.5/site-packages/bokeh/charts/stats.py in __init__(self, values, column, bins, stat, source, **properties)
    308         properties['source'] = source
    309         self._bins = bins
--> 310         super(BinnedStat, self).__init__(**properties)
    311 
    312 

/usr/local/lib/python3.5/site-packages/bokeh/charts/stats.py in __init__(self, **properties)
     53 
     54         super(Stat, self).__init__(**properties)
---> 55         self._refresh()
     56 
     57     def _refresh(self):

/usr/local/lib/python3.5/site-packages/bokeh/charts/stats.py in _refresh(self)
     59         if self.get_data() is not None:
     60             self.update()
---> 61             self.calculate()
     62 
     63     def set_data(self, data, column=None):

/usr/local/lib/python3.5/site-packages/bokeh/charts/stats.py in calculate(self)
    369         for name, group in df.groupby(self.bin_column):
    370             bin_models.append(Bin(bin_label=name, values=group[self.column],
--> 371                                   stat=self.stat))
    372 
    373         self.bins = bin_models

/usr/local/lib/python3.5/site-packages/bokeh/charts/stats.py in __init__(self, bin_label, values, source, **properties)
    175         properties['label'] = bin_label
    176 
--> 177         bounds = self.process_bounds(bin_label)
    178 
    179         starts, stops = zip(*bounds)

/usr/local/lib/python3.5/site-packages/bokeh/charts/stats.py in process_bounds(self, bin_label)
    205     def process_bounds(self, bin_label):
    206         if isinstance(bin_label, list):
--> 207             return [self.binstr_to_list(dim) for dim in bin_label]
    208         else:
    209             return [self.binstr_to_list(bin_label)]

/usr/local/lib/python3.5/site-packages/bokeh/charts/stats.py in <listcomp>(.0)
    205     def process_bounds(self, bin_label):
    206         if isinstance(bin_label, list):
--> 207             return [self.binstr_to_list(dim) for dim in bin_label]
    208         else:
    209             return [self.binstr_to_list(bin_label)]

/usr/local/lib/python3.5/site-packages/bokeh/charts/stats.py in binstr_to_list(bins)
    197     def binstr_to_list(bins):
    198         """Produce a consistent display of a bin of data."""
--> 199         value_chunks = bins.split(',')
    200         value_chunks = [val.replace('[', '').replace(']', '').replace('(', '').replace(')', '') for val in value_chunks]
    201         bin_values = [float(value) for value in value_chunks]

AttributeError: 'pandas._libs.interval.Interval' object has no attribute 'split'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Heatmap Not Displaying --> Blank Screen - Bokeh Discourse
I am trying to create a Heatmap from a csv using python pandas. I keep on getting a blank screen for my output,...
Read more >
Python 3 Bokeh Heatmap Rect simple example not showing ...
I'm trying to color code a simple categorical heatmap using python's Bokeh library. For example, given the following ...
Read more >
Customizing Plots — HoloViews v1.15.3
While different plotting extensions like bokeh, matplotlib and plotly offer ... Plots have an overall hierarchy and here we will break down the...
Read more >
Plotting — hvPlot 0.8.2 documentation
Here we will use the sample data module and load the pandas and dask ... it uses HoloViews to generate either static or...
Read more >
python-bokeh-0.12.15-bp150.1.3 - SUSE Package Hub -
... docs] Fix typo in docs + #7515 [component: bokehjs] Bokeh 0.12.14 doesn't ... compatibility + #4743 [component: docs] Bokeh docs heatmap example...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found