Heatmap limit visible rows

Hello everyone.
I was trying to create a heatmap from a dataframe which contains around 10 columns and 300 rows.
I followed this example and I will be using it to further explain my question.

My goal is to limit the user to only see a restricted amount of rows but, at the same time, still be able to navigate through the whole data (with the pan tool for example).
In the provided example it would be refected as being able to only see from January to April (4 rows), February to May, March to June, etc…

The closest I got was to limit the the y_range factors to 4 rows:

y_range = FactorRange(factors=list(reversed(months[0:4])))

But that doesn’t allow me to see the other factors on panning.

Is there any way to do what I desire? And if so, could you let me know how?

Additional Questions:

  • In the same example I see a ColorBar with a specified custom palette. I’m interested in having one but as a gradient (without the ticks, as it happens when we use ‘Viridis256’ as palette) with custom colors as well. Is that something we can do? And if so, how?

Thanks

I don’t think there’s a nice way of doing that right now since start and end properties of FactorRange are not writable. It should be possible to work around that but I’m pretty sure it would require quite a bit of JavaScript.
There’s this issue https://github.com/bokeh/bokeh/issues/9254 which sounds similar and has the same root cause. Although the actual problem there is different.
Please feel free to create a feature request on GitHub that better reflects your need.

I don’t think there’s any way to create a true gradient without creating custom color mapper models but at the very least you can remove all the ticks by just specifying ticker=BasicTicker(desired_num_ticks=0).

1 Like

Thank you for the quick reply. I already opened the feature request in bokeh github.
As a workaround, do you think it would be possible to provide the full data in the histogram and programmatically perform an (initial) zoom (I’m asking this because if I manually zoom the histogram I can achieve what I desire)? Unfortunately, I couldn’t find a way to zoom using the bokeh python API, are you aware of any method to achieve that?
Thanks

do you think it would be possible to provide the full data in the histogram and programmatically perform an (initial) zoom

Yes, that’s what I meant by “It should be possible to work around that but I’m pretty sure it would require quite a bit of JavaScript.”

The bit that I fail to understand is how the JavaScript gets involved in here.
I’m generating the heatmap on the server-side using the python bokeh module, saving it as a HTML file, and providing it to the client by embedding the page in an ‘iframe’.
Ideally, the HTML file would be generated already with the initial zoom applied to it (using python). Is this possible?
If not, could you point me to the javascript command that would affect the zoom of the plot?
Thanks

with the initial zoom applied to it (using python).

The start and end properties of FactorRange are read-only on Python side. How are you going to change them?
And you cannot “use” a tool via Python.

could you point me to the javascript command that would affect the zoom of the plot?

It’s not a single command. As I said, it would require quite a bit of JavaScript. And I don’t know it offhand, otherwise I would’ve posted it right then and there. It would require me hours to come up with it.

1 Like