I’m trying to add a second vertical axes to a simple lineplot showing temperature values in Celcius and Fahrenheit. But if you zoom into the areas marked with red circles you’ll see that the second (right) axis’ range is mapped to the entire plot height instead of only the range between minimum and maximum tick (or data) values of the original (left) axis. Please see attached sample code. Is there an easy fix to solve that?
The problem stems from the fact that the default ranges are "DataRanges" they try to automatically determine the envelope of all data, plus add a little padding, so that everything shows up comfortably in the plot automatically. So if you look carefully, you will notice the initial celsius bounds are not (0,100) they are slightly bigger than that. But you do set the Fahrenheit bounds explicitly to what should be (0,100):
So to fix this, you can set the celsius range explicitly so that the initial ranges line up correctly (and the initial ranges are what determines the relative scaling when zooming, e.g). You can do this either by passing
y_range=(0,100)
to the figure function call, or by setting the y_range attribute after the fact:
I'm trying to add a second vertical axes to a simple lineplot showing temperature values in Celcius and Fahrenheit. But if you zoom into the areas marked with red circles you'll see that the second (right) axis' range is mapped to the entire plot height instead of only the range between minimum and maximum tick (or data) values of the original (left) axis. Please see attached sample code. Is there an easy fix to solve that?
Let’s say I want to keep some padding, though, for better optical results. This DataRange1D class in http://bokeh.pydata.org/en/dev/docs/reference/models/ranges.html should come in handy. In fact, I can add this to the left axis easily like this (overwriting the default value, I suppose):
But it’s not clear where to add the same for the second (right) axis. I’ve tried in LinearAxis, but no luck. Is that possible, too?
Thanks!
Bryan Van de ven:
···
So to fix this, you can set the celsius range explicitly so that the initial ranges line up correctly (and the initial ranges are what determines the relative scaling when zooming, e.g). You can do this either by passing
y_range=(0,100)
to the figure function call, or by setting the y_range attribute after the fact:
I would say it is currently problematic to get twin axes working correctly with DataRanges. The reason is because the computed range is not known on the python side, it is computed in the browser. So there is no ahead of time to know what to set the second range limits too. It's possible there could be some nice way to express a scaling linkage explicitly, but this would be new development. For now I think you will have to set all the ranges explicitly.
Let's say I want to keep some padding, though, for better optical results. This DataRange1D class in http://bokeh.pydata.org/en/dev/docs/reference/models/ranges.html should come in handy. In fact, I can add this to the left axis easily like this (overwriting the default value, I suppose):
But it's not clear where to add the same for the second (right) axis. I've tried in LinearAxis, but no luck. Is that possible, too?
Thanks!
Bryan Van de ven:
So to fix this, you can set the celsius range explicitly so that the initial ranges line up correctly (and the initial ranges are what determines the relative scaling when zooming, e.g). You can do this either by passing
y_range=(0,100)
to the figure function call, or by setting the y_range attribute after the fact:
I would say it is currently problematic to get twin axes working correctly with DataRanges. The reason is because the computed range is not known on the python side, it is computed in the browser. So there is no ahead of time to know what to set the second range limits too. It’s possible there could be some nice way to express a scaling linkage explicitly, but this would be new development. For now I think you will have to set all the ranges explicitly.