It isn’t clear to me why xlim(0, 5) is being ignored. When I change this to ylim(0, 0.5) then the horizontal axis is constrained as expected. Does anybody have any suggestions for constraining the xlim for a barh?
Yes this has to do with the axis of a bar plot being categorical (here you’ve got numbers, but you could have an axis that is something like ['Appled', 'Banana', 'Pear']).
There’s another workaround to this issue. hvplot returns objects that are holoviews objects which are not plots but wrappers around your data, and that when displayed in a notebook are turned into plots. That’s a major difference with Matplotlib for instance, with which you get a plot object (Figure/Axes) and can’t do anything with your data anymore. It happens that holoviews objects can be indexed/sliced (Indexing and Selecting Data — HoloViews 1.14.5 documentation), most of its objects support the familiar .iloc method:
import numpy as np
import pandas as pd
import hvplot.pandas
n = 10
tmp_df = pd.DataFrame({"x": np.arange(n) + 1, "y": np.random.rand(n)})
tmp_df.hvplot.barh("x", "y").iloc[:5]