falo8056
falo8056

Reputation: 85

Sharing axis ranges - Bokeh

I want to share the ranges of my X-axis so that when I pan through my plots all of them move together.

I am trying to follow the example from the Guide Line. But because I am plotting them in a different way it does not allow me to share the range.

p = [figure(title="Title", 
            x_axis_label='Time (secs)', 
            y_axis_label='Voltage (V)', 
            tools = TOOLS, 
            x_range=(0, 500), 
            y_range=(0, 1000)),

    figure(title="Title_1", 
           x_axis_label='Time (secs)', 
           y_axis_label='Voltage (V)',  
           tools = TOOLS,
           x_range=p[0].x_range, 
           y_range=(0, 500))]

I get the following:

   x_range=p[0].x_range,

IndexError: list index out of range

What is going on?

Upvotes: 1

Views: 259

Answers (2)

bigreddot
bigreddot

Reputation: 34568

You can change the range after the creation instead of during creation:

p[1].x_range = p[0].x_range

Upvotes: 0

shayan rok rok
shayan rok rok

Reputation: 540

You have defined a list in which one of the elements refers to its first index. You can't refer to an index of the element on the definition.

for example:

class Person:
    def __init__(self, name):
        self.name = name

list1 = ['first', Person(list1[0])]

and in your snippet code:

p = [figure(title="Title", 
            x_axis_label='Time (secs)', 
            y_axis_label='Voltage (V)', 
            tools = TOOLS, 
            x_range=(0, 500), 
            y_range=(0, 1000)),

    figure(title="Title_1", 
           x_axis_label='Time (secs)', 
           y_axis_label='Voltage (V)',  
           tools = TOOLS,
           x_range=p[0].x_range, # Here is problem you the p[0] is refering 
                                 #  to index 0 on definition of the list 
           y_range=(0, 500))]

You can do something like below for the purpose you got:

p = [
    figure(
        title="Title", 
        x_axis_label='Time (secs)', 
        y_axis_label='Voltage (V)', 
        tools = TOOLS, 
        x_range=(0, 500), 
        y_range=(0, 1000)
    )
]
p.append(
    figure(
       title="Title_1", 
       x_axis_label='Time (secs)', 
       y_axis_label='Voltage (V)',  
       tools = TOOLS,
       x_range=p[0].x_range,
       y_range=(0, 500)
    )
)

Upvotes: 1

Related Questions