using solid colours in surface plots

Hi All,

I wanted to make a surface plot with some phong on it. I can generate the colour map without any problems, but the snag is that no matter what I do, the resulting plot is always transparent. It there a way to set the patch colour to a true solid colour?
Here is a piece of my code (without the phong)

<snip>
colors = np.empty(X.shape, tuple)
for y in range(ylen):
     for x in range(xlen):
         colors[x, y] = (0, 0, 1, 1)

surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,
         linewidth=0.0, antialiased=True)
</snip>

As far as I understand, this should generate a solid blue surface, but this is not what happens. Any hints or solutions?
Cheers,
Zolt�n

2012/1/8 Zoltán Vörös <zvoros@…287…>

colors = np.empty(X.shape, tuple)

for y in range(ylen):

 for x in range(xlen):

     colors[x, y] = (0, 0, 1, 1)

surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,

     linewidth=0.0, antialiased=True)

Is the issue that you have transparent lines between the faces? Set the “shade” kwarg to True and the “antialiased” kwarg to False.

If the shading is not what you want, it has been a feature request to implement the smooth coloring that shading does, but without a lightsource. I have yet to do this, and there have been some attempts to get this right, but nothing finalized yet. Contributions would be welcomed!

Ben Root

Thanks for the reply!

        surf = ax.plot_surface(X, Y, Z, rstride=1,

cstride=1, facecolors=colors,

                linewidth=0.0, antialiased=True)
  Is the issue that you have transparent lines between the faces? 

Set the “shade” kwarg to True and the “antialiased” kwarg to
False.
The problem is that the faces themselves are transparent. But if I
set shade to False, it becomes solid, so that must be the solution.

  If the shading is not what you want, it has been a

feature request to implement the smooth coloring that shading
does, but without a lightsource. I have yet to do this, and there
have been some attempts to get this right, but nothing finalized
yet. Contributions would be welcomed!
OK, I will try to get this done and send you an implementation.

Cheers,

Zoltán

2012/1/9 Zoltán Vörös <zvoros@…287…>

Thanks for the reply!

        surf = ax.plot_surface(X, Y, Z, rstride=1,

cstride=1, facecolors=colors,

                linewidth=0.0, antialiased=True)
  Is the issue that you have transparent lines between the faces? 

Set the “shade” kwarg to True and the “antialiased” kwarg to
False.

The problem is that the faces themselves are transparent. But if I

set shade to False, it becomes solid, so that must be the solution.

  If the shading is not what you want, it has been a

feature request to implement the smooth coloring that shading
does, but without a lightsource. I have yet to do this, and there
have been some attempts to get this right, but nothing finalized
yet. Contributions would be welcomed!

OK, I will try to get this done and send you an implementation.

Cheers,

Zoltán

What version of mpl are you using? For me (on master) I never get transparent faces.

Ben Root

I have 1.0.1 that comes with ubuntu. I was considering installing
1.1, but then I saw that the gtk backend is not supported, so I
decided against it.

By the way, here is an example of the transparent faces (I think it

won’t show on the mailing list). I can definitely see through the
surface. The code I used is

for y in range(ylen):

    for x in range(xlen):

        colors[x, y] = (1, 0.0, 1, 1.)

surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,

facecolors=colors,

        linewidth=0.1, antialiased=False, shade=True)

