The Wayback Machine - https://web.archive.org/web/20240110183002/https://github.com/matplotlib/matplotlib/issues/27500
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

[Bug]: Units behavior of streamplot #27500

Open
ksunden opened this issue Dec 12, 2023 · 0 comments
Open

[Bug]: Units behavior of streamplot #27500

ksunden opened this issue Dec 12, 2023 · 0 comments

Comments

@ksunden
Copy link
Member

ksunden commented Dec 12, 2023

Bug summary

As seen in #27489 streamplot does not allow passing unitful data as x/y

Code for reproduction

fig, ax = plt.subplots()

np.random.seed(19680801)
limit_value = 30

date_array = np.array(
        [datetime.datetime(2023, 12, n) for n in range(1, limit_value)]
    , dtype=np.datetime64)
#date_array_converted = mpl.dates.date2num(date_array)
X, Y = np.meshgrid(date_array, date_array)
U = np.random.rand(limit_value-1, limit_value-1)
V = np.random.rand(limit_value-1, limit_value-1)

ax.streamplot(X, Y, U, V)

Actual outcome

Traceback (most recent call last):
  File "/home/kyle/play/gh27487.py", line 22, in <module>
    ax.streamplot(X, Y, U, V)
  File "/home/kyle/src/scipy/matplotlib/lib/matplotlib/__init__.py", line 1472, in inner
    return func(
           ^^^^^
  File "/home/kyle/src/scipy/matplotlib/lib/matplotlib/streamplot.py", line 91, in streamplot
    grid = Grid(x, y)
           ^^^^^^^^^^
  File "/home/kyle/src/scipy/matplotlib/lib/matplotlib/streamplot.py", line 330, in __init__
    if not np.allclose(x_row, x):
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/kyle/.pyenv/versions/edge/lib/python3.11/site-packages/numpy/core/numeric.py", line 2241, in allc
lose
    res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kyle/.pyenv/versions/edge/lib/python3.11/site-packages/numpy/core/numeric.py", line 2345, in iscl
ose
    dt = multiarray.result_type(y, 1.)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy.exceptions.DTypePromotionError: The DType <class 'numpy._FloatAbstractDType'> could not be promoted by <c
lass 'numpy.dtypes.DateTime64DType'>. This means that no common DType exists for the given inputs. For example 
they cannot be stored in a single array unless the dtype is `object`. The full list of DTypes is: (<class 'nump
y.dtypes.DateTime64DType'>, <class 'numpy._FloatAbstractDType'>)

Expected outcome

Units can be passed as at least X/Ya (I could see requiring them to be the same units... or even saying "this type of plot shouldn't support units", but would want to be explicit about that.

I do wonder a bit about U/V and whether they should be specified in delta units or not? quiver can treat them as independent values or as delta values, I believe, but don't see such a distinction on stream lines.

Additional information

May be as easy as calling _process_unit_info on the inputs, I think.

Operating system

No response

Matplotlib Version

3.9.0.dev821+gfa6be74127 (~main at time of reporting)

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

git checkout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants