实际上,您需要在调用pareto 期间添加一个输出参数,然后您将获得2 个句柄(直线和条形系列)以及2 个轴。您想获得获得的第二个轴的 YTickLabel 属性。所以我怀疑在您对上述pareto 的调用中,您不需要提供ax 参数。
例子:
[handlesPareto, axesPareto] = pareto(explained,X);
现在如果你使用这个命令:
RightYLabels = get(axesPareto(2),'YTickLabel')
你会得到以下(或类似的东西):
RightYLabels =
'0%'
'14%'
'29%'
'43%'
'58%'
'72%'
'87%'
'100%'
您实际上可以做的是完全删除它们并用text 注释替换它们,您可以根据需要自定义它们。请参阅here 以获得精彩的演示。
适用于您的问题(使用函数文档中的虚拟值),您可以执行以下操作:
clear
clc
close all
y = [90,75,30,60,5,40,40,5];
figure
[hPareto, axesPareto] = pareto(y);
%// Get the poisition of YTicks and the YTickLabels of the right y-axis.
yticks = get(axesPareto(2),'YTick')
RightYLabels = cellstr(get(axesPareto(2),'YTickLabel'))
%// You need the xlim, i.e. the x limits of the axes. YTicklabels are displayed at the end of the axis.
xl = xlim;
%// Remove current YTickLabels to replace them.
set(axesPareto(2),'YTickLabel',[])
%// Add new labels, in bold font.
for k = 1:numel(RightYLabels)
BoldLabels(k) = text(xl(2)+.1,yticks(k),RightYLabels(k),'FontWeight','bold','FontSize',18);
end
xlabel('Principal Component','fontweight','b','fontsize',20)
ylabel('Variance Explained (%)','fontweight','b','fontsize',20)
这给出了这个:
你当然可以像这样自定义你想要的一切。