Change x-axis (xlim) on holoviews histogram

2019-07-08 10:52发布

In matplotlib we can change the limits of the x-axis with the xlim() method. Is there an equivalent method in HoloViews?

I searched the HV options page, but didn't find anything that seemed to do this.

I created the image below with the following code in a Jupyter notebook:

import numpy as np
import holoviews as hv
hv.notebook_extension('bokeh', width=90)

values = np.array([list of floats])

frequencies, edges = np.histogram(values, 10)
hv.Histogram(frequencies, edges)

histogram

How can I change the x-axis limit to [0.002, 0.016].

Also, is it possible to get a plot to return its current x-axis limit?

1条回答
在下西门庆
2楼-- · 2019-07-08 11:34

HoloViews will usually just use the bounds of the data you give it. So the easiest way to change the bounds of a histogram is to change it in the np.histogram call itself:

frequencies, edges = np.histogram(values, 10, range=(0.002, 0.016))
hv.Histogram(frequencies, edges)

If you simply want to change the viewing extents you can do also set those directly:

hv.Histogram(frequencies, edges, extents=(0.002, None, 0.016, None))

where extents is defined as (xmin, ymin, xmax, ymax).

查看更多
登录 后发表回答