Josh Sigler
Josh Sigler

Reputation: 21

Bokeh Chart Label Increment

I'm trying to eliminate the extraneous labels on the X axis on a chart using a bit of code I found in the Bokeh tutorials. Clearly I am missing something as I get the following error:

AttributeError: 'Chart' object has no attribute 'xaxis'

I am assuming the issue is that high level charts don't function like regular plots. Is there a way around this?

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)

Upvotes: 2

Views: 292

Answers (1)

bigreddot
bigreddot

Reputation: 34568

The xaxis, etc. convenience methods are on bokeh.plotting.Figure. However charts are a subclass of the basics bokeh.models.Plot base class, so they do not exist. You can use the select method to query for objects though:

In [18]: from bokeh.models import LinearAxis

In [19]: p.select(LinearAxis)
Out[19]: [<bokeh.models.axes.LinearAxis at 0x108f4def0>]

It would probably be reasonable to make it easier to get axes on Charts, please feel free to open a feature request issue on GitHub so that the other core devs can see and discuss it.

Upvotes: 2

Related Questions