簡體   English   中英

無法在Ubuntu 14.04上繪制直方圖

[英]Cannot plot Histogram on Ubuntu 14.04

我在Ubuntu 14.04上使用Python 2.7和Bokeh 0.12.4。 我有一個這樣的數據框:

         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)

運行此命令時,出現以下錯誤:

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系列時,我得到:

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

注意,dtype讀為Float。 我究竟做錯了什么? 我應該注意,所有其他圖表類型均能正常工作。

更新文檔上的示例不起作用:

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

同樣的錯誤。 這是一個已知的問題? 如果是這樣,則應更新文檔...

UPDATE

我在Macbook上沒有這個問題。 只有Ubuntu。 Bokeh與Linux之間是否存在兼容性問題? 我在Bokeh 0.12.4、0.12.3和0.11.0中遇到此問題。

舊的bokeh.charts API(包括Histogram )已被棄用,隨后被刪除。 要使用Bokeh創建直方圖,應使用bokeh.plotting API。 可以使用多種方法,這是使用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