Cannot plot Histogram on Ubuntu 14.04

2019-07-17 00:16发布

问题:

I'm using Python 2.7 and Bokeh 0.12.4 on Ubuntu 14.04. I have a data frame like so:

         msrp  price
compact   1.0    1.0
sedan     2.0    3.0
suv       3.0    5.0
sport     4.0    7.0

made this way:

import pandas as pd
from bokeh.charts import Histogram, output_file, show

s = pd.Series([1,2,3,4], index=['compact', 'sedan', 'suv', 'sport'], dtype='float64')
s2 = pd.Series([1,3,5,7], index=['compact', 'sedan', 'suv', 'sport'], dtype='float64')
df = pd.DataFrame({'msrp': s, 'price': s2})

output_file('test.html')
p = Histogram(df['msrp'], title='Test')
show(p)

When I run this, I get the following error:

ValueError: expected an element of either Column(Float), Column(Int), Column(String), Column(Date), Column(Datetime) or Column(Bool), got 0    2
dtype: int64

This is puzzling because when I examine the msrp series, I get:

>>> df['msrp']
compact    1.0
sedan      2.0
suv        3.0
sport      4.0
Name: msrp, dtype: float64

Note that dtype reads as a Float. what am I doing wrong? I should note that all other chart types work properly.

UPDATE The example on the docs dont work either:

from bokeh.sampledata.autompg import autompg as df
p = Histogram(df['hp'], title='Test')

Same error. Is this a known issue? If so, the docs should be updated...

UPDATE

I'm not having this problem on a Macbook. Only Ubuntu. Are there compatibility issues between Bokeh and Linux? I'm having this issue with Bokeh 0.12.4, 0.12.3, and 0.11.0.

回答1:

The old bokeh.charts API, including Histogram was deprecated and subsequently removed. To create histograms with Bokeh, you should use the bokeh.plotting API. There are a variety of ways that could work, here is one complete example, created with Bokeh 0.13:

import numpy as np
from bokeh.plotting import figure, show

measured = np.random.normal(0, 0.5, 1000)
hist, edge = np.histogram(measured, density=True, bins=50)

p = figure()
p.quad(top=hist, bottom=0, left=edge[:-1], right=edge[1:], line_color="white")

show(p)