MATLAB中条件图的条件着色 [英] Conditional coloring of histogram graph in MATLAB

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

问题描述



大于 50的值

code>具有柱和小于 50 的值具有 bars。



假设我们有这个输入矩阵:

  X = [32 64 32 12 56 76 65 44 89 87 78 56 96 90 86 95 100 65]; 

我需要MATLAB的默认bin并在X轴(bin)上应用这个着色。我使用GUIDE来设计我的GUI,这个柱状图是我的GUI中的一个轴。

/cnDfX.jpgalt =

这是我们的普通图。上限值大于50的条应为红色,低于50的条应为绿色(X轴)。大于50的酒吧应该是红色的??我认为这是你想要的(按照评论)。 50号左右的酒吧被分成两种颜色。这是通过使用补丁来改变该栏的一部分的颜色。

X = [32 64 32 12 56 76 65 44 89 87 78 56 96 90 86 95 100 65]; %//数据值
D = 50; %//分为两种颜色

%//柱状图:
[y n] = hist(X); %// y:值; n:仓中心
ind = n> 50; %// bin中心:大于还是小于D?
bar(n(ind),y(ind),1,'r'); %// for more:use red
hold on%// keep graph,或者使用hold(your_axis_handle,'on')
bar(n(〜ind),y(〜ind),1, 'b'); %//对于较小的:使用蓝色
[〜,nd] = min(abs(n-D)); %//定位左右D:它需要两种颜色
patch([(n(nd-1)+ n(nd))/ 2 DD(n(nd-1)+ n(nd))/ 2],[0 0 y(nd)y(nd)],'b');
%//使用合适的补丁来关注该栏


I have a histogram that I want conditional coloring in it with this rule :

Values that are upper than 50 have red bars and values lower than 50 have blue bars.

Suppose that we have this input matrix:

X = [32 64 32 12 56 76 65 44 89 87 78 56 96 90 86 95 100 65];

I want default bins of MATLAB and applying this coloring on X-axes (bins). I'm using GUIDE to design my GUI and this histogram is an axes in my GUI.

This is our normal graph. Bars with upper values than 50 should be red and bars with lower values than 50 should be green (X-axes). Bars with upper values than 50 should be red and ?

解决方案

I think this does what you want (as per comments). The bar around 50 is split into the two colors. This is done by using a patch to change the color of part of that bar.

%// Data:
X = [32 64 32 12 56 76 65 44 89 87 78 56 96 90 86 95 100 65]; %// data values
D = 50; %// where to divide into two colors

%// Histogram plot:
[y n] = hist(X); %// y: values; n: bin centers
ind = n>50; %// bin centers: greater or smaller than D?
bar(n(ind), y(ind), 1, 'r'); %// for greater: use red
hold on %// keep graph, Or use hold(your_axis_handle, 'on')
bar(n(~ind), y(~ind), 1, 'b'); %// for smaller: use blue
[~, nd] = min(abs(n-D)); %// locate bar around D: it needs the two colors
patch([(n(nd-1)+n(nd))/2 D D (n(nd-1)+n(nd))/2], [0 0 y(nd) y(nd)], 'b');
%// take care of that bar with a suitable patch

这篇关于MATLAB中条件图的条件着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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