# Plotting contour in X-Z plane

Hi All,

I have a question similar to one posted on Aug 30, 2011 titled "Plotting 2D
contourf in Axes3D X-Z plane instead of X-Y plane". In fact, it is the same
question, and I can't seem to find a satisfactory answer anywhere.

I've attached an image of what I've done in the X-Y plane for reference.
Like the other post, I'd like to do something similar to what I've done in
the X-Y direction, but in the X-Z and Y-Z planes. Since I've set up a grid
of points throughout the space, this effectively allows me to take "section
cuts" in different directions in the space. But I can't seem to figure out
how to do it. I've switched around the "z-dir", as well as replacing X and
Y with Z in ax.contourf. For reference, I'm using matplotlib 1.1.0.

I'm trying to achieve a similar affect to Mayavi's 'image_plane_widget' to
take volume slices, but using matplotlib.

http://old.nabble.com/file/p33168965/contours_xy.png

···

--
View this message in context: http://old.nabble.com/Plotting-contour-in-X-Z-plane-tp33168965p33168965.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

What you want is slightly different from what contourf3d does. Most likely, you have a 3D matrix and what you want is to plot representative 2D slices of that matrix with x, y, and z all being spatial coordinates. What contourf3d does is plots 2D data with x and y being spatial and z being the “intensity” value, not the spatial value.

I have an idea of how to do what you want, but I need to test it a bit first. I will get back to you on that.

Ben Root

···

On Thu, Jan 19, 2012 at 10:30 AM, alw46 <amandalaurelwebb@…287…> wrote:

Hi All,

I have a question similar to one posted on Aug 30, 2011 titled "Plotting 2D

contourf in Axes3D X-Z plane instead of X-Y plane". In fact, it is the same

question, and I can’t seem to find a satisfactory answer anywhere.

I’ve attached an image of what I’ve done in the X-Y plane for reference.

Like the other post, I’d like to do something similar to what I’ve done in

the X-Y direction, but in the X-Z and Y-Z planes. Since I’ve set up a grid

of points throughout the space, this effectively allows me to take "section

cuts" in different directions in the space. But I can’t seem to figure out

how to do it. I’ve switched around the “z-dir”, as well as replacing X and

Y with Z in ax.contourf. For reference, I’m using matplotlib 1.1.0.

I’m trying to achieve a similar affect to Mayavi’s ‘image_plane_widget’ to

take volume slices, but using matplotlib.

http://old.nabble.com/file/p33168965/contours_xy.png

View this message in context: http://old.nabble.com/Plotting-contour-in-X-Z-plane-tp33168965p33168965.html

Sent from the matplotlib - users mailing list archive at Nabble.com.

I've attached a function that I think does something similar to what you want, although without quite all of the bells and whistles you're looking for. I'm sure there are better ways than just plotting so many lines, but it worked for quickly looking at some data for me.

Eric

cntr3d.py (1.5 KB)

···

-----Original Message-----
From: alw46 [mailto:amandalaurelwebb@…287…]
Sent: Thursday, January 19, 2012 11:31 AM
To: matplotlib-users@lists.sourceforge.net
Subject: [Matplotlib-users] Plotting contour in X-Z plane

Hi All,

I have a question similar to one posted on Aug 30, 2011 titled
"Plotting 2D
contourf in Axes3D X-Z plane instead of X-Y plane". In fact, it is the
same
question, and I can't seem to find a satisfactory answer anywhere.

I've attached an image of what I've done in the X-Y plane for
reference.
Like the other post, I'd like to do something similar to what I've done
in
the X-Y direction, but in the X-Z and Y-Z planes. Since I've set up a
grid
of points throughout the space, this effectively allows me to take
"section
cuts" in different directions in the space. But I can't seem to figure
out
how to do it. I've switched around the "z-dir", as well as replacing X
and
Y with Z in ax.contourf. For reference, I'm using matplotlib 1.1.0.

I'm trying to achieve a similar affect to Mayavi's 'image_plane_widget'
to
take volume slices, but using matplotlib.

http://old.nabble.com/file/p33168965/contours_xy.png
--
View this message in context: http://old.nabble.com/Plotting-contour-
in-X-Z-plane-tp33168965p33168965.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Eric,

That is a neat example. Do you mind if I clean it up and include it in the mpl gallary?

Ben Root

···

On Thu, Jan 19, 2012 at 12:01 PM, Moore, Eric (NIH/NIDDK) [F] <eric.moore2@…3928…> wrote:

-----Original Message-----

From: alw46 [mailto:amandalaurelwebb@…287…]

Sent: Thursday, January 19, 2012 11:31 AM

Subject: [Matplotlib-users] Plotting contour in X-Z plane

Hi All,

I have a question similar to one posted on Aug 30, 2011 titled

"Plotting 2D

contourf in Axes3D X-Z plane instead of X-Y plane". In fact, it is the

same

question, and I can’t seem to find a satisfactory answer anywhere.

I’ve attached an image of what I’ve done in the X-Y plane for

reference.

Like the other post, I’d like to do something similar to what I’ve done

in

the X-Y direction, but in the X-Z and Y-Z planes. Since I’ve set up a

grid

of points throughout the space, this effectively allows me to take

"section

cuts" in different directions in the space. But I can’t seem to figure

out

how to do it. I’ve switched around the “z-dir”, as well as replacing X

and

Y with Z in ax.contourf. For reference, I’m using matplotlib 1.1.0.

I’m trying to achieve a similar affect to Mayavi’s ‘image_plane_widget’

to

take volume slices, but using matplotlib.

http://old.nabble.com/file/p33168965/contours_xy.png

View this message in context: http://old.nabble.com/Plotting-contour-

in-X-Z-plane-tp33168965p33168965.html

