holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.7k stars 402 forks source link

Rectangles + HLine = </3 (with matplotlib) #4979

Open douglas-raillard-arm opened 3 years ago

douglas-raillard-arm commented 3 years ago

ALL software version info

holoviews: 1.14.4 jupyterlab: 2.3.1 bokeh: 2.3.2 matplotlib: 3.4.2

Description of expected behavior and the observed behavior

Code raises exception instead of correctly rendering with matplotlib. Strangely enough, in some notebook a plot is still displayed, but in some others the plot is not displayed at all.

Complete, minimal, self-contained example code that reproduces the issue

import holoviews as hv
hv.extension('matplotlib')
# Removing either the HLine or the label avoid the exception
hv.Rectangles([(0,0,1,1), (2,2,3,3)], label='hello') * hv.HLine(3)

Stack traceback and/or browser JavaScript console output

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
venv-3.9/lib/python3.9/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:

venv-3.9/lib/python3.9/site-packages/holoviews/core/dimension.py in _repr_mimebundle_(self, include, exclude)
   1315         combined and returned.
   1316         """
-> 1317         return Store.render(self)
   1318 
   1319 

venv-3.9/lib/python3.9/site-packages/holoviews/core/options.py in render(cls, obj)
   1403         data, metadata = {}, {}
   1404         for hook in hooks:
-> 1405             ret = hook(obj)
   1406             if ret is None:
   1407                 continue

venv-3.9/lib/python3.9/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 

venv-3.9/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py in display(obj, raw_output, **kwargs)
    250     elif isinstance(obj, (CompositeOverlay, ViewableElement)):
    251         with option_state(obj):
--> 252             output = element_display(obj)
    253     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
    254         with option_state(obj):

venv-3.9/lib/python3.9/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 {}, {}

venv-3.9/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py in element_display(element, max_frames)
    190         return None
    191 
--> 192     return render(element)
    193 
    194 

venv-3.9/lib/python3.9/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 

venv-3.9/lib/python3.9/site-packages/holoviews/plotting/renderer.py in components(self, obj, fmt, comm, **kwargs)
    386             plot = obj
    387         else:
--> 388             plot, fmt = self._validate(obj, fmt)
    389 
    390         data, metadata = {}, {}

venv-3.9/lib/python3.9/site-packages/holoviews/plotting/renderer.py in _validate(self, obj, fmt, **kwargs)
    312                                  renderer=self)
    313         else:
--> 314             plot = self.get_plot(obj, renderer=self, **kwargs)
    315 
    316         all_formats = set(fig_formats + holomap_formats)

venv-3.9/lib/python3.9/site-packages/holoviews/plotting/renderer.py in get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
    241             init_key = tuple(v if d is None else d for v, d in
    242                              zip(plot.keys[0], defaults))
--> 243             plot.update(init_key)
    244         else:
    245             plot = obj

venv-3.9/lib/python3.9/site-packages/holoviews/plotting/mpl/plot.py in update(self, key)
    249     def update(self, key):
    250         if len(self) == 1 and ((key == 0) or (key == self.keys[0])) and not self.drawn:
--> 251             return self.initialize_plot()
    252         return self.__getitem__(key)
    253 

venv-3.9/lib/python3.9/site-packages/holoviews/plotting/mpl/plot.py in wrapper(self, *args, **kwargs)
     45     def wrapper(self, *args, **kwargs):
     46         with _rc_context(self.fig_rcparams):
---> 47             return f(self, *args, **kwargs)
     48     return wrapper
     49 

venv-3.9/lib/python3.9/site-packages/holoviews/plotting/mpl/element.py in initialize_plot(self, ranges)
   1127 
   1128         if self.show_legend and element is not None:
-> 1129             self._adjust_legend(element, axis)
   1130 
   1131         return self._finalize_axis(key, element=element, ranges=ranges,

venv-3.9/lib/python3.9/site-packages/holoviews/plotting/mpl/element.py in _adjust_legend(self, overlay, axis)
   1102             legend_opts = self.legend_opts.copy()
   1103             legend_opts.update(**dict(leg_spec, **self._fontsize('legend')))
-> 1104             leg = axis.legend(list(data.keys()), list(data.values()),
   1105                               title=title, **legend_opts)
   1106             title_fontsize = self._fontsize('legend_title')

venv-3.9/lib/python3.9/site-packages/matplotlib/axes/_axes.py in legend(self, *args, **kwargs)
    288         if len(extra_args):
    289             raise TypeError('legend only accepts two non-keyword arguments')
--> 290         self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
    291         self.legend_._remove_method = self._remove_legend
    292         return self.legend_

venv-3.9/lib/python3.9/site-packages/matplotlib/legend.py in __init__(self, parent, handles, labels, loc, numpoints, markerscale, markerfirst, scatterpoints, scatteryoffsets, prop, fontsize, labelcolor, borderpad, labelspacing, handlelength, handleheight, handletextpad, borderaxespad, columnspacing, ncol, mode, fancybox, shadow, title, title_fontsize, framealpha, edgecolor, facecolor, bbox_to_anchor, bbox_transform, frameon, handler_map)
    501 
    502         # init with null renderer
--> 503         self._init_legend_box(handles, labels, markerfirst)
    504 
    505         tmp = self._loc_used_default

venv-3.9/lib/python3.9/site-packages/matplotlib/legend.py in _init_legend_box(self, handles, labels, markerfirst)
    764                 # Create the artist for the legend which represents the
    765                 # original artist/handle.
--> 766                 handle_list.append(handler.legend_artist(self, orig_handle,
    767                                                          fontsize, handlebox))
    768                 handles_and_labels.append((handlebox, textbox))

venv-3.9/lib/python3.9/site-packages/matplotlib/legend_handler.py in legend_artist(self, legend, orig_handle, fontsize, handlebox)
    113                  handlebox.width, handlebox.height,
    114                  fontsize)
--> 115         artists = self.create_artists(legend, orig_handle,
    116                                       xdescent, ydescent, width, height,
    117                                       fontsize, handlebox.get_transform())

venv-3.9/lib/python3.9/site-packages/matplotlib/legend_handler.py in create_artists(self, legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)
    720         for handle1 in orig_handle:
    721             handler = legend.get_legend_handler(handler_map, handle1)
--> 722             _a_list = handler.create_artists(
    723                 legend, handle1,
    724                 next(xds_cycle), ydescent, width, height, fontsize, trans)

AttributeError: 'NoneType' object has no attribute 'create_artists'

Screenshots or screencasts of the bug in action

douglas-raillard-arm commented 3 years ago

Can also be reproduced with another hv.Rectangles() instead of the hv.HLine