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 [FEATURE] Add functionality to allow FactorRange.start/end to be writable. Ā· Issue #9254 Ā· bokeh/bokeh Ā· GitHub 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