Closed
Description
Bug report
Bug summary
This happens because some sympy functions return a "One" or "Integer" object. So it is not matplotlib's fault that they do this instead of a normal int, but it took me a while to figure out this error. Including a cast to float would fix it.
More confusingly, somehow it looks like the matplotlib code thinks that "np" is the number I passed as the point size, since it is checking whether that has a "sqrt" attribute.
Code for reproduction
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__
'3.0.2'
>>> import matplotlib.pyplot as plt
>>> import sympy
>>> size = sympy.divisor_count(48)
>>> size
10
>>> plt.scatter(0, 0, s=size)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/wesley/.local/lib/python3.5/site-packages/matplotlib/pyplot.py", line 2864, in scatter
is not None else {}), **kwargs)
File "/home/wesley/.local/lib/python3.5/site-packages/matplotlib/__init__.py", line 1810, in inner
return func(ax, *args, **kwargs)
File "/home/wesley/.local/lib/python3.5/site-packages/matplotlib/axes/_axes.py", line 4297, in scatter
alpha=alpha
File "/home/wesley/.local/lib/python3.5/site-packages/matplotlib/collections.py", line 901, in __init__
self.set_sizes(sizes)
File "/home/wesley/.local/lib/python3.5/site-packages/matplotlib/collections.py", line 874, in set_sizes
scale = np.sqrt(self._sizes) * dpi / 72.0 * self._factor
AttributeError: 'Integer' object has no attribute 'sqrt'
>>>
>>> # a simple cast to float fixes it.
>>> plt.scatter(0, 0, s=float(size))
<matplotlib.collections.PathCollection object at 0x7fc15937a4a8>
>>>
Actual outcome
# If applicable, paste the console output here
#
#
Expected outcome
Matplotlib version
- Operating system: Ubuntu 16.04
- Matplotlib version: 3.0.2
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: 3.5.2
- Jupyter version (if applicable):
- Other libraries: sympy 1.3
Metadata
Metadata
Assignees
Labels
No labels