I see examples on how to edit the extents (aka axis limits) on single objects like Images or Histograms in holoviews such as this answer on stack exchange for histogram extents. What about if you want to apply this to something more complicated like an NdOverlay or HoloMap object? Essentially, I want to apply limits to an entire axis or figure, without worrying about every element I might have in said axis or figure.
For example, suppose I have the following, and want to remove the suppressed zero on the axis:
df = pd.DataFrame({'A':[1,2,3,1,2,3],'B':[4,5,6,1,4,9],'C':['a','a','a','b','b','b']})
tbl = hv.Table(df)
fig = tbl.to.curve(kdims=['A'],vdims=['B'],mdims=['C']).overlay()
fig *= hv.Points([(3,4),(5,6),(1,3)])
fig
What is the best way to apply custom plot limits to multi-element objects like this overlay, or to a HoloMap? I'd prefer not to have to filter the data, since this can be cumbersome if you are doing exploratory work combining multiple data-sources. Do I need to apply an extents keyword to each component, or is there an easy way to broadcast it to the whole figure?
Thanks for any assistance.
The easiest way to specify explicit axis limits in recent versions of HoloViews is using xlim
and ylim
options:
df = pd.DataFrame({'A':[1,2,3,1,2,3],'B':[4,5,6,1,4,9],'C':
['a','a','a','b','b','b']})
tbl = hv.Table(df)
fig = tbl.to.curve(kdims=['A'],vdims=['B'],mdims=['C']).overlay()
fig *= hv.Points([(3,4),(5,6),(1,3)])
fig.opts(xlim=(0, 6), ylim=(0, 10))
Another option (which also works in older versions) is to use the redim
method (assuming you're using a recent dev release of HoloViews). In your case that would look something like this:
df = pd.DataFrame({'A':[1,2,3,1,2,3],'B':[4,5,6,1,4,9],'C':
['a','a','a','b','b','b']})
tbl = hv.Table(df)
fig = tbl.to.curve(kdims=['A'],vdims=['B'],mdims=['C']).overlay()
fig *= hv.Points([(3,4),(5,6),(1,3)])
fig.redim(A=dict(range=(0, 6)), B=dict(range=(0, 10)))
The redim
method recursively iterates over your object and lets you override any Dimension parameters including the ranges in this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With