contour3D custom levels possible?

Hello everyone,

does anybody know why the contour3D function has a fixed set of levels?

contour3D(X, Y, Z, levels=10, **kwargs)

I want to plot only one line for one level. With "contourf" it works:

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt

fig = plt.figure()
ax = axes3d.Axes3D(fig)
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contourf(X, Y, Z, 0) # doesn't work with contour
ax.clabel(cset, fontsize=9, inline=1)

plt.show()

Many greetings,
Tom

Hello everyone,

does anybody know why the contour3D function has a fixed set of levels?

contour3D(X, Y, Z, levels=10, **kwargs)

I want to plot only one line for one level. With "contourf" it works:

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt

fig = plt.figure()
ax = axes3d.Axes3D(fig)
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contourf(X, Y, Z, 0) # doesn't work with contour

This is a fluke. Try

cset = ax.contour(X, Y, Z, [0])

and the same for contour3d. When the levels arg or kwarg is a scalar, it specifies the number of levels to be found via auto-scaling; when it is a sequence, it specifies the actual levels.

Eric

···

On 08/01/2010 04:55 AM, Tom Arens wrote:

ax.clabel(cset, fontsize=9, inline=1)

plt.show()

Many greetings,
Tom

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hmm, interesting. Looking at the contour3d call signature, it appears that ‘levels’ was put into the call signature to basically remove that keyword argument from the kwargs that get passed down to the 2-d version of contour. It is never used in the body of contour3d().

I would guess that this is might be a remnant of some original code that actually used the levels parameter. Simply removing levels=0 from the call signature seems to fix it (and passing [0] to levels as well since it expects a sequence).

As a matter of consistency, I think the call signature should be changed to better match the call signature for contourf3d() and for the 2-d version of contour().

Ben Root

contour3d_call.patch (1.11 KB)

···

On Sun, Aug 1, 2010 at 9:55 AM, Tom Arens <takker@…380…> wrote:

Hello everyone,

does anybody know why the contour3D function has a fixed set of levels?

contour3D(X, Y, Z, levels=10, **kwargs)

I want to plot only one line for one level. With “contourf” it works:

from mpl_toolkits.mplot3d import axes3d

import matplotlib.pyplot as plt

fig = plt.figure()

ax = axes3d.Axes3D(fig)

X, Y, Z = axes3d.get_test_data(0.05)

cset = ax.contourf(X, Y, Z, 0) # doesn’t work with contour

ax.clabel(cset, fontsize=9, inline=1)

plt.show()

Many greetings,

Tom

    Hello everyone,

    does anybody know why the contour3D function has a fixed set of levels?

    contour3D(X, Y, Z, levels=10, **kwargs)

    I want to plot only one line for one level. With "contourf" it works:

    from mpl_toolkits.mplot3d import axes3d
    import matplotlib.pyplot as plt

    fig = plt.figure()
    ax = axes3d.Axes3D(fig)
    X, Y, Z = axes3d.get_test_data(0.05)
    cset = ax.contourf(X, Y, Z, 0) # doesn't work with contour
    ax.clabel(cset, fontsize=9, inline=1)

    plt.show()

    Many greetings,
    Tom

Hmm, interesting. Looking at the contour3d call signature, it appears
that 'levels' was put into the call signature to basically remove that
keyword argument from the kwargs that get passed down to the 2-d version
of contour. It is never used in the body of contour3d().

I would guess that this is might be a remnant of some original code that
actually used the levels parameter. Simply removing levels=0 from the
call signature seems to fix it (and passing [0] to levels as well since
it expects a sequence).

As a matter of consistency, I think the call signature should be changed
to better match the call signature for contourf3d() and for the 2-d
version of contour().

Ben,

Good idea, go ahead. The contourf3d docstring can also be modified to match your change to the contour3d docstring.

I would consider all this as bug-fixing, so it can go in branch and trunk.

Thanks.

Eric

···

On 08/01/2010 07:35 AM, Benjamin Root wrote:

On Sun, Aug 1, 2010 at 9:55 AM, Tom Arens <takker@...380... > <mailto:takker@…380…>> wrote:

Ben Root

Hello,

I thought that it has to be like Ben wrote:

