直方图中的颜色特定区间

时间:2012-07-06 17:15:15

标签: matlab histogram

让我说我有类似的东西:

A = randi(30, [10, 1]);
hist(A)

我希望将低于特定值(例如3)的箱子的颜色更改为红色,而将其他箱子的颜色更改为蓝色或其他深色(不重要)。我该怎么做?

2 个答案:

答案 0 :(得分:1)

您可以使用bar为您提供帮助:

A = randi(30, [10, 1]);
[N, X] = hist(A);                      %# Extract bin values and positions
idx = N < 3;                           %# Indices of values less than threshold
figure, bar(X, N), hold on             %# Plot histogram in default color
bar(X(idx), N(idx), 'facecolor', 'r')  %# Plot red bars on top

示例:

enter image description here

答案 1 :(得分:0)

最简单的方法是创建自己的colormap,用于绘制数据。这样您就可以定义何时需要使用哪种颜色。

你应该能够弄清楚如何制作自己的色彩图矩阵,但是如果你以后仍然卡住了,只需在这里弹出代码,我们就可以了解它。