Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Sep 4, 2025

HeatMap is currently rendered using rect glyphs. This approach is flexible, since it allows the heatmap to be overlaid on arbitrary categorical axes, and each rectangle is drawn independently of the axis ordering. However, for large heatmaps with many categories, it becomes extremely inefficient: each rectangle (pixel) must be sent and rendered individually, which both increases data transfer and slows down rendering. To address this, we’ve added a new code path that is used when the HeatMap is already gridded and the data is contiguous with respect to the x- and y-axis factors.

Example

import numpy as np

arr = np.ones((10, 12)) * np.arange(12) * np.atleast_2d(np.arange(10)).T
hm_data = (list(map(str, range(12))), [chr(65+i) for i in range(10)], arr)

hv.HeatMap(hm_data) * hv.Points([('0', 'A'), ('11', 'E'), ('12', 'F')]).opts(color='red')
bokeh_plot - 2025-09-04T124540 963

ToDo

  • Fix hover support
  • Ensure invert_axes is handled correctly
  • Ensure invert_xaxis and invert_yaxis are handled correctly
  • Add tests

Observations

In implementing this I found a fairly undesirable behavior of our axis range/factor calculations. Specifically because we accumulate the ranges by element type the ordering of factors is not preserved correctly if there is a layer above and below that are of the same type.

As an example here we have Points * HeatMap * Points:

hv.Points([('-1', '@')]) * hv.HeatMap(data) * hv.Points([('0', 'A'), ('11', 'E'), ('12', 'F')])
bokeh_plot - 2025-09-04T125023 924

because the factors of the Points are jointly calculated we end up with the x-axis order starting as [-1, 0, 11, 12, ...] rather than the [-1, 0, 1, 2, ...] ordering you'd expect if you calculated the element factors in sequence. In this case, this causes the heatmap to be non-contiguous, disabling the optimized codepath.

@philippjfr philippjfr changed the title Optimize HeatMap rendering path if gridded and contiguous enh: Optimize HeatMap rendering path if gridded and contiguous Sep 4, 2025
@philippjfr philippjfr added tag: component: plotting type: enhancement Minor feature or improvement to an existing feature labels Sep 4, 2025
@philippjfr philippjfr added this to the 1.22.0 milestone Sep 4, 2025
Copy link
Member

@hoxbro hoxbro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments.

I can't think of a better way to get HoverTool to work than using CustomJS.

@philippjfr
Copy link
Member Author

I can't think of a better way to get HoverTool to work than using CustomJS.

I can, will give that a shot.

Copy link

codecov bot commented Sep 11, 2025

Codecov Report

❌ Patch coverage is 80.17241% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.00%. Comparing base (365b4a4) to head (d8a6a63).

Files with missing lines Patch % Lines
holoviews/plotting/bokeh/heatmap.py 82.14% 15 Missing ⚠️
holoviews/core/util/__init__.py 11.11% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6680      +/-   ##
==========================================
- Coverage   89.02%   89.00%   -0.03%     
==========================================
  Files         329      329              
  Lines       70422    70500      +78     
==========================================
+ Hits        62693    62748      +55     
- Misses       7729     7752      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hoxbro hoxbro force-pushed the heatmap_raster_path branch from a497c20 to 520c323 Compare September 11, 2025 12:03
@hoxbro hoxbro changed the title enh: Optimize HeatMap rendering path if gridded and contiguous enh(bokeh): Optimize HeatMap rendering path if gridded and contiguous Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tag: component: plotting type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants