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

Notebook backend returns plot despite bad kwarg raising ValueError #9043

Closed
LindyBalboa opened this issue Aug 16, 2017 · 5 comments
Closed

Comments

@LindyBalboa
Copy link
Contributor

LindyBalboa commented Aug 16, 2017

Bug report

I would expect the only thing to change would be the color of all the elements including line, errorbars markers, and caps. Instead, doing so causes elements to disappear.

When running under Jupyter notebook, this plot gets displayed despite the bad kwarg raising a ValueError, which is only visible in the server terminal. Quite misleading behavior that had me wrinkling my forehead this afternoon and send me and a wild goose chase.

Code
In Jupyter!

%matplotlib notebook
from matplotlib import pyplot as plt

plt.figure()
plt.errorbar([1,2,3],
             [1,2,3],
             [1,1,1],
             marker='s',
             capsize=10,
            )
plt.figure()
plt.errorbar([1,2,3],
             [1,2,3],
             [1,1,1],
             marker='s',
             color='rk',
             capsize=10,
            )
plt.show()

Output
image
image

Matplotlib version

  • Operating System: Arch Linux
  • Matplotlib Version: 2.0.2
  • Python Version: 3.6.1
  • Jupyter Version (if applicable): 5.0.0

default Anaconda package

@LindyBalboa LindyBalboa changed the title Alternating colors with plt.errorbar breaks markers and caps Alternating colors with plt.errorbar breaks linestyle, markers, and caps Aug 16, 2017
@dopplershift
Copy link
Contributor

Where were you running the code? If I run at the terminal, I get a pretty clear traceback:

Traceback (most recent call last):
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/colors.py", line 142, in to_rgba
    rgba = _colors_full_map.cache[c, alpha]
KeyError: ('rk', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/backends/backend_qt5agg.py", line 152, in __draw_idle_agg
    self.draw()
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/backends/backend_qt5agg.py", line 132, in draw
    super(FigureCanvasQTAggBase, self).draw()
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/backends/backend_agg.py", line 426, in draw
    self.figure.draw(self.renderer)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/artist.py", line 68, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/figure.py", line 1310, in draw
    renderer, self, artists, self.suppressComposite)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/artist.py", line 68, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/axes/_base.py", line 2390, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/artist.py", line 68, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/lines.py", line 806, in draw
    rgbaFace = self._get_rgba_face()
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/lines.py", line 1278, in _get_rgba_face
    rgbaFace = mcolors.to_rgba(facecolor, self._alpha)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/colors.py", line 144, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/colors.py", line 188, in _to_rgba_no_colorcycle
    raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: 'rk'
Traceback (most recent call last):
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/colors.py", line 142, in to_rgba
    rgba = _colors_full_map.cache[c, alpha]
KeyError: ('rk', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/backends/backend_qt5agg.py", line 152, in __draw_idle_agg
    self.draw()
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/backends/backend_qt5agg.py", line 132, in draw
    super(FigureCanvasQTAggBase, self).draw()
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/backends/backend_agg.py", line 426, in draw
    self.figure.draw(self.renderer)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/artist.py", line 68, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/figure.py", line 1310, in draw
    renderer, self, artists, self.suppressComposite)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/artist.py", line 68, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/axes/_base.py", line 2390, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/artist.py", line 68, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/lines.py", line 806, in draw
    rgbaFace = self._get_rgba_face()
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/lines.py", line 1278, in _get_rgba_face
    rgbaFace = mcolors.to_rgba(facecolor, self._alpha)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/colors.py", line 144, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
  File "/Users/rmay/repos/matplotlib/lib/matplotlib/colors.py", line 188, in _to_rgba_no_colorcycle
    raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: 'rk'

color only accepts a single matplotlib color, which 'rk' isn't. If I change it to 'r', I get:
figure_2

You can also add the ecolor argument to control the color of the error bars and get:

figure_2-1

Was there something somewhere that suggested color would accept multiple colors?

@LindyBalboa
Copy link
Contributor Author

LindyBalboa commented Aug 16, 2017

I got the idea from this post. I thought it would apply, but given that the default errorbar plots a line through the data, it makes sense that this behavior wouldn't be accepted.

Looking again, the error code you posted does indeed pop up in the terminal where the jupyter server is running, but it was still displaying in the notebook.

I was running this with %matplotlib notebook. As a check, I just did %matplotlib inline and it did not work. So this seems to a problem related to the notebook backend.

I accept that the argument shouldn't behave the way I initially thought, I will retitled to reflect the true nature of the bug.

@LindyBalboa LindyBalboa changed the title Alternating colors with plt.errorbar breaks linestyle, markers, and caps Notebook backend returns plot despite bad kwarg raising ValueError Aug 16, 2017
@dopplershift
Copy link
Contributor

Well the notebook backend returns what it was able to plot before it encountered the error. I'm not sure I agree this is a bug, it's pretty standard matplotlib behavior: where we haven't done upfront validation of arguments, you get a plot-time traceback, sometimes after part of the plot happens. I was able to reproduce the exact images you pasted above without any notebook backend, just from the terminal--same exact behavior.

I agree it is definitely sub-optimal behavior, which will hopefully be helped by traitlets (#8917). I'll leave it to @tacaswell on whether this should stay open as a bug.

@LindyBalboa
Copy link
Contributor Author

Well what surprises me the most is that the traceback never made it to the notebook itself. That was the whole reason I thought it was a bug in the first place. I normally send the server terminal off to workspace 7 or so to keep it out of the way, since I expect tracebacks to wind up in the notebook.

@tacaswell
Copy link
Member

This is a known issue with nbagg, see #5111. We make our own web-socket independent of the notebook communication channels and have our own js independent from the widgets framework.

The options to fix this are to add an explicit exception handling channel to our web socket or to use ipywidgets. The former is a lot of work and the later is being done at https://github.com/matplotlib/jupyter-matplotlib

The traitlets work will move the validation up closer to the user level and doing it piecemeal is not a priority (but I don't think we would turn away a PR adding it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants