Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scatter() does not work with x/y variables and metadata kwargs #136

Closed
gidden opened this issue Nov 8, 2018 · 0 comments · Fixed by #152
Closed

scatter() does not work with x/y variables and metadata kwargs #136

gidden opened this issue Nov 8, 2018 · 0 comments · Fixed by #152
Labels

Comments

@gidden
Copy link
Member

gidden commented Nov 8, 2018

It seems like there is an issue if you want to use color/marker based on metadata

(df
 .filter(region='World')
 .filter(Temperature='uncategorized', keep=False)
 .scatter(x='Primary Energy|Coal', y='Emissions|CO2', color='Temperature', 
          legend=True)
)

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/.local/lib/python3.5/site-packages/matplotlib/colors.py in to_rgba(c, alpha)
    157     try:
--> 158         rgba = _colors_full_map.cache[c, alpha]
    159     except (KeyError, TypeError):  # Not in cache, or unhashable.

KeyError: ('T', None)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
~/.local/lib/python3.5/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   4209             try:  # Then is 'c' acceptable as PathCollection facecolors?
-> 4210                 colors = mcolors.to_rgba_array(c)
   4211                 n_elem = colors.shape[0]

~/.local/lib/python3.5/site-packages/matplotlib/colors.py in to_rgba_array(c, alpha)
    258     for i, cc in enumerate(c):
--> 259         result[i] = to_rgba(cc, alpha)
    260     return result

~/.local/lib/python3.5/site-packages/matplotlib/colors.py in to_rgba(c, alpha)
    159     except (KeyError, TypeError):  # Not in cache, or unhashable.
--> 160         rgba = _to_rgba_no_colorcycle(c, alpha)
    161         try:

~/.local/lib/python3.5/site-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
    203             pass
--> 204         raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
    205     # tuple color.

ValueError: Invalid RGBA argument: 'T'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-35-12664c2e4825> in <module>()
      3  .filter(Temperature='uncategorized', keep=False)
      4  .scatter(x='Primary Energy|Coal', y='Emissions|CO2', color='Temperature', 
----> 5           legend=True)
      6 )

~/.local/lib/python3.5/site-packages/pyam/core.py in scatter(self, x, y, **kwargs)
    958                 .rename(columns={'value': var})
    959             )
--> 960         ax = plotting.scatter(df, x, y, **kwargs)
    961         return ax
    962 

~/.local/lib/python3.5/site-packages/pyam/plotting.py in scatter(df, x, y, ax, legend, title, color, marker, linestyle, cmap, groupby, with_lines, **kwargs)
    603         else:
    604             kwargs.pop('linestyle')  # scatter() can't take a linestyle
--> 605             ax.scatter(group[x], group[y], **kwargs)
    606 
    607     # build legend handles and labels

~/.local/lib/python3.5/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1783                         "the Matplotlib list!)" % (label_namer, func.__name__),
   1784                         RuntimeWarning, stacklevel=2)
-> 1785             return func(ax, *args, **kwargs)
   1786 
   1787         inner.__doc__ = _add_data_doc(inner.__doc__,

~/.local/lib/python3.5/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   4229                     "or as numbers to be mapped to colors. "
   4230                     "Here c = {}."  # <- beware, could be long depending on c.
-> 4231                     .format(c)
   4232                 )
   4233         else:

ValueError: 'c' argument must either be valid as mpl color(s) or as numbers to be mapped to colors. Here c = Temperature.
@gidden gidden added the plotting label Nov 8, 2018
@gidden gidden changed the title scatter() does not work with metadata kwargs scatter() does not work with metadata kwargs Nov 8, 2018
@gidden gidden changed the title scatter() does not work with metadata kwargs scatter() does not work with x/y variables and metadata kwargs Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant