简体   繁体   中英

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

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 . 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() .

在此输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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