Bokeh: How to change extra axis visibility

半世苍凉 提交于 2019-12-04 20:51:19

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!