Changing ticks mark period in Holoviews heatmap

被刻印的时光 ゝ 提交于 2019-12-08 11:28:16

问题


I have the following heatmap made by Holoviews. I need to change x ticks to change the period of x ticks. [0,2,4,...] instead of [0,1,2,3,4,..]

data = [(i, j,  i*j) for i in range(10) for j in range(10)]
hv.HeatMap(data)

Change from this graph

To this graph


回答1:


It seems that bokeh doesn't provide such function. However you can change the doFormat function of xaxis.formatter before draw the plot.

After run the following cell:

from bokeh.models import CustomJS
import holoviews as hv
hv.extension("bokeh")

def change_formatter(p, o):
    fig = p.handles["plot"]

    def callback(fig=fig):
        def do_format(t, e):
            return [label if i % 2 == 0 else "" for i, label in enumerate(t)]

        fig.renderers[0].formatter.doFormat = do_format    
    fig.js_on_change("inner_width", CustomJS.from_py_func(callback))

%opts HeatMap [finalize_hooks=[change_formatter]]

plot the HeatMap:

data = [(i, j,  i*j) for i in range(10) for j in range(10)]
hv.HeatMap(data)    

here is the output:



来源:https://stackoverflow.com/questions/49211006/changing-ticks-mark-period-in-holoviews-heatmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!