![dgebgfac.png|656x554](upload://8jh9gqcZnguaAFhKGsQhUX2JBWG.png)
···

On 01/09/2012 05:30 PM, Benjamin Root wrote:

  The problem is that the faces themselves are

transparent. But if I set shade to False, it becomes solid, so
that must be the solution.

  What version of mpl are you using?  For me (on master) I never get

transparent faces.

2012/1/9 Zoltán Vörös <zvoros@…287…>

  The problem is that the faces themselves are

transparent. But if I set shade to False, it becomes solid, so
that must be the solution.

  What version of mpl are you using?  For me (on master) I never get

transparent faces.

I have 1.0.1 that comes with ubuntu. I was considering installing

1.1, but then I saw that the gtk backend is not supported, so I
decided against it.

When we said that GTK is not supported, (1) is not an official decision, I think, (2) we mean the pure GTK backend. We fully support the GTKAgg backend, which is superior to the GTK backend in every way. Please try v1.1.0 before continuing. There were many important changes to mplot3d between v1.0.1 and v1.1.0.

Ben Root

···
On 01/09/2012 05:30 PM, Benjamin Root wrote:

Indeed, that was the case. The surface plot works as advertised now. Thanks for helping out with this! Once I have a viable code for phonging, I will send it to you in a personal mail.
Cheers,
Zolt�n

···

On 01/09/2012 05:46 PM, Benjamin Root wrote:

When we said that GTK is not supported, (1) is not an official decision, I think, (2) we mean the pure GTK *backend*. We fully support the GTKAgg backend, which is superior to the GTK backend in every way. Please try v1.1.0 before continuing. There were many important changes to mplot3d between v1.0.1 and v1.1.0.

Along these lines, it looks to me like plot_surface is not shading when I would expect it to (maybe I just have the wrong expectations?)

I would expect the following to create a surface with colors from the colormap but shading from a lightsource.

  surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,shade=True)

However, axes3d.py requires facecolors to be set in order to generate facecolors to shade...

mpl_toolkits/mplot3d/axes3d.py
line 1378-1380 mpl v1.1.0

        # Shade the data
        if shade and cmap is not None and fcolors is not None:
            fcolors = self._shade_colors_lightsource(Z, cmap, lightsource)

should the if statement be:
        if shade and cmap is not None and fcolors is None:

I'm not sure if this will screw anything else up, but it makes a lot more sense to me as an API. Maybe there are other reasons to require facecolors to be set?

Ethan

···

On Jan 9, 2012, at 10:28 AM, Zoltán Vörös wrote:

On 01/09/2012 05:46 PM, Benjamin Root wrote:

When we said that GTK is not supported, (1) is not an official
decision, I think, (2) we mean the pure GTK *backend*. We fully
support the GTKAgg backend, which is superior to the GTK backend in
every way. Please try v1.1.0 before continuing. There were many
important changes to mplot3d between v1.0.1 and v1.1.0.

Indeed, that was the case. The surface plot works as advertised now.
Thanks for helping out with this! Once I have a viable code for
phonging, I will send it to you in a personal mail.
Cheers,
Zoltán

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

No, you are right. This is roughly the requested feature I was talking about. There are multiple features in plot_surface() that are entwined and I would like to figure out how to separate them and allow users to pick and choose.

Features I have identified:

Coloring edgelines (complicated to determine what color)
Coloring based on colormap
Coloring based on user-spec facecolors
Shading the colors (may or may not include edge lines)

Interpolating facecolors (for edgelines, IIRC)

These are inter-dependent and need to be made orthogonal.

Note, all of this is from memory, details might differ.

Cheers!
Ben Root

···

On Monday, January 9, 2012, Ethan Gutmann <ethan.gutmann@…287…> wrote:

Along these lines, it looks to me like plot_surface is not shading when I would expect it to (maybe I just have the wrong expectations?)

I would expect the following to create a surface with colors from the colormap but shading from a lightsource.

   surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,shade=True)

However, axes3d.py requires facecolors to be set in order to generate facecolors to shade…

mpl_toolkits/mplot3d/axes3d.py
line 1378-1380 mpl v1.1.0

   # Shade the data
   if shade and cmap is not None and fcolors is not None:
       fcolors = self._shade_colors_lightsource(Z, cmap, lightsource)

should the if statement be:
if shade and cmap is not None and fcolors is None:

I’m not sure if this will screw anything else up, but it makes a lot more sense to me as an API. Maybe there are other reasons to require facecolors to be set?

Ethan