matlab - 我无法在条形尖端上方绘制值,XEndPoints 不起作用
问题描述
我正在使用Matlab 2018b
,我想在条的提示上方绘制值,其中
A=[4, 8 , 20 ,5];
B=[1,3 4 ,8 ];y
我想在条形上方写字符串,但是当我使用时XEndPoints
,会显示以下消息:
No appropriate method, property, or field 'XEndPoints' for class 'matlab.graphics.chart.primitive.Bar'.
我的代码:
function DisplayBarTopsisSawRankReversal(A,B,...
X1,X2)
max1= max(A(1,:));
max2=max(B(1,:));
MAX=max(max1,max2);
% This will produce 4 groups of 3 different colored bars
x = [1 2 ];
y = [A;B];
Bar = bar(x,y); % h will have 3 handles, one for each color of bars
set(Bar, {'DisplayName'}, {'Txt1','Txt2'}');
legend() ;
somenames={X1,X2};
set(gca,'xticklabel',somenames);
ylabel('Rank Reversal Ratio [%]')
ylim([0 MAX+30]);
%text(xtips1,ytips1,string( ) ,'HorizontalAlignment','center','VerticalAlignment','bottom')
opts = {'VerticalAlign','middle', 'HorizontalAlign','left', ...
'FontSize',8, 'Rotation',90};
text(1, A(1) ,'s' , opts{:});
numel(Bar)
xtips2 = b(2).XEndPoints;
end
如何在我的情况下添加字符串?
解决方案
'XEndPoints'
是 Matlab R2019b 中的一个新功能。如果您尝试绘制单个条形图,这可能会对您有所帮助:
bar(data);
for i = 1:length(data)
text(i, data(i), num2str(data(i), '%g'),...
'HorizontalAlignment','center','VerticalAlignment','bottom');
end
当您决定绘制分组条形图时,最好将您的 Matlab 更新到 R2019b。
还有另一种方法可以解决这个问题:使用函数“rectangle”设计自己的函数“MyBar”。
推荐阅读
- elixir - 如何使用 Elixir/Nerves 获取当前设备 IP
- python - 将日期时间转换为序数
- javascript - hls.js hls.subtitleTracks 返回空数组
- image - 未能呈现 B64 编码的 Thymeleaf
- regex - 正则表达式 - 在字符的出现数 N 后开始匹配
- flutter - Flutter/Dart 使用 ListView.builder 为每个 x 项目构建一个不同的小部件
- sql - 根据前一行和相同的计算列计算列值
- java - 使用日期错误打印月份中的日期?
- c++ - 如何创建派生对象的向量?
- azure - Ansible 查找特定键