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

pyplot.scatter raises obscure error when mistakenly passed a third string param #5970

Closed
mtaran opened this issue Feb 7, 2016 · 0 comments · Fixed by #18042
Closed

pyplot.scatter raises obscure error when mistakenly passed a third string param #5970

mtaran opened this issue Feb 7, 2016 · 0 comments · Fixed by #18042

Comments

@mtaran
Copy link

mtaran commented Feb 7, 2016

This came up when I tried to pass a third param to pyplot.scatter(), specifically a string to represent the marker shape, by analogy to the third param in pyplot.plot(). It turned out that this is possible, but with the marker named param, which does not come third. The third param in order is s, which expects a sequence of numbers. The error that actually comes up when it's given a string (in this case '.') is not very helpful:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    337                 pass
    338             else:
--> 339                 return printer(obj)
    340             # Finally look for special method names
    341             method = _safe_get_formatter_method(obj, self.print_method)

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in <lambda>(fig)
    224 
    225     if 'png' in formats:
--> 226         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    227     if 'retina' in formats or 'png2x' in formats:
    228         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
    115 
    116     bytes_io = BytesIO()
--> 117     fig.canvas.print_figure(bytes_io, **kw)
    118     data = bytes_io.getvalue()
    119     if fmt == 'svg':

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2050         where the keys are a file type name, such as 'Joint Photographic
   2051         Experts Group', and the values are a list of filename extensions used
-> 2052         for that filetype, such as ['jpg', 'jpeg']."""
   2053         groupings = {}
   2054         for ext, name in six.iteritems(cls.filetypes):

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
    489             self.renderer.clear()
    490         return self.renderer
--> 491 
    492     def tostring_rgb(self):
    493         if __debug__: verbose.report('FigureCanvasAgg.tostring_rgb',

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in draw(self)
    437     """
    438     Create a new figure manager instance for the given figure.
--> 439     """
    440     canvas = FigureCanvasAgg(figure)
    441     manager = FigureManagerBase(canvas, num)

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     52         if artist.get_agg_filter() is not None:
     53             renderer.stop_filter(artist.get_agg_filter())
---> 54 
     55         if artist.get_rasterized():
     56             renderer.stop_rasterizing()

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
    997                 else:
    998                     # Undocumented convenience behavior:
--> 999                     # subplot(111); subplot(111, projection='polar')
   1000                     # will replace the first with the second.
   1001                     # Without this, add_subplot would be simpler and

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     52         if artist.get_agg_filter() is not None:
     53             renderer.stop_filter(artist.get_agg_filter())
---> 54 
     55         if artist.get_rasterized():
     56             renderer.stop_rasterizing()

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.pyc in draw(self, renderer, inframe)

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     52         if artist.get_agg_filter() is not None:
     53             renderer.stop_filter(artist.get_agg_filter())
---> 54 
     55         if artist.get_rasterized():
     56             renderer.stop_rasterizing()

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/collections.pyc in draw(self, renderer)
    692 
    693     def get_linewidths(self):
--> 694         return self._linewidths
    695     get_linewidth = get_linewidths
    696 

TypeError: ufunc 'sqrt' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

It would be great if there was some sort of validation that happened early on, to make sure that e.g. params that expect a sequence of numbers complain if they get something like a string instead.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Feb 7, 2016
@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Oct 3, 2017
QuLogic added a commit to QuLogic/matplotlib that referenced this issue Jul 23, 2020
@QuLogic QuLogic modified the milestones: needs sorting, v3.4.0 Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants