简体   繁体   中英

plotting color codded graph in matlab

I need to plot a color codded 2d graph using a .dat file. data in the file is arranged as

\n48.000000 0.000184 0.400000  \n48.500000 0.000185 0.400000  \n49.000000 0.000186 0.400000  \n49.500000 0.000187 0.400000  \n50.000000 0.000187 0.400000  \n50.500000 0.000186 0.400000  \n51.000000 0.000186 0.400000  \n51.500000 0.000186 0.400000  \n52.000000 0.000185 0.400000  \n52.500000 0.000184 0.400000  \n53.000000 0.000184 0.400000  \n53.500000 0.000182 0.400000  \n54.000000 0.000180 0.400000  \n54.500000 0.000179 0.400000  \n55.000000 0.000177 0.400000  \n55.500000 0.000174 0.400000  \n56.000000 0.000172 0.400000  \n

here 3rd column is also changing. There are almost 3000 lines. I need to plot a color codded 2d graph between 1st and 2nd variable and color has to put as height of 3rd variable. Can someone help me ?

If you want the colors of your data to go from dark to light based on the value in column 3, then you might be best off just using the scatter function. According to the documentation

scatter(X,Y,S,C) displays colored circles at the locations specified by the vectors X and Y (which must be the same size).

S determines the area of each marker ...

C determines the color of each marker. When C is a vector the same length as X and Y, the values in C are linearly mapped to the colors in the current colormap.

This means that you can explicitly chose the colormap that you want your data to use. Assuming col1 , col2 , col3 contain the values in each of the three columns of your data, the following code will draw a scatter plot with col1 and col2 defining the x and y positions (respectively) and col3 defining the color of each point.

scatter(col1, col2, 25, col3, '.');
colormap(gray);

After drawing the scatter plot, I explicitly set the colormap to gray so that points in col3 with a small value will be dark and those with a large value will be light. Note that in this example the marker area is 25 and the marker type is a dot ('.'), as specified by the 3rd and 5th parameters of the scatter function.

There are many other colormaps that you could use besides gray . For example, hot or copper might be more aesthetically pleasing. The doc for the colormap function gives more info on your other options.

Use >> gscatter(column1,column2,column3)

Since your column 3 is the same value, the plot will look like this: 在此处输入图片说明

But, add some noise to the third column, and you'd get something like this:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM