How to add a histogram to just the x-axis?

Hi! I’m wondering how I add a histogram to just the x-axis.

Surprisingly (to me) this adds a histogram to the y-axis:

import holoviews as hv
import vega_datasets

iris = vega_datasets.data.iris()

hv.Points(iris[["sepalLength", "sepalWidth"]]).hist("sepalLength")

As does this:

pts = hv.Points(iris[["sepalLength", "sepalWidth"]])
xhist = hv.operation.histogram(pts, dimension="sepalLength")
pts << xhist

How do I attach a histogram to just the x-axis without also having a histogram on the y-axis?

I also wonder how this can be done.
The only documentation I could find about hv.AdjointLayout() is: http://holoviews.org/reference/elements/bokeh/Histogram.html

I noticed there’s 3 positions in a AdjointLayout: ‘main’, ‘right’ and ‘top’.
So I wonder if there’s a way to point out specifically which plot should go where in the AdjointLayout.

1 Like

So AdjointLayout is kind of unfortunate in its design, the easiest way to do this is to adjoin an Empty element in the position on the right:

scatter = hv.Scatter(np.random.rand(100, 2))

scatter << hv.Empty() << scatter.hist(adjoin=False)

Hello,
I noticed that it does not work and throws an Attribute Error

Python 3.7
panel==0.10.1
holoviews==1.13.4
bokeh==2.2.3

AttributeError                            Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

/opt/conda/lib/python3.7/site-packages/holoviews/core/dimension.py in _repr_mimebundle_(self, include, exclude)
   1310         combined and returned.
   1311         """
-> 1312         return Store.render(self)
   1313 
   1314 

/opt/conda/lib/python3.7/site-packages/holoviews/core/options.py in render(cls, obj)
   1392         data, metadata = {}, {}
   1393         for hook in hooks:
-> 1394             ret = hook(obj)
   1395             if ret is None:
   1396                 continue

/opt/conda/lib/python3.7/site-packages/holoviews/ipython/display_hooks.py in pprint_display(obj)
    280     if not ip.display_formatter.formatters['text/plain'].pprint:
    281         return None
--> 282     return display(obj, raw_output=True)
    283 
    284 

/opt/conda/lib/python3.7/site-packages/holoviews/ipython/display_hooks.py in display(obj, raw_output, **kwargs)
    253     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
    254         with option_state(obj):
--> 255             output = layout_display(obj)
    256     elif isinstance(obj, (HoloMap, DynamicMap)):
    257         with option_state(obj):

/opt/conda/lib/python3.7/site-packages/holoviews/ipython/display_hooks.py in wrapped(element)
    144         try:
    145             max_frames = OutputSettings.options['max_frames']
--> 146             mimebundle = fn(element, max_frames=max_frames)
    147             if mimebundle is None:
    148                 return {}, {}

/opt/conda/lib/python3.7/site-packages/holoviews/ipython/display_hooks.py in layout_display(layout, max_frames)
    218         return None
    219 
--> 220     return render(layout)
    221 
    222 

/opt/conda/lib/python3.7/site-packages/holoviews/ipython/display_hooks.py in render(obj, **kwargs)
     66         renderer = renderer.instance(fig='png')
     67 
---> 68     return renderer.components(obj, **kwargs)
     69 
     70 

/opt/conda/lib/python3.7/site-packages/holoviews/plotting/renderer.py in components(self, obj, fmt, comm, **kwargs)
    393                 doc = Document()
    394                 with config.set(embed=embed):
--> 395                     model = plot.layout._render_model(doc, comm)
    396                 if embed:
    397                     return render_model(model, comm)

/opt/conda/lib/python3.7/site-packages/panel/viewable.py in _render_model(self, doc, comm)
    422         if comm is None:
    423             comm = state._comm_manager.get_server_comm()
--> 424         model = self.get_root(doc, comm)
    425 
    426         if config.embed:

/opt/conda/lib/python3.7/site-packages/panel/viewable.py in get_root(self, doc, comm, preprocess)
    480         """
    481         doc = init_doc(doc)
--> 482         root = self._get_model(doc, comm=comm)
    483         if preprocess:
    484             self._preprocess(root)

/opt/conda/lib/python3.7/site-packages/panel/layout/base.py in _get_model(self, doc, root, parent, comm)
    110         if root is None:
    111             root = model
--> 112         objects = self._get_objects(model, [], doc, root, comm)
    113         props = dict(self._init_properties(), objects=objects)
    114         model.update(**self._process_param_change(props))

/opt/conda/lib/python3.7/site-packages/panel/layout/base.py in _get_objects(self, model, old_objects, doc, root, comm)
    100             else:
    101                 try:
--> 102                     child = pane._get_model(doc, root, model, comm)
    103                 except RerenderError:
    104                     return self._get_objects(model, current_objects[:i], doc, root, comm)

/opt/conda/lib/python3.7/site-packages/panel/pane/holoviews.py in _get_model(self, doc, root, parent, comm)
    227             plot = self._render(doc, comm, root)
    228 
--> 229         plot.pane = self
    230         backend = plot.renderer.backend
    231         if hasattr(plot.renderer, 'get_plot_state'):

/opt/conda/lib/python3.7/site-packages/holoviews/plotting/plot.py in pane(self, pane)
    142             for plot in self.subplots.values():
    143                 if plot is not None:
--> 144                     plot.pane = pane
    145                 if not plot.root:
    146                     continue

/opt/conda/lib/python3.7/site-packages/holoviews/plotting/plot.py in pane(self, pane)
    143                 if plot is not None:
    144                     plot.pane = pane
--> 145                 if not plot.root:
    146                     continue
    147                 for cb in getattr(plot, 'callbacks', []):

AttributeError: 'NoneType' object has no attribute 'root'
1 Like