Setting x and y labels with holoviews

拈花ヽ惹草 提交于 2019-12-05 05:16:34

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')

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.

You can change x and y labels by providing a tuple of the column name and the longer label you would like to be displayed:

import numpy as np
import pandas as pd
import holoviews as hv
hv.extension()

data = np.random.normal(size=[50, 2])
df = pd.DataFrame(data, columns=['col1', 'col2'])

hv.Points(
    df, 
    kdims=[('col1', 'long label of col1'), ('col2', 'long label of col2')]
)

Other alternatives are in this question:
An elegant way to add long names and units to plots with Holoviews

This results in the following plot:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!