- def contour(self, X, Y, Z, levels=10, **kwargs):
+ def contour(self, X, Y, Z, *args, **kwargs):

Your suggestion Eric ( contour(X, Y, Z, [0] ) doesn't work as the levels
are still the same.

Can you translate this thread for a "normal" user? Is this a bug and
will be fixed in a newer version of matplotlib or what do I have to do
to get "less levels"?

Thank you for your help.
Tom

···

Am 01.08.2010 20:12 schrieb Eric Firing:

On 08/01/2010 07:35 AM, Benjamin Root wrote:

On Sun, Aug 1, 2010 at 9:55 AM, Tom Arens <takker@...380... >> <mailto:takker@…380…>> wrote:

    Hello everyone,

    does anybody know why the contour3D function has a fixed set of levels?

    contour3D(X, Y, Z, levels=10, **kwargs)

    I want to plot only one line for one level. With "contourf" it works:

    from mpl_toolkits.mplot3d import axes3d
    import matplotlib.pyplot as plt

    fig = plt.figure()
    ax = axes3d.Axes3D(fig)
    X, Y, Z = axes3d.get_test_data(0.05)
    cset = ax.contourf(X, Y, Z, 0) # doesn't work with contour
    ax.clabel(cset, fontsize=9, inline=1)

    plt.show()

    Many greetings,
    Tom

Hmm, interesting. Looking at the contour3d call signature, it appears
that 'levels' was put into the call signature to basically remove that
keyword argument from the kwargs that get passed down to the 2-d version
of contour. It is never used in the body of contour3d().

I would guess that this is might be a remnant of some original code that
actually used the levels parameter. Simply removing levels=0 from the
call signature seems to fix it (and passing [0] to levels as well since
it expects a sequence).

As a matter of consistency, I think the call signature should be changed
to better match the call signature for contourf3d() and for the 2-d
version of contour().

Ben,

Good idea, go ahead. The contourf3d docstring can also be modified to
match your change to the contour3d docstring.

I would consider all this as bug-fixing, so it can go in branch and trunk.

Thanks.

Eric

Ben Root

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Tom, it is a bug and it is currently getting patched in the released v1.0 of matplotlib. I am double-checking a few things in the tests before fully committing it. If you want, you can either install the revised v1.0 of matplotlib (when it is ready), or you can edit the axes3d.py file yourself to fix the function header.

Thank you for noticing this error.

Ben Root

···

On Sun, Aug 1, 2010 at 3:48 PM, Tom Arens <takker@…380…> wrote:

Hello,

I thought that it has to be like Ben wrote:

  • def contour(self, X, Y, Z, levels=10, **kwargs):
  • def contour(self, X, Y, Z, *args, **kwargs):

Your suggestion Eric ( contour(X, Y, Z, [0] ) doesn’t work as the levels

are still the same.

Can you translate this thread for a “normal” user? Is this a bug and

will be fixed in a newer version of matplotlib or what do I have to do

to get “less levels”?

Thank you for your help.

Tom

Ok, this has been committed to v1.0 as r8610 and merged to trunk as r8611. I should note that the image for contour3d_demo2.py will be changed (personally, for the better). I don’t know if something needs to be done for that.

Ben Root

···

On Sun, Aug 1, 2010 at 4:10 PM, Benjamin Root <ben.root@…3176…> wrote:

On Sun, Aug 1, 2010 at 3:48 PM, Tom Arens <takker@…380…> wrote:

Hello,

I thought that it has to be like Ben wrote:

  • def contour(self, X, Y, Z, levels=10, **kwargs):
  • def contour(self, X, Y, Z, *args, **kwargs):

Your suggestion Eric ( contour(X, Y, Z, [0] ) doesn’t work as the levels

are still the same.

Can you translate this thread for a “normal” user? Is this a bug and

will be fixed in a newer version of matplotlib or what do I have to do

to get “less levels”?

Thank you for your help.

Tom

Tom, it is a bug and it is currently getting patched in the released v1.0 of matplotlib. I am double-checking a few things in the tests before fully committing it. If you want, you can either install the revised v1.0 of matplotlib (when it is ready), or you can edit the axes3d.py file yourself to fix the function header.

Thank you for noticing this error.

Ben Root