简体   繁体   English

散景绘制第二轴 - 如何获得主轴的限制?

[英]bokeh plotting second axis - how to get limits of primary axis?

I have a bokeh plot with date on the x-axis ( data["obs_date"] ) and I want another x-axis at the top covering the same range but shown in a different format ( mjd below). 我有一个在x轴上有日期的散景图( data["obs_date"] ),我希望顶部的另一个x轴覆盖相同的范围,但以不同的格式显示(下面的mjd )。

I have tried to add the second axis with: 我试图添加第二个轴:

plot.extra_x_ranges = {"MJD":
                           Range1d(start=Time(min(data["obs_date"])).mjd,
                                   end=Time(max(data["obs_date"])).mjd)}
plot.add_layout(LinearAxis(x_range_name="MJD", axis_label="MJD",
                               axis_label_text_font_size="16pt"),
                               "above")

However, because bokeh adds a small buffer to the limits of the plot, using min max of data["obs_date"] as the limits for this new axis gives me a small offset - in the image below 16 Jan 2018 should align with 58134 . 然而,由于背景虚化增加了一个小的缓冲的情节的限制,使用min maxdata["obs_date"]作为用于这个新轴的限制给我一个小的偏移-在下面的图片16 Jan 2018 ,应对准58134 It also causes it to break when I only have one point to plot. 当我只有一点绘图时,它也会导致它破裂。

How can I set the limits of my new axis so that it is 'aware' of the limits of the primary axis? 如何设置新轴的极限,以便“了解”主轴的极限? Coming form a matplotlib background, I suppose the equivalent I am looking for is ax.get_xlim() . 来自matplotlib背景,我想我正在寻找的等价物是ax.get_xlim()

在此输入图像描述

Bokeh implicitly uses DataRange1d that computes the padded bounds based on its range_padding , range_padding_units , and follow_interval fields, and whether the underlying scale is linear or logarithmic. Bokeh隐式使用DataRange1d ,它根据其range_paddingrange_padding_unitsfollow_interval字段计算填充边界,以及基础比例是线性还是对数。 But it does not store the computed values. 但它不存储计算值。

So, your only options at this point are either to set the boundaries explicitly for both ranges or to compute the boundaries for the extra range based on the aforementioned DataRange1d fields and the scale type. 因此,此时您唯一的选择是为两个范围明确设置边界,或者根据前面提到的DataRange1d字段和比例类型计算额外范围的边界。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM