Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
2D Colour Plot from 3D Data

Subject: 2D Colour Plot from 3D Data

From: Sam

Date: 20 Aug, 2009 20:24:19

Message: 1 of 12

Hello,

I'm currently stuck on a problem, I have a large matrix, with X, Y, Z values (~4000 in each)

What I want to do is plot, in 2D X and Y as axis, and then have boxes filled with colour according to the appropriate value in Z.

Much like a colourful chess/chequers board.

I'm sure there must be a reasonably easy solution to this, but I have limited MATLAB experience and am considering using C++ in ROOT to solve this.

For interest: This is being used to map data 'quality' taken in a Neutrino Physics experiment, we have over a year's worth of raw audio (30TB!) and have designed algorithms to classify each file with a quality, to reduce processing time by ignoring bad files. Thus the X axis correspond to the date, the Y axis to the time (in24hours) and the Z axis the quality of the file present at that point.

Any help is appreciated.
-Sam

Subject: 2D Colour Plot from 3D Data

From: Cheryl

Date: 20 Aug, 2009 21:17:58

Message: 2 of 12


try:

pcolor(X,Y,Z(i)); shading flat
or imagesc()

where i is the z-level you want to visualize
you might have to transpose an array to get it to work


> I'm currently stuck on a problem, I have a large matrix, with X, Y, Z values (~4000 in each)
>
> What I want to do is plot, in 2D X and Y as axis, and then have boxes filled with colour according to the appropriate value in Z.
>
> Much like a colourful chess/chequers board.
>
> I'm sure there must be a reasonably easy solution to this, but I have limited MATLAB experience and am considering using C++ in ROOT to solve this.
>
> For interest: This is being used to map data 'quality' taken in a Neutrino Physics experiment, we have over a year's worth of raw audio (30TB!) and have designed algorithms to classify each file with a quality, to reduce processing time by ignoring bad files.  Thus the X axis correspond to the date, the Y axis to the time (in24hours) and the Z axis the quality of the file present at that point.
>
> Any help is appreciated.
> -Sam

Subject: 2D Colour Plot from 3D Data

From: Sam

Date: 21 Aug, 2009 09:27:03

Message: 3 of 12

Cheryl <chsharrison@gmail.com> wrote in message <29269db5-4142-46ae-9293-71fcf69eee01@v23g2000pro.googlegroups.com>...
>
> try:
>
> pcolor(X,Y,Z(i)); shading flat
> or imagesc()
>
> where i is the z-level you want to visualize
> you might have to transpose an array to get it to work
>
>


Hello,

I tried the method above, but cannot get it to work.

I do not want to visualise a single layer (z-level) of data, I want to visualise every piece. Each X(i) and Y(i) maps to only one Z(i).

I made a typo in my original post, X, Y, Z are all column vectors,
eg:
X Y Z
12 0105 10
12 0106 8


Cheers for your help though, anymore is greatly appreciated.

-Sam

Subject: 2D Colour Plot from 3D Data

From: Bruno Luong

Date: 21 Aug, 2009 09:37:02

Message: 4 of 12

"Sam " <phb06sd@shef.ac.uk> wrote in message <h6lp97$2ku$1@fred.mathworks.com>...
> Cheryl <chsharrison@gmail.com> wrote in message <29269db5-4142-46ae-9293-71fcf69eee01@v23g2000pro.googlegroups.com>...
> >
> > try:
> >
> > pcolor(X,Y,Z(i)); shading flat
> > or imagesc()
> >
> > where i is the z-level you want to visualize
> > you might have to transpose an array to get it to work
> >
> >
>
>
> Hello,
>
> I tried the method above, but cannot get it to work.
>
> I do not want to visualise a single layer (z-level) of data, I want to visualise every piece. Each X(i) and Y(i) maps to only one Z(i).
>
> I made a typo in my original post, X, Y, Z are all column vectors,
> eg:
> X Y Z
> 12 0105 10
> 12 0106 8
>

try

tri = delaunay(X(:),Y(:));
trisurf(tri,X(:),Y(:),Z(:));

% Bruno

Subject: 2D Colour Plot from 3D Data

From: T

