在MATLAB中绘制时循环颜色 [英] Cycle over colors while plotting in MATLAB

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

问题描述

当我使用按住在同一个图上绘制多个曲线时,每个曲线默认使用相同的颜色(蓝色)。我想让他们有所有不同的颜色。

When I plot several curves on the same plot using hold on, each curve defaults to the same color (blue). I'd like them to have all different colors.

我看到的一个解决方案是制作一个颜色矢量,例如。 c = ['k','g','r',...] 并且循环,但我不喜欢这个解决方案。如果我的绘图数量大于我的颜色矢量 c 的长度,我会打破,我不想定义 c

One solution I've seen is to make a color vector, e.g. c = ['k', 'g', 'r', ...] and loop over it, but I don't like this solution. Things will break if my number of plots is greater than the length of my color vector c, and I don't want to have to define c in every file.

有没有更好的解决方案?

Is there a better solution?

推荐答案

c $ c>保存所有。您的曲线应该自动循环在色彩映射上。从 帮助保持

Try using hold all instead. Your curves should cycle over the colormap automatically. From help hold:


保持所有保持图形和当前线条颜色和线条样式,因此
后续绘制命令不会重置ColorOrder和
LineStyleOrder属性值到列表的开头。绘制
命令继续循环遍历预定义的颜色和行
样式,其中最后一个图形在列表中停止。

hold all holds the graph and the current line color and line style so that subsequent plotting commands do not reset the ColorOrder and LineStyleOrder property values to the beginning of the list. Plotting commands continue cycling through the predefined colors and line styles from where the last graph stopped in the list.

您可以使用 get(gca,'ColorOrder')检查色彩映射。

You can examine the colormap with get(gca,'ColorOrder').

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

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