无法在Ubuntu 14.04上绘制直方图

编程入门 行业动态 更新时间:2024-10-28 04:30:08
本文介绍了无法在Ubuntu 14.04上绘制直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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.

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

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...

更新

我在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上绘制直方图

本文发布于:2023-07-04 10:59:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023490.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:直方图   Ubuntu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!