You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is one change in behaviour I noticed when upgrading to Python 3.8, where matplotlib 3.1.1 used to work in Python 3.7, but not in Python 3.8 any more.
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> plt.xlim(np.array([3]), 4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/deil/opt/anaconda3/envs/py38/lib/python3.8/site-packages/matplotlib/pyplot.py", line 1434, in xlim
ret = ax.set_xlim(*args, **kwargs)
File "/Users/deil/opt/anaconda3/envs/py38/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 3270, in set_xlim
left, right = sorted([left, right], reverse=reverse)
TypeError: only integer scalar arrays can be converted to a scalar index
I think the issue is that reverse = np.array([False]) and sorted refuses to process that, raising the TypeError. I'm not sure if this is a change in behaviour in CPython, or if I'm having slightly different Numpy & matplotlib versions in my Python 3.7 and 3.8 environments.
In our scripts we have code that computes the left and right for set_xlim, and for complex reasons it gives a 1-element ndim=1 Numpy array, not a Numpy scalar.
Is the old behaviour to work OK with single-entry ndim=1 arrays something you want to support via some code change in matplotlib?
Or is this a usage bug that only accidentally worked earlier, and we fix our code?
Activity
jklymak commentedon Nov 13, 2019
I guess if something broke we should figure out what, even if your use case isn’t canonical.
anntzer commentedon Nov 13, 2019
This has been fixed as of master in #15168.