Skip to content
Advertisement

Contourf on the faces of a Matplotlib cube

I am trying to ‘paint’ the faces of a cube with a contourf function using Python Matplotlib. Is this possible?

This is similar idea to what was done here but obviously I cannot use patches. Similarly, I don’t think I can use add_collection3d like this as it only supports PolyCollection, LineColleciton and PatchCollection.

I have been trying to use contourf on a fig.gca(projection='3d'). Toy example below.

JavaScript

1 From the example, the top surface comes easily:
example plot #1

2 But I’m not sure how to do the sides. Left side of this plot is what the section should look like (but rotated)…
example plot #2

Open to other python approaches. The data I’m actually plotting are geophysical netcdf files.

Advertisement

Answer

You have to assign the data to the right axis. The zig-zag results from the fact that now you are at x = const and have your oscillation in the z-direction (from the random data, which is generated between 0 and 1).
If you you assign the matrixes differently in your example, you end up with the desired result:

JavaScript

The result looks like this:

contour cube

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement