'ValueError: need at least one array to concatenate - when label and size array given

I want to plot a few data columns in a scatter plot and get the

ValueError: need at least one array to concatenate

only if both the size parameter is given with an array and a label is given (and when I want the legend to be plotted). When I don't pass an array to the size parameter or leave out the label (or don't set the legend), the error doesn't occur. What also seems to influence is the size of data points plotted, i.e. changing the value in .iloc[-42:]. (data is a pandas DataFrame.)

data_on_period = data.iloc[-42:]
fig, ax = plt.subplots(1, 1, sharex=False, figsize=(17, 7))
ax.scatter(data_on_period.index, data_on_period["workout"],
             s=data_on_period["workout"]*100, label='workout')
plt.legend()

EDIT: head of data:

            medi    other   read    goals   workout sleep
Datum                           
2022-01-01  2.000000    NaN NaN 7.083333    NaN     5.750000
2022-01-02  1.833333    NaN NaN 8.333333    NaN     5.416667
2022-01-03  2.166667    NaN NaN 9.666667    1.0     5.750000
2022-01-04  2.166667    NaN 1.0 8.166667    NaN     5.750000
2022-01-05  2.250000    NaN 1.0 10.000000   NaN     5.750000

full error log:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
    149         FigureCanvasBase(fig)
    150 
--> 151     fig.canvas.print_figure(bytes_io, **kw)
    152     data = bytes_io.getvalue()
    153     if fmt == 'svg':

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2228                        else suppress())
   2229                 with ctx:
-> 2230                     self.figure.draw(renderer)
   2231 
   2232             if bbox_inches:

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     72     @wraps(draw)
     73     def draw_wrapper(artist, renderer, *args, **kwargs):
---> 74         result = draw(artist, renderer, *args, **kwargs)
     75         if renderer._rasterizing:
     76             renderer.stop_rasterizing()

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/figure.py in draw(self, renderer)
   2788 
   2789             self.patch.draw(renderer)
-> 2790             mimage._draw_list_compositing_images(
   2791                 renderer, self, artists, self.suppressComposite)
   2792 

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    130     if not_composite or not has_images:
    131         for a in artists:
--> 132             a.draw(renderer)
    133     else:
    134         # Composite any adjacent images together

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs)
    429                          else deprecation_addendum,
    430                 **kwargs)
--> 431         return func(*inner_args, **inner_kwargs)
    432 
    433     return wrapper

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
   2919             renderer.stop_rasterizing()
   2920 
-> 2921         mimage._draw_list_compositing_images(renderer, self, artists)
   2922 
   2923         renderer.close_group('axes')

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    130     if not_composite or not has_images:
    131         for a in artists:
--> 132             a.draw(renderer)
    133     else:
    134         # Composite any adjacent images together

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/legend.py in draw(self, renderer)
    615 
    616         self.legendPatch.draw(renderer)
--> 617         self._legend_box.draw(renderer)
    618 
    619         renderer.close_group('legend')

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/offsetbox.py in draw(self, renderer)
    366         for c, (ox, oy) in zip(self.get_visible_children(), offsets):
    367             c.set_offset((px + ox, py + oy))
--> 368             c.draw(renderer)
    369 
    370         bbox_artist(self, renderer, fill=False, props=dict(pad=0.))

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/offsetbox.py in draw(self, renderer)
    366         for c, (ox, oy) in zip(self.get_visible_children(), offsets):
    367             c.set_offset((px + ox, py + oy))
--> 368             c.draw(renderer)
    369 
    370         bbox_artist(self, renderer, fill=False, props=dict(pad=0.))

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/offsetbox.py in draw(self, renderer)
    366         for c, (ox, oy) in zip(self.get_visible_children(), offsets):
    367             c.set_offset((px + ox, py + oy))
--> 368             c.draw(renderer)
    369 
    370         bbox_artist(self, renderer, fill=False, props=dict(pad=0.))

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/offsetbox.py in draw(self, renderer)
    366         for c, (ox, oy) in zip(self.get_visible_children(), offsets):
    367             c.set_offset((px + ox, py + oy))
--> 368             c.draw(renderer)
    369 
    370         bbox_artist(self, renderer, fill=False, props=dict(pad=0.))

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/offsetbox.py in draw(self, renderer)
    692             if self._clip_children and not (c.clipbox or c._clippath):
    693                 c.set_clip_path(tpath)
--> 694             c.draw(renderer)
    695 
    696         bbox_artist(self, renderer, fill=False, props=dict(pad=0.))

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/collections.py in draw(self, renderer)
   1010     def draw(self, renderer):
   1011         self.set_sizes(self._sizes, self.figure.dpi)
-> 1012         super().draw(renderer)
   1013 
   1014 

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/collections.py in draw(self, renderer)
    387             else:
    388                 combined_transform = transform
--> 389             extents = paths[0].get_extents(combined_transform)
    390             if (extents.width < self.figure.bbox.width
    391                     and extents.height < self.figure.bbox.height):

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/matplotlib/path.py in get_extents(self, transform, **kwargs)
    632                 # as can the ends of the curve
    633                 xys.append(curve([0, *dzeros, 1]))
--> 634             xys = np.concatenate(xys)
    635         if len(xys):
    636             return Bbox([xys.min(axis=0), xys.max(axis=0)])

~/forest/miniconda3/envs/aap/lib/python3.9/site-packages/numpy/core/overrides.py in concatenate(*args, **kwargs)

ValueError: need at least one array to concatenate


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source