1

我使用散景源代码。版本是 0.5.1

源码在bokeh主页,源码是histogram

但不是操作,


# -*- coding: utf-8 -*-

import numpy as np
import scipy.special
from bokeh.plotting import *

mu, sigma = 0, 0.5

measured = np.random.normal(mu, sigma, 1000)
hist, edges = np.histogram(measured, density=True, bins=50)

x = np.linspace(-2, 2, 1000)
pdf = 1/(sigma * np.sqrt(2*np.pi)) * np.exp(-(x-mu)**2 / (2*sigma**2))
cdf = (1+scipy.special.erf((x-mu)/np.sqrt(2*sigma**2)))/2

output_file('histogram.html')

hold()

figure(title="Normal Distribution (횓쩌=0, 횕혘=0.5)",tools="previewsave",
       background_fill="#E8DDCB")
quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564", line_color="#033649")


show()

编译错误--->

回溯(最后一次调用):文件“E:\workspace\python\anaconda\test\temp1.py”,第 22 行,在 quad(top=hist, bottom=0, left=edges[:-1], right =edges[1:], fill_color="#036564", line_color="#033649") 文件“C:\Users\junseok\Anaconda\lib\site-packages\bokeh\plotting.py”,第 336 行,在包装中retval = func(curdoc(), *args, **kwargs) 文件“C:\Users\junseok\Anaconda\lib\site-packages\bokeh_glyph_functions.py”,第 54 行,在 func y_data_fields = [ glyph_params[yy][ 'field'] for yy in yfields if glyph_params[yy]['units'] == 'data'] TypeError: 'int' object has no attribute ' getitem '

4

1 回答 1

0

嗨,此示例中的此更改已过早签入。问题是bottom=0. 这现在可以在 master 上运行,但它还没有在发布时改变,所以这个例子也不应该改变。对于所有这些,您只需要传递一个完整的实际零列表:

quad(top=hist, bottom=np.zeros_like(hist), left=edges[:-1], right=edges[1:], fill_color="#036564", line_color="#033649")

这种更好、更简单bottom=0的语法将在几周后发布到 0.5.2 版本以及 Binstar 上的任何介入开发版本中。

于 2014-07-29T14:59:35.097 回答