Change x-axis (xlim) on holoviews histogram

2019-07-08 11:06发布

问题:

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)

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:

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