matlab - 根据百分比更改直方图的背景颜色
问题描述
我有一个直方图,我想在直方图中分布的 16.5% 到 83.5% 的点之间为背景着色。
我怎样才能做到这一点?如何找到这些点?
数据在file
- 一列值中。
h = histogram( file, 50 );
解决方案
就像添加另一个变体一样。使用直方图属性和 prctile 找到限制:
data = randn(100000,1);
% Start with the original histogram
figure;
h=histogram(data,50);
% Find the bin edges you received.
be=h.BinEdges;
% Find the limits where your percentile limits lie
y=prctile(data,[16.5 83.5]);
% However, percentile limits will not generally concide with your bin-limits, so this must be fudged.
% Option A: Adjust be, to lie on the percentiles.
% DYI
% Option B: Adjust your limits for a pretty plot
% Find which be indicies are closest to the desired limits.
vals=y(:);
rv=be(:)';
diffs=bsxfun(@minus,vals, rv); % Finds differences to all be for all vals.
[~,inds]=min(abs(diffs),[],2); % Finds the minimum ones.
vals=rv(inds); % Find values to use for the cutoff.
% Replace the original plot with the inner cut.
h1=histogram(data(data>vals(1) & data<vals(2)),'BinEdges',be);
hold on;
% Plot the data outside the limits.
h2=histogram(data(data<vals(1) | data>vals(2)),'BinEdges',be);
% Pretty colors have ensued. As per post, you can color the tails to
% something else
h2.FaceColor='white';
感谢 Tom R 四舍五入到特定值: https ://se.mathworks.com/matlabcentral/fileexchange/37674-roundtowardvec
推荐阅读
- python-3.x - 如何使用带有 discord.py 的 gmail API 每分钟在聊天中将 10 封最近的未读电子邮件作为单独的消息发送?
- ngrx - @ngrx/store 要求安装 @angular/core@^10.0.0 但是我们有 "@angular/core": "^11.0.5"
- migration - 尝试将问题从 JIRA 导入到 Redmine
- python - 拆分功能的python替代解决方案
- php - 组装菜单(节点树),其中只有父节点是已知的
- shell - 如何在 UNIX shell 脚本中引用通用脚本中的变量和文件中的变量名
- python - 在python中将一个列表分成两个单独的列表
- excel - 在 Excel 的单元格 C1 中,如何从单元格 B1 的逗号分隔值列表中选择未在 A 列中以逗号分隔的单元格/值?
- python - 如何使用 NLP 从 PDF 文件中提取关键字及其页码?
- c - 如何使用缓冲区溢出攻击找到要利用的程序的漏洞