holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.71k stars 403 forks source link

Unable to control minor ticks on HeatMap #5261

Open jbednar opened 2 years ago

jbednar commented 2 years ago

According to https://holoviews.org/user_guide/Customizing_Plots.html#font-sizes, there are plot options to control minor_xticks and minor_ticks, but I can't find anything to control the minor ticking behavior on a HeatMap:

import numpy as np, holoviews as hv
hv.extension('bokeh', width=100)

data = [(i, chr(97+j),  i*j) for i in range(5) for j in range(5) if i!=j]
hm = hv.HeatMap(data).sort().opts(width=200, height=200)
(hm.options(xticks=0) + hm.options(xticks=1) + hm.options(xticks=2) + hm.options(xticks=4) +  hm.options(xticks=5)).cols(5)
image

I.e., the only option available appears to be xticks, but apart from the default (with lots of minor ticks) and 0 (with no ticks at all), there don't seem to be any useful values for a heatmap. A value of 1 seems broken, in that it puts ticks but only labels one of them, and none of the other values achieve having one tick per cell in this plot, which is what I was trying to achieve, i.e. the default for the Matplotlib backend:

image

marcbernot commented 2 years ago

In the exemple, the x-axis is a LinearAxis. This seems problematic ; shouldn't both axes be CategoricalAxis (as stated in the documentation you link to)? And then, this would be logical that there is no notion of minor_ticks.

import holoviews as hv
import pandas as pd

hv.extension('bokeh', width=100)
data = [(i, chr(97+j),  i*j) for i in range(5) for j in range(5) if i!=j]
hm = hv.HeatMap(data)

df = pd.DataFrame(data,columns = ['x','y','z'])
hm = hv.HeatMap(df)

brenderer = hv.renderer('bokeh')
fig = brenderer.get_plot_state(hm)
fig.axis

result is [LinearAxis(id='1673', ...), CategoricalAxis(id='1677', ...)].

The figure you look for can be achieved by casting df['x'] = df['x'].astype(str). However I think, this should work with no explicit casting (or such a casting should be taken care of by holoviews).

Besides, I noticed that an alternative casting df.x = pd.Categorical(df.x) was giving a warning and a LinearAxis where we could expect no warning and two CategoricalAxis.

jbednar commented 2 years ago

Sounds like a good explanation to me. Something to fix in HoloViews's Bokeh plotting for HeatMaps, then?