Search code examples
pythonmatplotlibplotseaborncatplot

Seaborn ValueError: Invalid RGBA argument: masked


I'm trying to create a catplot with seaborn. I prepared the data like this

PDB_throughput=pd.DataFrame()

PDCPlayer_throughputD['Type'] = 'Drone-BS'
perfect_throughput['Type'] = 'Perfect'

PDB_throughput=PDB_throughput.append(PDCPlayer_throughputD)
PDB_throughput=PDB_throughput.append(perfect_throughput) 

print(PDB_throughput)

This is the final dataframe:

     Throughput [Mbit/s]      Type  numUe
0            195.498916  Drone-BS     11
1            192.380980  Drone-BS     14
2            192.037444  Drone-BS     17
3            160.040452  Drone-BS     15
4            201.267220  Drone-BS     25
5            197.800036  Drone-BS     28
6            199.214980  Drone-BS     29
7            198.483028  Drone-BS     10
8            197.064004  Drone-BS     28
9            197.154580  Drone-BS     27
10           192.037444  Drone-BS     17
11           222.887140  Drone-BS     23
12           155.018788  Drone-BS     22
13           192.380980  Drone-BS     14
14           193.452388  Drone-BS     27
15           191.702068  Drone-BS     30
16           201.326788  Drone-BS     13
17           194.959540  Drone-BS     34
18           197.411620  Drone-BS     26
0            431.933760   Perfect     12
1            299.260800   Perfect      8
2           2214.725760   Perfect     26
3            957.402000   Perfect     15
4           1773.351360   Perfect     22
5            526.555920   Perfect     11
6            956.444400   Perfect     15
7            581.627520   Perfect     12
8           2189.540160   Perfect     27
9            682.550880   Perfect     11
10          1555.985520   Perfect     17
11          1651.017840   Perfect     31
12          1998.955200   Perfect     17
13          2028.858000   Perfect     25
14           472.330560   Perfect     13
15          2032.578000   Perfect     25
16          2155.689120   Perfect     26
17          1091.718240   Perfect     17
18           586.302720   Perfect     16

and I want to create a plot with 2 curves of different colors in order to see the differences. One curve Type=Perfect and another one Type=Drone-BS

I tried 2 types of seaborn plots

sns.catplot(data=PDB_throughput,
            x='numUe',
            y='Throughput [Mbit/s]',
            hue='Type',
            kind='point',
            height=5, aspect=2)

and

g = sns.factorplot('numUe', 'Throughput [Mbit/s]', 'Type', data=PDB_throughput, kind="point")

I always get the same ValueError: Invalid RGBA argument: masked and I don't understand the mistake in the code or in the logic.

Here the details of the entire error

ValueError                                Traceback (most recent call last)
<ipython-input-57-7f71b1dbaaa5> in <module>
     22 
     23 #e = sns.FacetGrid(data= PDB_throughput)
---> 24 g = sns.factorplot('numUe', 'Throughput [Mbit/s]', 'Type', data=PDB_throughput, kind="point")
     25 #e.map_dataframe(sns.pointplot, 'numUe', 'Throughput [Mbit/s]', hue='Type', order=["Drone-BS", "Perfect"], hue_order=[0, 1])
     26 #e.add_legend()

~/anaconda3/lib/python3.7/site-packages/seaborn/categorical.py in factorplot(*args, **kwargs)
   3674     kwargs.setdefault("kind", "point")
   3675 
-> 3676     return catplot(*args, **kwargs)
   3677 
   3678 

~/anaconda3/lib/python3.7/site-packages/seaborn/categorical.py in catplot(x, y, hue, data, row, col, col_wrap, estimator, ci, n_boot, units, order, hue_order, row_order, col_order, kind, height, aspect, orient, color, palette, legend, legend_out, sharex, sharey, margin_titles, facet_kws, **kwargs)
   3753 
   3754     # Draw the plot onto the facets
-> 3755     g.map_dataframe(plot_func, x, y, hue, **plot_kws)
   3756 
   3757     # Special case axis labels for a count type plot

~/anaconda3/lib/python3.7/site-packages/seaborn/axisgrid.py in map_dataframe(self, func, *args, **kwargs)
    818 
    819             # Draw the plot
--> 820             self._facet_plot(func, ax, args, kwargs)
    821 
    822         # Finalize the annotations and layout

~/anaconda3/lib/python3.7/site-packages/seaborn/axisgrid.py in _facet_plot(self, func, ax, plot_args, plot_kwargs)
    836 
    837         # Draw the plot
