简体   繁体   English

无法在Ubuntu 14.04上绘制直方图

[英]Cannot plot Histogram on Ubuntu 14.04

I'm using Python 2.7 and Bokeh 0.12.4 on Ubuntu 14.04. 我在Ubuntu 14.04上使用Python 2.7和Bokeh 0.12.4。 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: 这令人困惑,因为当我检查msrp系列时,我得到:

>>> 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. 注意,dtype读为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 UPDATE

I'm not having this problem on a Macbook. 我在Macbook上没有这个问题。 Only Ubuntu. 只有Ubuntu。 Are there compatibility issues between Bokeh and Linux? Bokeh与Linux之间是否存在兼容性问题? I'm having this issue with Bokeh 0.12.4, 0.12.3, and 0.11.0. 我在Bokeh 0.12.4、0.12.3和0.11.0中遇到此问题。

The old bokeh.charts API, including Histogram was deprecated and subsequently removed. 旧的bokeh.charts API(包括Histogram )已被弃用,随后被删除。 To create histograms with Bokeh, you should use the bokeh.plotting API. 要使用Bokeh创建直方图,应使用bokeh.plotting API。 There are a variety of ways that could work, here is one complete example, created with Bokeh 0.13: 可以使用多种方法,这是使用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)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM