AttributeError when using name of column as `color` argument for bar plot with Matplotlib backend
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 124
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 1
Description
I would expect to be able to use the name of a column as `color` argument for a bar plot with Matplotlib backend just as I can for the Bokeh backend. But I cannot because an AttributeError is raised.

```bash
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File C:\repos\private\hvplot\.venv\lib\site-packages\IPython\core\formatters.py:972, in MimeBundleFormatter.__call__(self, obj, include, exclude)
969 method = get_real_method(obj, self.print_method)
971 if method is not None:
--> 972 return method(include=include, exclude=exclude)
973 return None
974 else:
File c:\repos\private\tmp\holoviews\holoviews\core\dimension.py:1293, in Dimensioned._repr_mimebundle_(self, include, exclude)
1286 def _repr_mimebundle_(self, include=None, exclude=None):
1287 """
1288 Resolves the class hierarchy for the class rendering the
1289 object using any display hooks registered on Store.display
1290 hooks. The output of all registered display_hooks is then
1291 combined and returned.
1292 """
-> 1293 return Store.render(self)
File c:\repos\private\tmp\holoviews\holoviews\core\options.py:1426, in Store.render(cls, obj)
1424 data, metadata = {}, {}
1425 for hook in hooks:
-> 1426 ret = hook(obj)
1427 if ret is None:
1428 continue
File c:\repos\private\tmp\holoviews\holoviews\ipython\display_hooks.py:277, in pprint_display(obj)
275 if not ip.display_formatter.formatters['text/plain'].pprint:
276 return None
--> 277 return display(obj, raw_output=True)
File c:\repos\private\tmp\holoviews\holoviews\ipython\display_hooks.py:247, in display(obj, raw_output, **kwargs)
245 elif isinstance(obj, (CompositeOverlay, ViewableElement)):
246 with option_state(obj):
--> 247 output = element_display(obj)
248 elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
249 with option_state(obj):
File c:\repos\private\tmp\holoviews\holoviews\ipython\display_hooks.py:141, in display_hook..wrapped(element)
139 try:
140 max_frames = OutputSettings.options['max_frames']
--> 141 mimebundle = fn(element, max_frames=max_frames)
142 if mimebundle is None:
143 return {}, {}
File c:\repos\private\tmp\holoviews\holoviews\ipython\display_hooks.py:187, in element_display(element, max_frames)
184 if type(element) not in Store.registry[backend]:
185 return None
--> 187 return render(element)
File c:\repos\private\tmp\holoviews\holoviews\ipython\display_hooks.py:68, in render(obj, **kwargs)
65 if renderer.fig == 'pdf':
66 renderer = renderer.instance(fig='png')
---> 68 return renderer.components(obj, **kwargs)
File c:\repos\private\tmp\holoviews\holoviews\plotting\renderer.py:380, in Renderer.components(self, obj, fmt, comm, **kwargs)
378 plot = obj
379 else:
--> 380 plot, fmt = self._validate(obj, fmt)
382 if not isinstance(plot, Viewable):
383 html = self._figure_data(plot, fmt, as_script=True, **kwargs)
File c:\repos\private\tmp\holoviews\holoviews\plotting\renderer.py:309, in Renderer._validate(self, obj, fmt, **kwargs)
306 plot = HoloViewsPane(obj, center=self.center, backend=self.backend,
307 renderer=self)
308 else:
--> 309 plot = self.get_plot(obj, renderer=self, **kwargs)
311 all_formats = set(fig_formats + holomap_formats)
312 if fmt not in all_formats:
File c:\repos\private\tmp\holoviews\holoviews\plotting\renderer.py:240, in Renderer.get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
237 defaults = [kd.default for kd in plot.dimensions]
238 init_key = tuple(v if d is None else d for v, d in
239 zip(plot.keys[0], defaults))
--> 240 plot.update(init_key)
241 else:
242 plot = obj
File c:\repos\private\tmp\holoviews\holoviews\plotting\mpl\plot.py:249, in MPLPlot.update(self, key)
247 def update(self, key):
248 if len(self) == 1 and ((key == 0) or (key == self.keys[0])) and not self.drawn:
--> 249 return self.initialize_plot()
250 return self.__getitem__(key)
File c:\repos\private\tmp\holoviews\holoviews\plotting\mpl\plot.py:45, in mpl_rc_context..wrapper(self, *args, **kwargs)
43 def wrapper(self, *args, **kwargs):
44 with _rc_context(self.fig_rcparams):
---> 45 return f(self, *args, **kwargs)
File c:\repos\private\tmp\holoviews\holoviews\plotting\mpl\chart.py:893, in BarPlot.initialize_plot(self, ranges)
890 ranges = self.compute_ranges(self.hmap, key, ranges)
891 ranges = match_spec(element, ranges)
--> 893 self.handles['artist'], xticks, xdims = self._create_bars(axis, element, ranges, style)
894 kwargs = {'yticks': xticks} if self.invert_axes else {'xticks': xticks}
895 return self._finalize_axis(key, ranges=ranges, element=element,
896 dimensions=[xdims, vdim], **kwargs)
File c:\repos\private\tmp\holoviews\holoviews\plotting\mpl\chart.py:992, in BarPlot._create_bars(self, axis, element, ranges, style)
989 labels.append(label)
991 # Draw bars
--> 992 bars = [getattr(axis, plot_fn)(**bar_spec) for bar_spec in bar_data.values()]
994 # Generate legend and axis labels
995 ax_dims = [gdim]
File c:\repos\private\tmp\holoviews\holoviews\plotting\mpl\chart.py:992, in (.0)
989 labels.append(label)
991 # Draw bars
--> 992 bars = [getattr(axis, plot_fn)(**bar_spec) for bar_spec in bar_data.values()]
994 # Generate legend and axis labels
995 ax_dims = [gdim]
File C:\repos\private\hvplot\.venv\lib\site-packages\matplotlib\__init__.py:1423, in _preprocess_data..inner(ax, data, *args, **kwargs)
1420 @functools.wraps(func)
1421 def inner(ax, *args, data=None, **kwargs):
1422 if data is None:
-> 1423 return func(ax, *map(sanitize_sequence, args), **kwargs)
1425 bound = new_sig.bind(ax, *args, **kwargs)
1426 auto_label = (bound.arguments.get(label_namer)
1427 or bound.kwargs.get(label_namer))
File C:\repos\private\hvplot\.venv\lib\site-packages\matplotlib\axes\_axes.py:2462, in Axes.bar(self, x, height, width, bottom, align, **kwargs)
2453 for l, b, w, h, c, e, lw, htch, lbl in args:
2454 r = mpatches.Rectangle(
2455 xy=(l, b), width=w, height=h,
2456 facecolor=c,
(...)
2460 hatch=htch,
2461 )
-> 2462 r._internal_update(kwargs)
2463 r.get_path()._interpolation_steps = 100
2464 if orientation == 'vertical':
File C:\repos\private\hvplot\.venv\lib\site-packages\matplotlib\artist.py:1186, in Artist._internal_update(self, kwargs)
1179 def _internal_update(self, kwargs):
1180 """
1181 Update artist properties without prenormalizing them, but generating
1182 errors as if calling `set`.
1183
1184 The lack of prenormalization is to maintain backcompatibility.
1185 """
-> 1186 return self._update_props(
1187 kwargs, "{cls.__name__}.set() got an unexpected keyword argument "
1188 "{prop_name!r}")
File C:\repos\private\hvplot\.venv\lib\site-packages\matplotlib\artist.py:1160, in Artist._update_props(self, props, errfmt)
1158 func = getattr(self, f"set_{k}", None)
1159 if not callable(func):
-> 1160 raise AttributeError(
1161 errfmt.format(cls=type(self), prop_name=k))
1162 ret.append(func(v))
1163 if ret:
AttributeError: Rectangle.set() got an unexpected keyword argument 'vmin'
```
```python
import pandas as pd
import hvplot.pandas # noqa
from bokeh.sampledata.autompg import autompg_clean as autompg
autompg.head()
autompg_long_form = autompg.groupby("yr").mean(numeric_only=True).reset_index()
autompg_long_form.head()
autompg_multi_index = autompg.query("yr<=80").groupby(['yr', 'origin']).mean(numeric_only=True)
autompg_wide = autompg_multi_index.reset_index().pivot(index='yr', columns='origin', values='mpg')
autompg_wide.head()
hvplot.extension("bokeh")
autompg_long_form.hvplot.bar(y='mpg', color="weight", colorbar=True, clabel="Weight", cmap="bmy", width=1000)
hvplot.extension("matplotlib")
autompg_long_form.hvplot.bar(y='mpg', color="weight", colorbar=True, clabel="Weight", cmap="bmy", width=1000)
```
Contributor guide
Assessment
This issue has not been assessed yet.