Bokeh: How to change extra axis visibility

China☆狼群 提交于 2019-12-06 15:11:56

问题


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?


回答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.



来源:https://stackoverflow.com/questions/38664831/bokeh-how-to-change-extra-axis-visibility

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