4

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?

katahdin
  • 389
  • 7
  • 16

2 Answers2

3

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

philippjfr
  • 3,997
  • 14
  • 15
1

The easiest way is probably by adding .opts(xlim=(0.002, 0.016)) to your plot, like so:

hv.Histogram((frequencies, edges)).opts(xlim=(0.002, 0.016))

You can do the same for ylim, for example:

 .opts(xlim=(0.002, 0.016), ylim=(0, 300))

This is all very similar to matplotlib.

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96