Pill-GZ
September 23, 2021, 7:48pm
1
Is there a way to access the option values associate with an existing figure?
E.g., for setting the axis ranges of a plot, we can use redim.
https://holoviews.org/user_guide/Customizing_Plots.html#Axis-ranges
But how do we get the current axis range of a plot, or an Overlay?
E.g., for setting the axis labels, we can use relabel.
https://holoviews.org/user_guide/Customizing_Plots.html#Axis-labels
But how do we get the current axis labels of a plot, or an Overlay?
etc…
I tried looking at dir
of the figure objects but could not figure out how these metadata are stored.
Is there an easy way to access these option values?
Thanks!
1 Like
Maybe
import holoviews as hv
hv.extension("bokeh")
curve = hv.Curve(([0, 1, 2], [3, 4, 5])) * hv.Scatter(([0, 3, 5], [6, 7, 8])).opts(xlim=(150, 200), xlabel="hey").redim(**{"y": "ylabel"})
print(curve.opts.info())
print(curve.dimensions())
import holoviews as hv
hv.extension("bokeh")
curve = hv.Curve(([0, 1, 2], [3, 4, 5])) * hv.Scatter(([0, 3, 5], [6, 7, 8])).opts(xlim=(150, 200), xlabel="hey").redim(**{"y": "ylabel"})
print(curve.opts.info())
print(curve.dimensions())
for dim in curve.dimensions():
print(curve.range(dim))
:Overlay
.Curve.I :Curve [x] (y)
.Scatter.I :Scatter [x] (ylabel)
| Options(xlabel='hey', xlim=(150, 200))
None
[Dimension('x'), Dimension('y'), Dimension('ylabel')]
(0.0, 5.0)
(3.0, 5.0)
(6.0, 8.0)
I’m trying to find the initial xlim/ylim values of a plot. After pounding away at this for a while, I finally came across Plot Hooks . These allow you to drill down to the extension (i.e., matplotlib, bokeh, etc.) attributes.
For example:
import numpy as np
import panel as pn
pn.extension()
import holoviews as hv
hv.extension('bokeh')
xs = np.linspace(1, 100, 5)
def hook(plot, element):
print('plot.state: ', plot.state)
print('plot.handles: ', sorted(plot.handles.keys()))
print('plot.handles.x_range: ', plot.handles['x_range'])
print(plot.handles['x_range'].__dict__)
print(plot.handles['x_range'].start)
print(plot.handles['x_range'].end)
curve = hv.Points((xs, xs / 3), ['X', 'Y']).opts(hooks=[hook])
print(curve.range('X'))
print(curve.range('Y'))
pn.Row(curve).servable()
Notice the holoviews’ call curve.range()
gives you the data limits, not the axis limits.
1 Like
Theom
July 3, 2023, 7:50am
4