# Problem with hover display in heatmap with plotlyjs backend

**URL:** <https://discourse.julialang.org/t/problem-with-hover-display-in-heatmap-with-plotlyjs-backend/107586>\
**Category:** Visualization\
**Tags:** plots, plotlyjs\
**Created:** [December 13, 2023, 9:37pm UTC](https://discourse.julialang.org/t/problem-with-hover-display-in-heatmap-with-plotlyjs-backend/107586 "2023-12-13T21:37:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![adannenberg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adannenberg/32/7869_2.png) [@adannenberg](https://discourse.julialang.org/u/adannenberg)\
**Post date:** [December 13, 2023, 9:37pm UTC](https://discourse.julialang.org/t/problem-with-hover-display-in-heatmap-with-plotlyjs-backend/107586/1 "2023-12-13T21:37:42Z")

</div>

if i use the plotly backend to make a heatmap with a small number of categorical variables then everything is fine

```julia
using Plots
plotly()

categories = string.(collect('a':'e'))
n = length(categories) #5
heatmap(categories, categories, rand(n,n))

```

which is to say that the hover always shows the x and y categories and the value

 ![Screenshot 2023-12-13 at 4.27.19 PM](https://global.discourse-cdn.com/julialang/original/3X/7/9/79f399b1b66c5a32c36335b00bf31be3e7468489.png)

But when the number of categories becomes large then the x and y axes are, very reasonably, labeled with only a subset of the categories. That’s fine, but the problem is that the hover display doesn’t show the underlying category unless it happens to be displayed along the axis:

```julia
categories = string.(collect('a':'z'))
n = length(categories) #26
heatmap(categories, categories, rand(n,n))

```

gives

 ![Screenshot 2023-12-13 at 4.32.40 PM](https://global.discourse-cdn.com/julialang/original/3X/0/d/0deaa1850312a8194de8d08b0bce456e006da5b1.png)  
or  
 ![Screenshot 2023-12-13 at 4.33.04 PM](https://global.discourse-cdn.com/julialang/original/3X/0/d/0db50a7bb7a155156ab95b281b3d5eacd9949dc3.png)

**Finally, my question:** Is there a way to force the heatmap function to display the underlying categories even when the categorical values of the x and/or y coords are not displayed along the axis?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 13, 2023, 10:17pm UTC](https://discourse.julialang.org/t/problem-with-hover-display-in-heatmap-with-plotlyjs-backend/107586/2 "2023-12-13T22:17:41Z")

</div>

You can try this:

```julia
using Plots; plotly()
categories = 'a':'z'
n = length(categories) #26
t = (0.5:(n-0.5), categories)
heatmap(categories, categories, rand(n,n), ticks=t)

```

---

<div class="post-metadata">

**Author:** ![adannenberg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adannenberg/32/7869_2.png) [@adannenberg](https://discourse.julialang.org/u/adannenberg)\
**Post date:** [December 13, 2023, 10:26pm UTC](https://discourse.julialang.org/t/problem-with-hover-display-in-heatmap-with-plotlyjs-backend/107586/3 "2023-12-13T22:26:38Z")

</div>

That’s great, thank you.

---

<div class="post-metadata">

**Author:** ![adannenberg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adannenberg/32/7869_2.png) [@adannenberg](https://discourse.julialang.org/u/adannenberg)\
**Post date:** [April 12, 2024, 7:15pm UTC](https://discourse.julialang.org/t/problem-with-hover-display-in-heatmap-with-plotlyjs-backend/107586/4 "2024-04-12T19:15:03Z")

</div>

I’d like to re-open this because I’m confused again. The solution provided for @rafael.guerra works great when the number of categories is relatively small.

But if, for example, I do

```julia
using Plots; plotly()
categories = collect(Iterators.flatten(('a':'z', 'A':'Z','0':'9')))
n = length(categories) #62
t = (0.5:(n-0.5), categories)
heatmap(categories, categories, rand(n,n), ticks=t)

```

then the x and y-axis tick marks become very congested.

 ![Screenshot 2024-04-12 at 2.57.23 PM](https://global.discourse-cdn.com/julialang/original/3X/8/0/808f2d0066d900cb50d9fffff7dca18604402442.png)

But if I ‘thin out’ the tick marks by choosing, for example

```julia
indx = 1:10:length(categories)
subset_of_categories = categories[indx]
nsub = length(subset_of_categories)
t = (collect(indx) .- 0.5, subset_of_categories)

```

then the hover display only shows the category label for points that happen to have an x-value or y-value for which there’s a tickmark. Otherwise you just see a number.

 ![Screenshot 2024-04-12 at 3.11.25 PM](https://global.discourse-cdn.com/julialang/original/3X/3/1/31d26062edd8eee7ea6a52d72eca0edef612ea7e.png)

MY QUESTION: Is there a “best of both worlds” choice of settings that leave the tickmarks on the axes as something reasonable (as is automatically the case when we omit the ticks argument to `heatmap`) but still shows the x and y category labels when I hover over an arbitrary point in the heatmap(as is the case when the tickmarks include all labels)?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 12, 2024, 9:57pm UTC](https://discourse.julialang.org/t/problem-with-hover-display-in-heatmap-with-plotlyjs-backend/107586/5 "2024-04-12T21:57:49Z")

</div>

Try increasing the plot size by calling `heatmap()` with the keyword argument `size=(1200,1200)` or larger.

---

<div class="post-metadata">

**Author:** ![adannenberg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adannenberg/32/7869_2.png) [@adannenberg](https://discourse.julialang.org/u/adannenberg)\
**Post date:** [April 12, 2024, 11:03pm UTC](https://discourse.julialang.org/t/problem-with-hover-display-in-heatmap-with-plotlyjs-backend/107586/6 "2024-04-12T23:03:14Z")

</div>

This was just a minimal example of the issue… In my actual use case I have a date range as the categorical variable on 1 axis and discrete numerical variable on the other axis. So there are hundreds of discrete categorical variables. Which means I can’t make my plot big enough to prevent the tick marks from being congested 😃

I like using `heatmap` in addition to `surface` because the two visualization tools help me develop intuition and aid pattern recognition in _different_ ways. And if I call

```julia
z = [sqrt(x^2 + y^2) for y in 1:n, x in 1:n]
surface(categories, categories, z, ticks=:native)

```

then all is well, i.e. the x and y axis ticks are subset reasonably AND mouseover shows the categories rather than numbers for the x and y coord of the surface plot.

But `ticks=:native` doesn’t work with `heatmap` :\< . I don’t know why that would be, since a `heatmap` is just a visually “flattened” version of a `surface` plot. But, in any case, I’m simply wondering if there’s a way to get the equivalent of `ticks = :native` behavior in `heatmap`…

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 12, 2024, 11:07pm UTC](https://discourse.julialang.org/t/problem-with-hover-display-in-heatmap-with-plotlyjs-backend/107586/7 "2024-04-12T23:07:11Z")

</div>

If you’re using dates, [try this solution](https://discourse.julialang.org/t/plots-jl-plotly-heatmap-labels/106252/2) for getting `:native` working.

---

<div class="post-metadata">

**Author:** ![adannenberg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adannenberg/32/7869_2.png) [@adannenberg](https://discourse.julialang.org/u/adannenberg)\
**Post date:** [April 13, 2024, 1:56am UTC](https://discourse.julialang.org/t/problem-with-hover-display-in-heatmap-with-plotlyjs-backend/107586/8 "2024-04-13T01:56:59Z")

</div>

No. That doesn’t deal with the problem. But thank you for trying to help. I appreciate the generosity.
