How to control Holoviews y-tick format?

2019-07-29 19:58发布

I am trying to gain control of the Holoviews Curve (though this should work for any other plotting element) and set the y-tick labels to be in scientific notations.

In MatPlotLib I would do this with ticklabel_format(style='sci', axis='y', scilimits=(0,0)).

Currently I have this:

Current Holoview y-ticks

But would like the Y axis numbers to be in scientific notations instead of the long decimal numbers currently shown on the Y axis.

Is there anyway to do this and what is it?

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-07-29 20:22

HoloViews let's you supply a tick formatter directly on a Dimension, so you can do something like this:

from matplotlib.ticker import ScalarFormatter
yfmt = ScalarFormatter()
yfmt.set_powerlimits((0,0))
yfmt.set_scientific(True)
hv.Curve(np.random.rand(10), vdims=[hv.Dimension('y', value_format=yfmt)])

If you ever find options that you can't control directly you can always attach hooks on your Element, which will give you direct control over the plotting object, e.g.:

def sciticks(plot, element):
    plot.handles['axis'].ticklabel_format(style='sci', axis='y', scilimits=(0,0))

hv.Curve(np.random.rand(10,2))(plot=dict(final_hooks=[sciticks])) 

The plot argument to the callback function is the HoloViews plotting class, which will let you access various plotting objects on its handles attribute. The handles contain various important plot objects, for example the 'axis' keyword corresponds to the matplotlib Axes object, but among other things you can also access and modify the Figure using 'fig' and the Artist using 'artist'.

查看更多
登录 后发表回答