问题描述
我在Ubuntu 14.04上使用Python 2.7和Bokeh 0.12.4.我有一个这样的数据框:
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
是这样制作的:
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
这令人困惑,因为当我检查msrp系列时,我得到:
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
请注意,dtype读为Float.我究竟做错了什么?我应该注意,所有其他图表类型都可以正常工作.
Note that dtype reads as a Float. what am I doing wrong? I should note that all other chart types work properly.
更新文档上的示例也不起作用:
UPDATEThe 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...
更新
我在Macbook上没有这个问题.只有Ubuntu. Bokeh和Linux之间是否存在兼容性问题?我在Bokeh 0.12.4、0.12.3和0.11.0中遇到了这个问题.
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.
推荐答案
不推荐使用旧的bokeh.charts
API,包括Histogram
,随后将其删除.要使用Bokeh创建直方图,应使用bokeh.plotting
API.可以使用多种方法,下面是一个使用Bokeh 0.13创建的完整示例:
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)
这篇关于无法在Ubuntu 14.04上绘制直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!