Sent from the matplotlib - users mailing list archive at Nabble.com.

I’ve attached a function that I think does something similar to what you want, although without quite all of the bells and whistles you’re looking for. I’m sure there are better ways than just plotting so many lines, but it worked for quickly looking at some data for me.

Eric

From:
ben.v.root@…287… [mailto:ben.v.root@…287…] On Behalf Of Benjamin
Root

···

Sent: Monday, January 23, 2012 10:49 AM
To: Moore, Eric (NIH/NIDDK) [F]
Cc: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] Plotting contour in X-Z plane

On Thu, Jan 19, 2012 at 12:01 PM, Moore, Eric (NIH/NIDDK) [F] <eric.moore2@…3928…> wrote:

-----Original Message-----
From: alw46 [mailto:amandalaurelwebb@…287…]
Sent: Thursday, January 19, 2012 11:31 AM
To: matplotlib-users@lists.sourceforge.net
Subject: [Matplotlib-users] Plotting contour in X-Z plane

Hi All,

I have a question similar to one posted on Aug 30, 2011 titled
“Plotting 2D
contourf in Axes3D X-Z plane instead of X-Y plane”. In fact, it
is the
same
question, and I can’t seem to find a satisfactory answer anywhere.

I’ve attached an image of what I’ve done in the X-Y plane for
reference.
Like the other post, I’d like to do something similar to what I’ve done
in
the X-Y direction, but in the X-Z and Y-Z planes. Since I’ve set up
a
grid
of points throughout the space, this effectively allows me to take
“section
cuts” in different directions in the space. But I can’t seem to
figure
out
how to do it. I’ve switched around the “z-dir”, as well as
replacing X
and
Y with Z in ax.contourf. For reference, I’m using matplotlib 1.1.0.

I’m trying to achieve a similar affect to Mayavi’s ‘image_plane_widget’
to
take volume slices, but using matplotlib.

## http://old.nabble.com/file/p33168965/contours_xy.png

View this message in context: http://old.nabble.com/Plotting-contour-
in-X-Z-plane-tp33168965p33168965.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I’ve attached a function that I
think does something similar to what you want, although without quite all of
the bells and whistles you’re looking for. I’m sure there are better ways
than just plotting so many lines, but it worked for quickly looking at some
data for me.

Eric

Eric,

That is a neat example. Do you mind if I clean it up and include it in
the mpl gallary?

Ben Root

Ben,

free to do so.

Eric

Hi Eric,

First, thanks for the sample - I agree that it's a neat example and I really
appreciate the help.

Second, I've tried to adapt your code to my specific situation and I'm
running into a problem: it's not printing all the levels that I'm
specifying. Do you have any insights into why? I can't seem to find any
documentation on the cntr.cntr method, so I'm just trial-and-erroring it for
now.

I'd like it to print more than 6 contour levels (why did you have this
limit?), so I changed your error statement. I've also used a 10x10x10 grid,
and put in my own data for the 'v' set.

Also, I've simplified it so that it's only displaying in the X-Y plane, and
so that it's only displaying one "slice" in that plane. I'm asking it to
display contours every 0.1, between 3.0 and 4.0, but some contours are
missing, and come up as empty arrays when I print 'c'.

http://old.nabble.com/file/p33197575/cntr3d_alw.py cntr3d_alw.py

Thanks!
Amanda

···

--
View this message in context: http://old.nabble.com/Plotting-contour-in-X-Z-plane-tp33168965p33197575.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

From: alw46 [mailto:amandalaurelwebb@…287…]
Sent: Tuesday, January 24, 2012 3:40 PM
To: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] Plotting contour in X-Z plane

Hi Eric,

First, thanks for the sample - I agree that it's a neat example and I
really
appreciate the help.

Second, I've tried to adapt your code to my specific situation and I'm
running into a problem: it's not printing all the levels that I'm
specifying. Do you have any insights into why? I can't seem to find
any
documentation on the cntr.cntr method, so I'm just trial-and-erroring
it for
now.

Running the code you posted, I don't see any failures. The simplest way to check if is producing all of the contours that it should is to use the contour() function to plot the contours in each plane separately, and see that what it plots is identical to what contour3D() plots in each plane. When I do that, everything looks okay.

For instance, in the v[:,:,0] plane, the nominally missing contours are at 3, 3.1111, and 3.2222. However, if we ask if we should see these contours, by evaluating v[:,:,0].min() = 3.307, the answer is no, since they are all smaller than the minimum v in that plane. I haven't repeated this analysis for the other 9 planes, but I suspect it also follows there.

For reference, the Cntr object is defined by mpl as a C extension (code here: https://github.com/matplotlib/matplotlib/blob/master/src/cntr.c ). To display the small amount of help that it comes with call help(cntr.Cntr) in ipython. (Using cntr.Cntr? won't find the help.) I think that the entire cntr module is really an internal detail, hence the lack of user facing documentation.

I'd like it to print more than 6 contour levels (why did you have this
limit?), so I changed your error statement. I've also used a 10x10x10
grid,
and put in my own data for the 'v' set.

I limited it to 6 levels since my mesh was much denser and really with more than 1 or 2 levels there were too many lines to see anything useful. Rotating the view also becomes slow if the number of lines becomes excessively large.

Also, I've simplified it so that it's only displaying in the X-Y plane,
and
so that it's only displaying one "slice" in that plane. I'm asking it
to
display contours every 0.1, between 3.0 and 4.0, but some contours are
missing, and come up as empty arrays when I print 'c'.

FYI, your code does r_[3:4:10j] which gives 3.0 to 4.0 inclusive in steps of 1/9, rather than steps of 1/10, since when called this way r_[] is endpoint inclusive.