如何在MATLAB中创建具有渐变标记颜色的散点图? [英] How do I create a scatter plot with graduated marker colours in MATLAB?

查看:6937
本文介绍了如何在MATLAB中创建具有渐变标记颜色的散点图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MATLAB中绘制一个简单的散点图,标记颜色从光谱的一端到另一端变化(例如红色,橙色,黄色...蓝色,紫色)。

I would like to plot a simple scatter graph in MATLAB, with marker colours varying from one end of the spectrum to the other (e.g. red, orange, yellow....blue, purple).

我的数据比较了河流中的水量与水质,随着时间的推移(3个简单的列:时间,数量,质量)。我想绘制量和质量的x,y散点图,但随着时间的推移,颜色进展,以便可以看到质量随时间的进展。

My data compares the amount of water in a river with the quality of the water, over time (3 simple columns: time, amount, quality). I would like to plot the x,y scatter plot of amount vs quality, but with the colour progressing over time, so that it is possible to see the progression of the quality over time.

我需要生成许多这种类型的图形,所以如果我可以找到一段代码适用于任何长度的数据集,这将是非常有用的。

I will need to produce many graphs of this type, so if I can find a piece of code that will work for any length of dataset, that would be really useful.

非常感谢您提前帮助Matlab新手!

Many thanks in advance for helping a Matlab novice!

推荐答案

您可以使用散布

如果您的数据已经按时排序,只需使用:

If your data are already sorted in time than simply use:

% let n be the number of points you have
cmp = jet(n); % create the color maps changed as in jet color map
scatter(x, y, 10, cmp, 'filled');

否则,您需要先对数据进行排序:

Otherwise you need to sort your data first:

[time, idx] = sort(time);
x = x(idx);
y = y(idx);
cmp = jet(n); % create the color maps changed as in jet color map
scatter(x, y, 10, cmp, 'filled');

这篇关于如何在MATLAB中创建具有渐变标记颜色的散点图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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