Skip to content

API/FIX : don't accept None for x or y in plot #4352

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

Merged
merged 1 commit into from
Apr 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions doc/api/api_changes/2015-04-08_plot_noNone.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Disallow ``None`` as x or y value in ax.plot
````````````````````````````````````````````

Do not allow ``None`` as a valid input for the ``x`` or ``y`` args in
`ax.plot`. This may break some user code, but this was never officially
supported (ex documented) and allowing ``None`` objects through can lead
to confusing exceptions downstream.

To create an empty line use ::

ln1, = ax.plot([], [], ...)
ln2, = ax.plot([], ...)

In either case to update the data in the `Line2D` object you must update
both the ``x`` and ``y`` data.
7 changes: 7 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ def _plot_args(self, tup, kwargs):
raise ValueError('third arg must be a format string')
else:
linestyle, marker, color = None, None, None

# Don't allow any None value; These will be up-converted
# to one element array of None which causes problems
# downstream.
if any(v is None for v in tup):
raise ValueError("x and y must not be None")

kw = {}
for k, v in zip(('linestyle', 'marker', 'color'),
(linestyle, marker, color)):
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3668,6 +3668,13 @@ def test_bar_negative_width():
assert_equal(b._height, indx + 1)


@cleanup
def test_no_None():
fig, ax = plt.subplots()
assert_raises(ValueError, plt.plot, None)
assert_raises(ValueError, plt.plot, None, None)


if __name__ == '__main__':
import nose
import sys
Expand Down