Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Better fallback when color is a float #6266

Copy link
Copy link
Closed
@jankatins

Description

@jankatins
Issue body actions

I'm using matplotlib via the "new" data interface and with cartopy (all latest conda env with conda-forge and py3.5).

ax.scatter("lon", "lat", color="sum_prob", lw = 0, data=good_data, transform=ll_proj)

I get the following error message:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\colors.py in to_rgba(self, arg, alpha)
    367                     raise ValueError(
--> 368                             'length of rgba sequence should be either 3 or 4')
    369             else:

ValueError: length of rgba sequence should be either 3 or 4

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\colors.py in to_rgba_array(self, c, alpha)
    398             # Single value? Put it in an array with a single row.
--> 399             return np.array([self.to_rgba(c, alpha)], dtype=np.float)
    400         except ValueError:

C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\colors.py in to_rgba(self, arg, alpha)
    375             raise ValueError(
--> 376                 'to_rgba: Invalid rgba arg "%s"\n%s' % (str(arg), exc))
    377 

ValueError: to_rgba: Invalid rgba arg "6574    0.000165
6674    0.000167
6774    0.000168
6873    0.000165
6874    0.000170
6973    0.000166
6974    0.000171
7073    0.000167
7074    0.000173
7172    0.000163
7173    0.000168
7174    0.000174
7272    0.000164
7273    0.000169
7274    0.000176
7372    0.000165
7373    0.000170
7374    0.000177
7472    0.000166
7473    0.000172
7474    0.000179
7571    0.000162
7572    0.000167
7573    0.000173
7574    0.000181
7671    0.000163
7672    0.000168
7673    0.000175
7674    0.000183
7771    0.000163
          ...   
9670    0.000193
9671    0.000207
9672    0.000221
9673    0.000236
9765    0.000138
9766    0.000148
9767    0.000158
9768    0.000170
9769    0.000183
9770    0.000196
9771    0.000211
9772    0.000226
9864    0.000130
9865    0.000140
9866    0.000150
9867    0.000161
9868    0.000173
9869    0.000186
9870    0.000200
9871    0.000215
9872    0.000230
9964    0.000131
9965    0.000142
9966    0.000152
9967    0.000163
9968    0.000176
9969    0.000189
9970    0.000204
9971    0.000219
9972    0.000234
Name: sum_prob, dtype: float64"
length of rgba sequence should be either 3 or 4

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\colors.py in to_rgb(self, arg)
    321                 raise ValueError(
--> 322                     'cannot convert argument to rgb sequence')
    323 

ValueError: cannot convert argument to rgb sequence

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\colors.py in to_rgba(self, arg, alpha)
    369             else:
--> 370                 r, g, b = self.to_rgb(arg)
    371             if alpha is None:

C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\colors.py in to_rgb(self, arg)
    327             raise ValueError(
--> 328                 'to_rgb: Invalid rgb arg "%s"\n%s' % (str(arg), exc))
    329             # Error messages could be improved by handling TypeError

ValueError: to_rgb: Invalid rgb arg "0.000165462141918"
cannot convert argument to rgb sequence

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-40-c01684ee4af6> in <module>()
     22 #plt.show()
     23 
---> 24 ax.scatter("lon", "lat", color=good_data["sum_prob"], lw = 0, data=good_data, transform=ll_proj)
     25 #ax.scatter("lon", "lat", color="sum_prob", lw = 0, data=best, transform=ll_proj)

C:\portabel\miniconda\envs\zalando\lib\site-packages\cartopy\mpl\geoaxes.py in scatter(self, *args, **kwargs)
   1179                              '(PlateCarree or RotatedPole).')
   1180 
-> 1181         result = matplotlib.axes.Axes.scatter(self, *args, **kwargs)
   1182         self.autoscale_view()
   1183         return result

C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
   1809                     warnings.warn(msg % (label_namer, func.__name__),
   1810                                   RuntimeWarning, stacklevel=2)
-> 1811             return func(ax, *args, **kwargs)
   1812         pre_doc = inner.__doc__
   1813         if pre_doc is None:

C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   3891                 offsets=offsets,
   3892                 transOffset=kwargs.pop('transform', self.transData),
-> 3893                 alpha=alpha
   3894                 )
   3895         collection.set_transform(mtransforms.IdentityTransform())

C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\collections.py in __init__(self, paths, sizes, **kwargs)
    829         """
    830 
--> 831         Collection.__init__(self, **kwargs)
    832         self.set_paths(paths)
    833         self.set_sizes(sizes)

C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\collections.py in __init__(self, edgecolors, facecolors, linewidths, linestyles, antialiaseds, offsets, transOffset, norm, cmap, pickradius, hatch, urls, offset_position, zorder, **kwargs)
    114         cm.ScalarMappable.__init__(self, norm, cmap)
    115 
--> 116         self.set_edgecolor(edgecolors)
    117         self.set_facecolor(facecolors)
    118         self.set_linewidth(linewidths)

C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\collections.py in set_edgecolor(self, c)
    658             c = mpl.rcParams['patch.edgecolor']
    659         self._edgecolors_original = c
--> 660         self._edgecolors = mcolors.colorConverter.to_rgba_array(c, self._alpha)
    661         self.stale = True
    662 

C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\colors.py in to_rgba_array(self, c, alpha)
    420             result = np.zeros((nc, 4), dtype=np.float)
    421             for i, cc in enumerate(c):
--> 422                 result[i] = self.to_rgba(cc, alpha)
    423             return result
    424 

C:\portabel\miniconda\envs\zalando\lib\site-packages\matplotlib\colors.py in to_rgba(self, arg, alpha)
    374         except (TypeError, ValueError) as exc:
    375             raise ValueError(
--> 376                 'to_rgba: Invalid rgba arg "%s"\n%s' % (str(arg), exc))
    377 
    378     def to_rgba_array(self, c, alpha=None):

ValueError: to_rgba: Invalid rgba arg "0.000165462141918"
to_rgb: Invalid rgb arg "0.000165462141918"
cannot convert argument to rgb sequence

IMO the default (or at least the fallback) should simple take the float array, get min/max and then convert each value to a rgb value depending on the value in sum_prob.

[current mood: why did I start this notebook in python and tried to do this in pandas, cartopy and matplotlib? ggplot would have so much nice defaults... an hour gone to find a way to display a dataframe with x,y,z values on a image, where x,y are every lat-lon combi on a plot but contour/whatever needs it in a non-pandas.dataframe format... the above scatter is actually the workaround...]

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.