在matlab中绘制彩色编码图 [英] plotting color codded graph in matlab

查看:32
本文介绍了在matlab中绘制彩色编码图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 .dat 文件绘制彩色编码的二维图形.文件中的数据排列为

<块引用><前>48.000000 0.000184 0.40000048.500000 0.000185 0.40000049.000000 0.000186 0.40000049.500000 0.000187 0.40000050.000000 0.000187 0.40000050.500000 0.000186 0.40000051.000000 0.000186 0.40000051.500000 0.000186 0.40000052.000000 0.000185 0.40000052.500000 0.000184 0.40000053.000000 0.000184 0.40000053.500000 0.000182 0.40000054.000000 0.000180 0.40000054.500000 0.000179 0.40000055.000000 0.000177 0.40000055.500000 0.000174 0.40000056.000000 0.000172 0.400000

这里的第三列也在变化.有将近 3000 行.我需要在第一个和第二个变量之间绘制一个彩色编码的二维图,并且颜色必须作为第三个变量的高度.有人能帮我吗 ?

解决方案

如果您希望数据的颜色根据第 3 列中的值从深到浅,那么您最好只使用 分散 功能.根据文档

<块引用>

scatter(X,Y,S,C) 在向量 X 和 Y 指定的位置(必须具有相同的大小)显示彩色圆圈.

S 确定每个标记的面积...

C 确定每个标记的颜色.当 C 是与 X 和 Y 长度相同的向量时,C 中的值线性映射到当前颜色图中的颜色.

这意味着您可以明确选择您希望数据使用的颜色图.假设 col1col2col3 包含数据三列中每一列的值,以下代码将绘制带有 col1 的散点图col2 定义 x 和 y 位置(分别)和 col3 定义每个点的颜色.

scatter(col1, col2, 25, col3, '.');颜色图(灰色);

绘制散点图后,我明确地将颜色图设置为灰色,这样 col3 中值小的点会变暗,值大的点会变亮.请注意,在此示例中,标记区域为 25,标记类型为点 ('.'),由 scatter 函数的第 3 和第 5 个参数指定.

除了灰色之外,您还可以使用许多其他颜色图.例如,hotcopper 可能更美观.颜色图函数的 doc 提供了有关其他选项的更多信息.

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 ?

解决方案

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.

这篇关于在matlab中绘制彩色编码图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