plotting color codded graph in matlab

笑着哭i 提交于 2019-12-01 12:54:40

问题


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

48.000000 0.000184 0.400000 
48.500000 0.000185 0.400000 
49.000000 0.000186 0.400000 
49.500000 0.000187 0.400000 
50.000000 0.000187 0.400000 
50.500000 0.000186 0.400000 
51.000000 0.000186 0.400000 
51.500000 0.000186 0.400000 
52.000000 0.000185 0.400000 
52.500000 0.000184 0.400000 
53.000000 0.000184 0.400000 
53.500000 0.000182 0.400000 
54.000000 0.000180 0.400000 
54.500000 0.000179 0.400000 
55.000000 0.000177 0.400000 
55.500000 0.000174 0.400000 
56.000000 0.000172 0.400000 

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 ?


回答1:


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.




回答2:


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:



来源:https://stackoverflow.com/questions/11957769/plotting-color-codded-graph-in-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!