--> 838         func(*plot_args, **plot_kwargs)
    839 
    840         # Sort out the supporting information

~/anaconda3/lib/python3.7/site-packages/seaborn/categorical.py in pointplot(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, markers, linestyles, dodge, join, scale, orient, color, palette, errwidth, capsize, ax, **kwargs)
   3338         ax = plt.gca()
   3339 
-> 3340     plotter.plot(ax)
   3341     return ax
   3342 

~/anaconda3/lib/python3.7/site-packages/seaborn/categorical.py in plot(self, ax)
   1809     def plot(self, ax):
   1810         """Make the plot."""
-> 1811         self.draw_points(ax)
   1812         self.annotate_axes(ax)
   1813         if self.orient == "h":

~/anaconda3/lib/python3.7/site-packages/seaborn/categorical.py in draw_points(self, ax)
   1805                            c=point_colors, edgecolor=point_colors,
   1806                            linewidth=mew, marker=marker, s=markersize,
-> 1807                            zorder=z)
   1808 
   1809     def plot(self, ax):

~/anaconda3/lib/python3.7/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1587     def inner(ax, *args, data=None, **kwargs):
   1588         if data is None:
-> 1589             return func(ax, *map(sanitize_sequence, args), **kwargs)
   1590 
   1591         bound = new_sig.bind(ax, *args, **kwargs)

~/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, plotnonfinite, **kwargs)
   4488                 offsets=offsets,
   4489                 transOffset=kwargs.pop('transform', self.transData),
-> 4490                 alpha=alpha
   4491                 )
   4492         collection.set_transform(mtransforms.IdentityTransform())

~/anaconda3/lib/python3.7/site-packages/matplotlib/collections.py in __init__(self, paths, sizes, **kwargs)
    881         """
    882 
--> 883         Collection.__init__(self, **kwargs)
    884         self.set_paths(paths)
    885         self.set_sizes(sizes)

~/anaconda3/lib/python3.7/site-packages/matplotlib/collections.py in __init__(self, edgecolors, facecolors, linewidths, linestyles, capstyle, joinstyle, antialiaseds, offsets, transOffset, norm, cmap, pickradius, hatch, urls, offset_position, zorder, **kwargs)
    126         self._hatch_color = mcolors.to_rgba(mpl.rcParams['hatch.color'])
    127         self.set_facecolor(facecolors)
--> 128         self.set_edgecolor(edgecolors)
    129         self.set_linewidth(linewidths)
    130         self.set_linestyle(linestyles)

~/anaconda3/lib/python3.7/site-packages/matplotlib/collections.py in set_edgecolor(self, c)
    726         """
    727         self._original_edgecolor = c
--> 728         self._set_edgecolor(c)
    729 
    730     def set_alpha(self, alpha):

~/anaconda3/lib/python3.7/site-packages/matplotlib/collections.py in _set_edgecolor(self, c)
    710         except AttributeError:
    711             pass
--> 712         self._edgecolors = mcolors.to_rgba_array(c, self._alpha)
    713         if set_hatch_color and len(self._edgecolors):
    714             self._hatch_color = tuple(self._edgecolors[0])

~/anaconda3/lib/python3.7/site-packages/matplotlib/colors.py in to_rgba_array(c, alpha)
    284     result = np.empty((len(c), 4), float)
    285     for i, cc in enumerate(c):
--> 286         result[i] = to_rgba(cc, alpha)
    287     return result
    288 

~/anaconda3/lib/python3.7/site-packages/matplotlib/colors.py in to_rgba(c, alpha)
    175         rgba = None
    176     if rgba is None:  # Suppress exception chaining of cache lookup failure.
--> 177         rgba = _to_rgba_no_colorcycle(c, alpha)
    178         try:
    179             _colors_full_map.cache[c, alpha] = rgba

~/anaconda3/lib/python3.7/site-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
    236         # float)` and `np.array(...).astype(float)` all convert "0.5" to 0.5.
    237         # Test dimensionality to reject single floats.
--> 238         raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
    239     # Return a tuple to prevent the cached value from being modified.
    240     c = tuple(c.astype(float))

ValueError: Invalid RGBA argument: masked

Solution

  • Your code seems to work:

    sns.catplot(data=PDB_throughput,
                x='numUe',
                y='Throughput [Mbit/s]',
                hue='Type',
                kind='point',
                height=5, aspect=2)
    
    plt.show()
    

    Seaborn

    For your information:

    # Python 3.9.6
    matplotlib==3.4.2
    seaborn==0.11.1
    pandas==1.3.0
    numpy==1.21.2