Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd643bd

Browse files
committed
Throw ValueError when irregularly gridded data is passed to streamplot.
... instead of silently generating an incorrect streamplot.
1 parent e08d7ba commit bd643bd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

doc/api/api_changes/2018-10-10-AL.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
`Axes.streamplot` now raises ValueError when an irregular grid is passed in
2+
```````````````````````````````````````````````````````````````````````````
3+
4+
`Axes.streamplot` does not support irregularly gridded ``x`` and ``y`` values.
5+
So far, it used to silently plot an incorrect result. This has been changed to
6+
raise a ValueError instead.
7+
8+
The `.streamplot.Grid` class, which is internally used by streamplot code, also
9+
throws a ValueError when irregularly gridded values are passed in.

lib/matplotlib/streamplot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ def __init__(self, x, y):
335335
self.width = x[-1] - x[0]
336336
self.height = y[-1] - y[0]
337337

338+
if not np.allclose(np.diff(x), self.width / (self.nx - 1)):
339+
raise ValueError("'x' values must be equally spaced")
340+
if not np.allclose(np.diff(y), self.height / (self.ny - 1)):
341+
raise ValueError("'y' values must be equally spaced")
342+
338343
@property
339344
def shape(self):
340345
return self.ny, self.nx

0 commit comments

Comments
 (0)