根据MATLAB中的数据值使用标记填充颜色 [英] use marker fill colors according to data value in MATLAB

查看:1977
本文介绍了根据MATLAB中的数据值使用标记填充颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用matlab绘制三个数据序列. 例如

I am using matlab to plot three data series. e.g.

0.4545 0.7676 10
0.3232 0.5432 20

可以说这是一个100 x 3的矩阵. (我们称它为A,也根据A(:,1)进行排序).第三列是一个附加数字,范围是1到100. 我正在使用MATLAB执行以下操作:

Lets say this is a 100 x 3 matrix. (Lets call it A, also it is sorted according to A(:,1) )The third column is an additional number which ranges from 1 to 100. I am using MATLAB to do the following:

plot (A(:,1));
hold on;
plot (A(:,2));

我正在使用属性编辑器以行格式表示数据系列A(:,1),并使用附加标记[正方形,即绘图中的--rs选项]表示A(:,2).

I am using the property editor to represent data-series A(:,1) in line format and A(:,2) with additional marker [square i.e --rs option in plot].

我的问题是,如何根据第三列中的数据填充正方形?

My question is, how do I fill the squares according to data in the 3rd column ?

基本上我该如何根据3d列中的数据对第二个数据系列进行颜色编码? 在附图中,如何通过A(:,3)中的数据将颜色填充到正方形中 通过建立渐变是否可以使颜色渐变?

Basically how do i go about color coding the 2nd data-series according to data in 3d column ? In the figure attached, how do i fill color into the squares by data in A(:,3) Would it be possible to make a gradation in the color by making a gradient ?

请帮助.谢谢.

推荐答案

这是一种非常简单,效率不高但很易读的方法:

Here is a very simple, not so efficient but very easy to read, way to do this:

% create fake data
x=linspace(-10,10,100);
y=sin(x);
c=randi(numel(x),1,numel(x));
cmap=colormap(jet(numel(x)));

% plot the lines
plot(x,y,'--'); hold on

% plot the squares, one at a time according to color vector c
% I added some randome noise to y to get the image nicer... 
for n=1:numel(x)
    plot(x(n),y(n)+0.3*(rand-0.5),'s','MarkerFaceColor',cmap(c(n),:));hold on
end
hold off

一个完全不同的问题是,这个问题使我想起了我不久前在类似主题上给出的答案(

On a completely different not, this question reminded me of an answer I gave a while ago on a similar subject (see here)...

这篇关于根据MATLAB中的数据值使用标记填充颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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