I've been trying for hours to figure out how to change the x-axis range dynamically (with a DynamicMap). But nowhere on the user guide can I find examples of how to do this! It seems like it should be the easiest thing.
Agreed, this deserves more discussion and at minimum a major section in the documentation. I think what you are looking for is the {+framewise} normalization option, e.g.:
%%opts Curve {+framewise}
hv.DynamicMap(lambda i: hv.Curve(np.arange(i)), kdims=['i']).redim.range(i=((10, 20)))
Using the .opts method you can do it like this:
hv.DynamicMap(lambda i: hv.Curve(np.arange(i)), kdims=['i']).redim.range(i=((10, 20))).opts(norm=dict(framewise=True))
Thank you, didn't know that existed, but it worked for me! I'm new to HoloViews, and actually the live plotting is what drove me to Bokeh, which led to HoloViews. The streaming functionality is a big pro, especially because it seems that Matplotlib doesn't have very good options and Plotly is either non-offline or paid.
Thank you, didn't know that existed
That's our fault and we'll have to make this more obvious or find a more obvious way to control this. Great to hear HoloViews is addressing your problems. If you run into more issues please don't hesitate to file issues or ask us a question on Gitter.
@philippjfr So is this not something that can be passed directly into a function or into an %%opts magic? If I read @nikhilxb 's question correctly, this seems to be intuitive disconnect, that something like axis ranges are not a customisation option I can access directly as I can line_color, width, etc.
I would never have thought of looking into .redim.range() ...
Is there a design choice behind this or are we missing something?
... also ... recently started using HoloViews, and I think your work and ideas on this are great.
@maegul Sorry for the delay on my reply, that is a sensible point and I would not actually object to adding explicit range plot options, particularly once we have completely deprecated the extents parameter on elements (I don't want three different ways to set the axis ranges). That said the range and soft_range are often things that are associated directly with a dimension and that you want to control at that level so I still think they are appropriate there.
I think Charts need a first class way to set their Axes ranges. A Chart is a "view" on some dimensions/metrics that are part of a data "model". range and soft_range are attributes of a dimension, which is an aspect of the data model. A Chart can Inhert/Infer its default axis range from the data dimension range. But the Chart axis range belongs to the view and needs to be explicitly set. Think of two charts/views linked to the same data dimension/model. One chart/view could be set to zoom in on one range of data, while the other could be set to zoom out.
To make the idea of Inherit/Infer more general, think of the this transformation from model to view as something an advanced user needs to have control, i.e. a user defined function. For example, the Y-axis range should "go from 0 to the 95%-tile of the data values". The default behavior is for the Chart to inherit the axis range from the dimension, but the advance user should be able to override this behavior. Maybe the generic transformation between model and view attributes could be handled by the proposed "op" functions #2152
I'd also be glad to be able to explicitly set the limits on the axes; I was surprised I couldn't find a way to do that with %%opts somehow. I have a Scatter chart that's cutting off the edges of my data, and zooming out a little each time I plot isn't nearly as nice as being able to adjust the limits (especially if I could do this by percentiles instead of having to calculate the min and max value for each axis to put this in %%opts).
(especially if I could do this by percentiles instead of having to calculate the min and max value for each axis to put this in %%opts).
The next release will have an option for dimension range padding: https://github.com/ioam/holoviews/pull/2293
I've still not been able to find out how to set limits for the default plotting ranges - I don't understand how this "framework" method is supposed to work? Maybe this could be something that you could also address in "Customizing Plots" where no explicit example is given?
Say for the example:
import numpy as np
import holoviews as hv
hv.extension('bokeh')
xs = np.linspace(-np.pi,np.pi,100)
curve = hv.Curve((xs, xs/3))
curve
ranges for x: (-4,4), ranges for y: (-1.5,1.5).
Ok, finally figured it out.
xs = np.linspace(-np.pi,np.pi,100)
curve = hv.Curve((xs, xs/3), extents = (-4,-1.5,4,1.5))
curve
I still think an explicit example should be given in "Customizing Plots"!
Totally agree with you on Customizing plots having a section on this. Also note that extents is now by far the least preferred way of setting plot limits. The preferred approaches are:
xdim = hv.Dimension('x_dim', range=(-4, 4))
ydim = hv.Dimension('y_dim', range=(-1.5, 1.5))
hv.Curve((xs, xs/3), xdim, ydim)
redim.range:hv.Curve((xs, xs/3), 'xdim', 'ydim').redim.range(xdim=(-4, 4), ydim=(-1.5, 1.5))
xlim and ylim plot options, which will be supported once 1.11 is released:hv.Curve((xs, xs/3), 'xdim', 'ydim').options(xlim=(-4, 4), ylim=(-1.5, 1.5))
Any chance the xlim and ylim options will be available on the Overlay object with 1.11?
Any chance the xlim and ylim options will be available on the Overlay object with 1.11?
They will be yes. The semantics of xlim/ylim are such that setting it on any Element in an Overlay will override the ranges on any other Element in that Overlay, and setting it on the Overlay itself overrides everything.
This has been documented in FAQ items and in the docs now.
Most helpful comment
Totally agree with you on Customizing plots having a section on this. Also note that
extentsis now by far the least preferred way of setting plot limits. The preferred approaches are:redim.range:xlimandylimplot options, which will be supported once 1.11 is released: