Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting x and y labels with holoviews

I would like to change the labels on the x and y axis on a figure from holoviews to be something other than the internal variable name. It seems the typical way to affect the axis labels is to change the variable names themselves to the label. This is rather inconvenient if you want complex labels, especially if you are frequently converting from other complex data objects like pandas dataframes.

Is there a general way to either: (A) change x and y labels of a figure as or after you plot it or (B) set up an human readable alias for variable names?

like image 638
Caleb Avatar asked Dec 05 '16 16:12

Caleb


Video Answer


2 Answers

You can change the axis labels as or after you plot a figure like this for example

hv.Image(np.random.rand(10,10), kdims=['x','y']).redim.label(x='neXt', y='Ys')

EDIT: In earlier versions of HoloViews you are able to change the axis labels easily like this, check the second answer on Holoviews FAQ

curve = hv.Curve(df, 'x_col', 'y_col')
curve = curve.options(xlabel='X Label', ylabel='Label for Y')
like image 110
Nelson Rodrigues Avatar answered Oct 02 '22 16:10

Nelson Rodrigues


There are indeed dimension aliases in HoloViews, although we should document them better. There are two ways of defining them. You can either supply a tuple of the form (name, label) as a dimension or explicitly declare an Aliases object and supply the attribute. Here is a simple example:

aliases = hv.util.Aliases(x='Some long label')
hv.Image(np.random.rand(10,10), kdims=[aliases.x, ('y', 'Inline label')])

The plotting code will use the long label, and you'll be able to refer to either the name or the label when using the object's methods. You can also supply a tuple to a dimension directly: hv.Dimension(('name', 'label'), range=(0,10)) if you also want to define a range or other Dimension parameter.

like image 34
philippjfr Avatar answered Oct 02 '22 16:10

philippjfr