0

I know I can turn axes on and off in bokeh with p1.xaxis.visible = None or p1.yaxis.visible = None from Hide Axis in Bokeh. What if I have an extra y range I want to change the visibility of? I've defined my extra axis like this:

plot.extra_y_ranges = {'ORP': Range1d(start=0, end=plot_d['y_axis2_max'])}
plot.add_layout(LinearAxis(y_range_name='ORP', axis_label='ORP, mV'), 'left')

I tried plot.extra_y_ranges.visible = None but it has no effect, and I wasn't able to find anything in the documentation. Have I missed something?

Community
  • 1
  • 1

1 Answers1

1

You need to change the visibility of the lines, not the axis.

I've done this in a project on Github that displays temperature and humidity data (amongst other things). The humidity data is the extra y axis and I have check boxes to show/hide temperature and/or humidity. Here's the function that shows/hides the lines on the chart:

def h_t_lines_changed(self, active):
    """Helper function for h_t_tab - turns lines on and off"""
    for index in range(len(self.h_t_line)):
        self.h_t_line[index].visible = index in active

Here's the line definitions:

    self.h_t_line[0] = self.h_t_fig.line(x='Timestamp',
                                         y='Temperature (C)',
                                         source=self.source,
                                         color="blue",
                                         legend="Temperature",
                                         line_width=2)

    self.h_t_line[1] = self.h_t_fig.line(x="Timestamp",
                                         y="Relative humidity (%)",
                                         source=self.source,
                                         y_range_name="humidity",
                                         color="green",
                                         legend="Humidity",
                                         line_width=2)

and here's the checkbox code, including the callback:

    resp_b = [0, 1]
    h_t_check_head = Div(text="Responses")
    h_t_check = CheckboxGroup(labels=["Temperature", "Humidity"],
                              active=resp_b,
                              name="Lines")

    h_t_check.on_click(self.h_t_lines_changed)

I'm updating my project now. If you want me to post a link to it, let me know.

Mike Woodward
  • 211
  • 2
  • 10