Bokeh building a second axis - how to get the limits of the primary axis?

I have a bokeh graph with a date on the x axis ( data["obs_date"]), and I want the other x axis at the top to cover the same range, but display in a different format ( mjdbelow).

I tried to add a 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, since bokeh adds a small buffer to the borders of the graph using min maxof data["obs_date"], since the restrictions for this new axis give me a slight offset - in the image below I 16 Jan 2018should align with 58134. It also makes it break when I have only one point to build.

How can I set the limits of my new axis so that it "knows" the limits of the primary axis? Starting to create a matplotlib background, I assume that the equivalent I'm looking for is this ax.get_xlim().

enter image description here

+6
source share
1 answer

Bokeh implicitly uses DataRange1dthat calculates filled borders based on its fields range_padding, range_padding_unitsand follow_interval, and whether the base scale is linear or logarithmic. But it does not store the calculated values.

So, your only options at this point are either to set the boundaries explicitly for both ranges, or to calculate the boundaries for the additional range based on the above fields DataRange1dand the type of scale.

+1
source

All Articles