Skip to content

AttributeError: 'float' object has no attribute 'deg2rad' #13286

Closed

Description

@jschueller

With numpy>=1.16.0 Axes.pie chokes on a 2-d array as argument:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(4, 4))
plt.suptitle("Pie example")
axis = fig.add_subplot(111)

x=np.array([[0.4], [0.3], [0.2], [0.1]])
axis.pie(x, labels=['a0', 'a1', 'a2', 'a3'], colors=['#ff0000','#ccff00','#00ff66','#0066ff'])
axis.set_xlim(auto=True)
plt.show()

with the following traceback:

Traceback (most recent call last):
  File "../../pie_np.py", line 9, in <module>
    axis.pie(x, labels=['a0', 'a1', 'a2', 'a3'], colors=['#ff0000','#ccff00','#00ff66','#0066ff'])
  File "/usr/lib/python3.7/site-packages/matplotlib/__init__.py", line 1810, in inner
    return func(ax, *args, **kwargs)
  File "/usr/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 2854, in pie
    **wedgeprops)
  File "/usr/lib/python3.7/site-packages/matplotlib/patches.py", line 1041, in __init__
    self._recompute_path()
  File "/usr/lib/python3.7/site-packages/matplotlib/patches.py", line 1053, in _recompute_path
    arc = Path.arc(theta1, theta2)
  File "/usr/lib/python3.7/site-packages/matplotlib/path.py", line 862, in arc
    eta1, eta2 = np.deg2rad([eta1, eta2])
AttributeError: 'float' object has no attribute 'deg2rad'

It's ok if I use x = [0.4, 0.3, 0.2, 0.1] or go back to numpy 1.15.4

Using Linux/py3.7 here.

Activity

  1. anntzer commented on Jan 25, 2019

    @anntzer
    Contributor

    My gut feeling is that even if we do temporarily fix this (i.e. work around the bad interaction between numpy 1.16 and mpl, which is probably just a matter of squeeze()ing the inpût), we should take that opportunity to deprecate support for 2D input here (essentially like in may other places (errorbar(), scatter()), where we interpret 2D "column" inputs as 1D inputs (likely due to MATLAB heritage) but that behavior is simply not consistent with numpy's general broadcasting rules); see #13209 for a similar case.

  2. jschueller commented on Jan 26, 2019

    @jschueller
    ContributorAuthor

    Ok, I'll change our code too then.

  3. added this to the v3.0.3 milestone on Jan 27, 2019
  4. modified the milestones: v3.0.3, v3.1 on Feb 4, 2019
  5. added a commit that references this issue on Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions