我试图使用Bokeh教程中的一些代码消除图表上X轴上的无关标签。很明显,我错过了一些东西,因为我收到以下错误:
属性错误:'图表'对象没有属性' xaxis'
我假设问题是高级别图表不像常规情节那样起作用。有没有解决的办法?
import numpy
'''
***************** Craps Array Functions*****************
'''
def rollDie(n):
import random
die = random.randint(1,n)
return die
def crapsRoll():
a = rollDie(6)
b = rollDie(6)
c = a + b
return(c)
def crapsArray(count) :
import numpy as np
rollcount = 0
inc = 0
rolls = []
row = []
while inc < count:
inc = inc + 1
rollcount = rollcount + 1
roll = crapsRoll()
row = [rollcount, roll]
rolls.append(row)
else:
rollsArray = np.asarray(rolls)
print(' Rolls Done')
return(rollsArray)
temp = crapsArray(100)
numpy.savetxt('test.csv', temp, fmt= '%3.0d', delimiter = ',', header = "roll,score", comments ='')
'''
********************* Bokeh Plots ***********************
'''
import pandas as pd
from bokeh.charts import Bar, output_file, show
from bokeh.plotting import figure
from bokeh.models import FixedTicker
csv=pd.read_csv('test.csv')
output_file("craps.html")
p = figure(plot_width = 1000, plot_height = 400)
p = Bar(csv, 'roll', values = 'score', title = "Craps Outcomes", bar_width = 1, color = 'roll')
p.xaxis[0].ticker=FixedTicker(ticks=[0,25,50,75,100])
show(p)
答案 0 :(得分:2)
xaxis
等便捷方法在bokeh.plotting.Figure
上。但是,图表是基础bokeh.models.Plot
基类的子类,因此它们不存在。您可以使用select
方法查询对象:
In [18]: from bokeh.models import LinearAxis
In [19]: p.select(LinearAxis)
Out[19]: [<bokeh.models.axes.LinearAxis at 0x108f4def0>]
在图表上更容易获取轴可能是合理的,请随意在GitHub上打开功能请求问题,以便其他核心开发人员可以查看和讨论它。