Date: 21 Aug, 2009 11:13:02

Message: 5 of 12

image(z) should do the trick.

I have once modified pcolor to draw exactly what you want, draw boxes centred on the x/y/z values, instead of x/y for corners. Never put it on the fex though. You could also just duplicate the bottom and left row/column of x and y, and then use pcolor

Subject: 2D Colour Plot from 3D Data

From: Luigi Giaccari

Date: 27 Aug, 2009 21:29:03

Message: 6 of 12

"Sam " <phb06sd@shef.ac.uk> wrote in message <h6kbdj$b2l$1@fred.mathworks.com>...
> Hello,
>
> I'm currently stuck on a problem, I have a large matrix, with X, Y, Z values (~4000 in each)
>
> What I want to do is plot, in 2D X and Y as axis, and then have boxes filled with colour according to the appropriate value in Z.
>
> Much like a colourful chess/chequers board.
>
> I'm sure there must be a reasonably easy solution to this, but I have limited MATLAB experience and am considering using C++ in ROOT to solve this.
>
> For interest: This is being used to map data 'quality' taken in a Neutrino Physics experiment, we have over a year's worth of raw audio (30TB!) and have designed algorithms to classify each file with a quality, to reduce processing time by ignoring bad files. Thus the X axis correspond to the date, the Y axis to the time (in24hours) and the Z axis the quality of the file present at that point.
>
> Any help is appreciated.
> -Sam

Here is the solution

1- grid X and Y vectors with:

 http://www.mathworks.com/matlabcentral/fileexchange/23916

this will produce a triangular mesh, you can modify the code to produce quad patches.

2- Once you have the triangulation you can use "trisurf" command to plot the surface (triangualr patches). Be carefull on how to assign the colormap, each point according to your description must have a color value according to Z initial value.

In any case you will have to batch your code, your dataset is too large, memory errors may occur.

If you have problems contact me or send me a demo.

http://www.advancedmcode.org/

Subject: 2D Colour Plot from 3D Data

From: sagar poudel

Date: 26 Jan, 2012 23:02:10

Message: 7 of 12

Hi Sam
I am stucked with the same problem. 3 data values but need to plot 2D graph (X,Y) with third point (Z) representing the values with unique color. I tried to look at these solutions, the last one seems convincing but was not able to open it. If you were able to solve the problem, can you send me the code or a way to deal with this problem?

Thank you for your help.

Sagar

"Sam " <phb06sd@shef.ac.uk> wrote in message <h6kbdj$b2l$1@fred.mathworks.com>...
> Hello,
>
> I'm currently stuck on a problem, I have a large matrix, with X, Y, Z values (~4000 in each)
>
> What I want to do is plot, in 2D X and Y as axis, and then have boxes filled with colour according to the appropriate value in Z.
>
> Much like a colourful chess/chequers board.
>
> I'm sure there must be a reasonably easy solution to this, but I have limited MATLAB experience and am considering using C++ in ROOT to solve this.
>
> For interest: This is being used to map data 'quality' taken in a Neutrino Physics experiment, we have over a year's worth of raw audio (30TB!) and have designed algorithms to classify each file with a quality, to reduce processing time by ignoring bad files. Thus the X axis correspond to the date, the Y axis to the time (in24hours) and the Z axis the quality of the file present at that point.
>
> Any help is appreciated.
> -Sam

Subject: 2D Colour Plot from 3D Data

From: Zhiting

Date: 28 Mar, 2012 18:25:11

Message: 8 of 12

Hi Sagar,

Have you figured out how to do it? I need to do the same thing. I have tried different approaches but haven't got what I want.

Thanks,
Zhiting

