pyplot.contourf() returns error when specified levels argument
up vote
1
down vote
favorite
EDIT: The issue is most likely about the version. The levels
argument takes an integer argument in version 3.0.0, while this issue has occurred while using version 2.2.2.
I'm trying to make a contour plot in Python using the matplotlib.pyplot.contourf()
function, and it works perfectly like this:
plt.contourf(x, y, z)
but when I try to specify an integer for the levels argument, like this:
plt.contourf(x, y, z, levels=100)
it always returns the error: TypeError: len() of unsized object
In the documentation, it says that the argument levels
can be either int
or array_like
so I don't know why it would even call the len()
function
Any ideas why this happens and any suggestion on how to fix it?
python matplotlib typeerror contourf
add a comment |
up vote
1
down vote
favorite
EDIT: The issue is most likely about the version. The levels
argument takes an integer argument in version 3.0.0, while this issue has occurred while using version 2.2.2.
I'm trying to make a contour plot in Python using the matplotlib.pyplot.contourf()
function, and it works perfectly like this:
plt.contourf(x, y, z)
but when I try to specify an integer for the levels argument, like this:
plt.contourf(x, y, z, levels=100)
it always returns the error: TypeError: len() of unsized object
In the documentation, it says that the argument levels
can be either int
or array_like
so I don't know why it would even call the len()
function
Any ideas why this happens and any suggestion on how to fix it?
python matplotlib typeerror contourf
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
EDIT: The issue is most likely about the version. The levels
argument takes an integer argument in version 3.0.0, while this issue has occurred while using version 2.2.2.
I'm trying to make a contour plot in Python using the matplotlib.pyplot.contourf()
function, and it works perfectly like this:
plt.contourf(x, y, z)
but when I try to specify an integer for the levels argument, like this:
plt.contourf(x, y, z, levels=100)
it always returns the error: TypeError: len() of unsized object
In the documentation, it says that the argument levels
can be either int
or array_like
so I don't know why it would even call the len()
function
Any ideas why this happens and any suggestion on how to fix it?
python matplotlib typeerror contourf
EDIT: The issue is most likely about the version. The levels
argument takes an integer argument in version 3.0.0, while this issue has occurred while using version 2.2.2.
I'm trying to make a contour plot in Python using the matplotlib.pyplot.contourf()
function, and it works perfectly like this:
plt.contourf(x, y, z)
but when I try to specify an integer for the levels argument, like this:
plt.contourf(x, y, z, levels=100)
it always returns the error: TypeError: len() of unsized object
In the documentation, it says that the argument levels
can be either int
or array_like
so I don't know why it would even call the len()
function
Any ideas why this happens and any suggestion on how to fix it?
python matplotlib typeerror contourf
python matplotlib typeerror contourf
edited Nov 16 at 18:52
asked Nov 10 at 20:52
vejtics
133
133
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Sorry, this happens to you. The documentation changed in version 2.2.3 without this feature being fully implemented. So depending on the version of matplotlib the levels
argument is interpreted differently.
matplotlib < 3.0.0
levels
is interpreted as a list of levels where to draw contours. An integer is interpreted as a single level. For a contourf
(a filled contour) plot you need at least two levels. Use the previously known way to specfify the number of levels as the second or fourth unnamed argument
plt.contourf(z, 100)
plt.contourf(x, y, z, 100)
matplotlib >= 3.0.0
levels
can take either a list or an integer. When an integer, it signifies the (approximate [*]) number of levels. The relevant PR is this.
plt.contourf(z, levels=100)
plt.contourf(x, y, z, levels=100)
This shouldn't be the case, but perhaps I have a version older than 3.0.0.
– vejtics
Nov 16 at 0:33
I checked. That's indeed the issue (I was running version 2.2.2).
– vejtics
Nov 16 at 18:49
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Sorry, this happens to you. The documentation changed in version 2.2.3 without this feature being fully implemented. So depending on the version of matplotlib the levels
argument is interpreted differently.
matplotlib < 3.0.0
levels
is interpreted as a list of levels where to draw contours. An integer is interpreted as a single level. For a contourf
(a filled contour) plot you need at least two levels. Use the previously known way to specfify the number of levels as the second or fourth unnamed argument
plt.contourf(z, 100)
plt.contourf(x, y, z, 100)
matplotlib >= 3.0.0
levels
can take either a list or an integer. When an integer, it signifies the (approximate [*]) number of levels. The relevant PR is this.
plt.contourf(z, levels=100)
plt.contourf(x, y, z, levels=100)
This shouldn't be the case, but perhaps I have a version older than 3.0.0.
– vejtics
Nov 16 at 0:33
I checked. That's indeed the issue (I was running version 2.2.2).
– vejtics
Nov 16 at 18:49
add a comment |
up vote
1
down vote
accepted
Sorry, this happens to you. The documentation changed in version 2.2.3 without this feature being fully implemented. So depending on the version of matplotlib the levels
argument is interpreted differently.
matplotlib < 3.0.0
levels
is interpreted as a list of levels where to draw contours. An integer is interpreted as a single level. For a contourf
(a filled contour) plot you need at least two levels. Use the previously known way to specfify the number of levels as the second or fourth unnamed argument
plt.contourf(z, 100)
plt.contourf(x, y, z, 100)
matplotlib >= 3.0.0
levels
can take either a list or an integer. When an integer, it signifies the (approximate [*]) number of levels. The relevant PR is this.
plt.contourf(z, levels=100)
plt.contourf(x, y, z, levels=100)
This shouldn't be the case, but perhaps I have a version older than 3.0.0.
– vejtics
Nov 16 at 0:33
I checked. That's indeed the issue (I was running version 2.2.2).
– vejtics
Nov 16 at 18:49
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Sorry, this happens to you. The documentation changed in version 2.2.3 without this feature being fully implemented. So depending on the version of matplotlib the levels
argument is interpreted differently.
matplotlib < 3.0.0
levels
is interpreted as a list of levels where to draw contours. An integer is interpreted as a single level. For a contourf
(a filled contour) plot you need at least two levels. Use the previously known way to specfify the number of levels as the second or fourth unnamed argument
plt.contourf(z, 100)
plt.contourf(x, y, z, 100)
matplotlib >= 3.0.0
levels
can take either a list or an integer. When an integer, it signifies the (approximate [*]) number of levels. The relevant PR is this.
plt.contourf(z, levels=100)
plt.contourf(x, y, z, levels=100)
Sorry, this happens to you. The documentation changed in version 2.2.3 without this feature being fully implemented. So depending on the version of matplotlib the levels
argument is interpreted differently.
matplotlib < 3.0.0
levels
is interpreted as a list of levels where to draw contours. An integer is interpreted as a single level. For a contourf
(a filled contour) plot you need at least two levels. Use the previously known way to specfify the number of levels as the second or fourth unnamed argument
plt.contourf(z, 100)
plt.contourf(x, y, z, 100)
matplotlib >= 3.0.0
levels
can take either a list or an integer. When an integer, it signifies the (approximate [*]) number of levels. The relevant PR is this.
plt.contourf(z, levels=100)
plt.contourf(x, y, z, levels=100)
edited Nov 10 at 21:32
answered Nov 10 at 21:12
ImportanceOfBeingErnest
119k10117190
119k10117190
This shouldn't be the case, but perhaps I have a version older than 3.0.0.
– vejtics
Nov 16 at 0:33
I checked. That's indeed the issue (I was running version 2.2.2).
– vejtics
Nov 16 at 18:49
add a comment |
This shouldn't be the case, but perhaps I have a version older than 3.0.0.
– vejtics
Nov 16 at 0:33
I checked. That's indeed the issue (I was running version 2.2.2).
– vejtics
Nov 16 at 18:49
This shouldn't be the case, but perhaps I have a version older than 3.0.0.
– vejtics
Nov 16 at 0:33
This shouldn't be the case, but perhaps I have a version older than 3.0.0.
– vejtics
Nov 16 at 0:33
I checked. That's indeed the issue (I was running version 2.2.2).
– vejtics
Nov 16 at 18:49
I checked. That's indeed the issue (I was running version 2.2.2).
– vejtics
Nov 16 at 18:49
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243303%2fpyplot-contourf-returns-error-when-specified-levels-argument%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown