FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Should xlim support single-entry arrays? · Issue #15690 · matplotlib/matplotlib · GitHub

Repository navigation

Should xlim support single-entry arrays? #15690

Closed

Description

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.

Now the docstring says that only scalar is supported:
https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.set_xlim.html

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

  1. jklymak commented on Nov 13, 2019

    Member

    I guess if something broke we should figure out what, even if your use case isn’t canonical.

  2. anntzer commented on Nov 13, 2019

    Contributor

    This has been fixed as of master in #15168.

  3. added this to the v3.1.2 milestone on Nov 13, 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


      Back | FazBrowse Home | New Git URL