"sagar poudel" wrote in message <jfsm1i$bje$1@newscl01ah.mathworks.com>...
> Hi Sam
> I am stucked with the same problem. 3 data values but need to plot 2D graph (X,Y) with third point (Z) representing the values with unique color. I tried to look at these solutions, the last one seems convincing but was not able to open it. If you were able to solve the problem, can you send me the code or a way to deal with this problem?
>
> Thank you for your help.
>
> Sagar
>
> "Sam " <phb06sd@shef.ac.uk> wrote in message <h6kbdj$b2l$1@fred.mathworks.com>...
> > Hello,
> >
> > I'm currently stuck on a problem, I have a large matrix, with X, Y, Z values (~4000 in each)
> >
> > What I want to do is plot, in 2D X and Y as axis, and then have boxes filled with colour according to the appropriate value in Z.
> >
> > Much like a colourful chess/chequers board.
> >
> > I'm sure there must be a reasonably easy solution to this, but I have limited MATLAB experience and am considering using C++ in ROOT to solve this.
> >
> > For interest: This is being used to map data 'quality' taken in a Neutrino Physics experiment, we have over a year's worth of raw audio (30TB!) and have designed algorithms to classify each file with a quality, to reduce processing time by ignoring bad files. Thus the X axis correspond to the date, the Y axis to the time (in24hours) and the Z axis the quality of the file present at that point.
> >
> > Any help is appreciated.
> > -Sam

Subject: 2D Colour Plot from 3D Data

From: sagar poudel

Date: 28 Mar, 2012 18:35:17

Message: 9 of 12

Hi Zhiting
Yes, I was able to get one relevant idea after a good search. Then I wrote the code relevant for my purpose. What is the exact thing you are looking for?

"Zhiting " <tianzhiting@gmail.com> wrote in message <jkvl27$rkd$1@newscl01ah.mathworks.com>...
> Hi Sagar,
>
> Have you figured out how to do it? I need to do the same thing. I have tried different approaches but haven't got what I want.
>
> Thanks,
> Zhiting
>
> "sagar poudel" wrote in message <jfsm1i$bje$1@newscl01ah.mathworks.com>...
> > Hi Sam
> > I am stucked with the same problem. 3 data values but need to plot 2D graph (X,Y) with third point (Z) representing the values with unique color. I tried to look at these solutions, the last one seems convincing but was not able to open it. If you were able to solve the problem, can you send me the code or a way to deal with this problem?
> >
> > Thank you for your help.
> >
> > Sagar
> >
> > "Sam " <phb06sd@shef.ac.uk> wrote in message <h6kbdj$b2l$1@fred.mathworks.com>...
> > > Hello,
> > >
> > > I'm currently stuck on a problem, I have a large matrix, with X, Y, Z values (~4000 in each)
> > >
> > > What I want to do is plot, in 2D X and Y as axis, and then have boxes filled with colour according to the appropriate value in Z.
> > >
> > > Much like a colourful chess/chequers board.
> > >
> > > I'm sure there must be a reasonably easy solution to this, but I have limited MATLAB experience and am considering using C++ in ROOT to solve this.
> > >
> > > For interest: This is being used to map data 'quality' taken in a Neutrino Physics experiment, we have over a year's worth of raw audio (30TB!) and have designed algorithms to classify each file with a quality, to reduce processing time by ignoring bad files. Thus the X axis correspond to the date, the Y axis to the time (in24hours) and the Z axis the quality of the file present at that point.
> > >
> > > Any help is appreciated.
> > > -Sam

Subject: 2D Colour Plot from 3D Data

From: Sagar

Date: 29 Mar, 2014 00:49:08

Message: 10 of 12

Hi,
Has anyone figured out solution to this problem? I have the same problem. I need to plot (x,y) with the color specified by z.

Subject: 2D Colour Plot from 3D Data

From: Steven Lord

Date: 31 Mar, 2014 01:33:56

Message: 11 of 12


"Sagar " <hisagar123@gmail.com> wrote in message
news:lh55a4$fmd$1@newscl01ah.mathworks.com...
> Hi, Has anyone figured out solution to this problem? I have the same
> problem. I need to plot (x,y) with the color specified by z.

HELP SCATTER.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: 2D Colour Plot from 3D Data

From: Tyler Pierce

Date: 16 Apr, 2014 00:21:08

Message: 12 of 12

I had the same problem and found the following to give me the plot that I was after:

do a 3-D surface fit of the data:

fitobject = fit([x,y],z,fitType)

(search the 'fit' documentation for more info)

then plot the fitted surface:

plot(fitobject)

you can adjust the colormap and display the colorbar on your plot as desired. It's cool!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us