本文介绍了散景:如何更改额外的轴可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用隐藏的p1.xaxis.visible = Nonep1.yaxis.visible = None在bokeh中打开和关闭轴散景中的轴.如果我有一个额外的y范围要更改其可见度怎么办?我已经这样定义了额外的轴:

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')

我尝试了plot.extra_y_ranges.visible = None,但是没有任何效果,而且我在文档中找不到任何内容.我错过了什么吗?

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?

推荐答案

您需要更改线条(而不是轴)的可见性.

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

我已经在Github上的一个项目中做到了这一点,该项目显示温度和湿度数据(以及其他信息).湿度数据是额外的y轴,我有复选框显示/隐藏温度和/或湿度.这是显示/隐藏图表上线条的功能:

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

以下是行定义:

    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.

这篇关于散景:如何更改额外的轴可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:49