 # Plotting 2D contourf in Axes3D X-Z plane instead of X-Y plane

Hi All,

I have a 2D grid comprised of 100 nodes in X, 300 nodes in Z, and a single node in Y. I have a scalar value defined at each node point.

I want to display this planar grid in 3D by first rendering a contour plot (no problems there) and then rotating it such that it plots as a vertical sheet when viewed in 3D. Right now it is automatically forced to reside in the X-Y plane, but I want it to reside in the X-Z plane. Here is an excerpt from my code:

fig = plt.figure(figsize=(25,20))
ax = Axes3D(fig)
ax.contourf(xx, yy, zz, 100, cmp = plt.cm.jet,zdir=‘y’,extend3D=False)
plt.hold(True)
ax.bar3d(5000, 625, 1500, 1, 1, 1, color=‘r’)
ax.set_xlabel(“X [m]”)
ax.set_ylabel(“Y [m]”)
ax.set_zlabel(“Z [m]”)
plt.savefig(“Feature.png”,dpi=200)

I think the ‘zdir’ flag is supposed to do this exact task, but setting it to ‘y’ seems to have no effect on my plot. Also, the plot is being extended into 3D even though I set the extend3D flag to False. Can anyone tell me what I’m doing wrong?

Cheers!

What version of mpl are you using? I don’t think those kwargs were added until the upcoming release, v1.1.0. Does the graph look right if you do just contour?

Plus, from the top of my head, I don’t think extend3d works for contourf (but I could be wrong).

Ben Root

···

On Tuesday, August 30, 2011, Katie Boyle <katielboyle@…287…> wrote:

Hi All,

I have a 2D grid comprised of 100 nodes in X, 300 nodes in Z, and a single node in Y. I have a scalar value defined at each node point.

I want to display this planar grid in 3D by first rendering a contour plot (no problems there) and then rotating it such that it plots as a vertical sheet when viewed in 3D. Right now it is automatically forced to reside in the X-Y plane, but I want it to reside in the X-Z plane. Here is an excerpt from my code:

fig = plt.figure(figsize=(25,20))
ax = Axes3D(fig)
ax.contourf(xx, yy, zz, 100, cmp = plt.cm.jet,zdir=‘y’,extend3D=False)
plt.hold(True)
ax.bar3d(5000, 625, 1500, 1, 1, 1, color=‘r’)

ax.set_xlabel(“X [m]”)
ax.set_ylabel(“Y [m]”)
ax.set_zlabel(“Z [m]”)
plt.savefig(“Feature.png”,dpi=200)

I think the ‘zdir’ flag is supposed to do this exact task, but setting it to ‘y’ seems to have no effect on my plot. Also, the plot is being extended into 3D even though I set the extend3D flag to False. Can anyone tell me what I’m doing wrong?

Cheers!

Hi Ben,

I’m using mpl 0.99 on Ubuntu 10.10, and whether I use contour or
contourf I get a plot that is laying in the X-Y plane with contour
loops extending into the +z direction. The contour plot itself looks
right (if I could get it to be 2D instead of 3D), it’s just its
orientation and non-planarity that pose problems.

Cheers,
Katie

···

On Tue, Aug 30, 2011 at 5:22 PM, Benjamin Root <ben.root@…1304…> wrote:

On Tuesday, August 30, 2011, Katie Boyle <katielboyle@…287…> wrote:

Hi All,

I have a 2D grid comprised of 100 nodes in X, 300 nodes in Z, and a single node in Y. I have a scalar value defined at each node point.

I want to display this planar grid in 3D by first rendering a contour plot (no problems there) and then rotating it such that it plots as a vertical sheet when viewed in 3D. Right now it is automatically forced to reside in the X-Y plane, but I want it to reside in the X-Z plane. Here is an excerpt from my code:

fig = plt.figure(figsize=(25,20))
ax = Axes3D(fig)
ax.contourf(xx, yy, zz, 100, cmp = plt.cm.jet,zdir=‘y’,extend3D=False)
plt.hold(True)
ax.bar3d(5000, 625, 1500, 1, 1, 1, color=‘r’)

ax.set_xlabel(“X [m]”)
ax.set_ylabel(“Y [m]”)
ax.set_zlabel(“Z [m]”)
plt.savefig(“Feature.png”,dpi=200)

I think the ‘zdir’ flag is supposed to do this exact task, but setting it to ‘y’ seems to have no effect on my plot. Also, the plot is being extended into 3D even though I set the extend3D flag to False. Can anyone tell me what I’m doing wrong?

Cheers!

What version of mpl are you using? I don’t think those kwargs were added until the upcoming release, v1.1.0. Does the graph look right if you do just contour?

Plus, from the top of my head, I don’t think extend3d works for contourf (but I could be wrong).

Ben Root

Posting an image would be very helpful. In addition, I don’t think v0.99 supports what you are trying to do. But perhaps the image would make things clearer.

Ben Root

···

On Tuesday, August 30, 2011, Katie Boyle <katielboyle@…287…> wrote:

Hi Ben,

I’m using mpl 0.99 on Ubuntu 10.10, and whether I use contour or contourf I get a plot that is laying in the X-Y plane with contour loops extending into the +z direction. The contour plot itself looks right (if I could get it to be 2D instead of 3D), it’s just its orientation and non-planarity that pose problems.

Cheers,
Katie