MATLAB图中的左右轴是否不同? [英] Different right and left axes in a MATLAB plot?
本文介绍了MATLAB图中的左右轴是否不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用plot()
在MATLAB中绘制了一条迹线.我想添加带有不同刻度线(线性缩放)的右y轴.这可能吗?
I plot a single trace in MATLAB with plot()
. I'd like to add a right-y axis with a different set of tick marks (scaled linearly). Is this possible?
推荐答案
关于这个密切相关的问题,有很多好的建议,尽管它们处理的情况比您要复杂得多.如果您想要超简单的DIY解决方案,可以尝试以下方法:
There are a number of good suggestions on this closely related question, although they deal with a more complicated situation than yours. If you want a super-simple DIY solution, you can try this:
plot(rand(1, 10)); % Plot some random data
ylabel(gca, 'scale 1'); % Add a label to the left y axis
set(gca, 'Box', 'off'); % Turn off the box surrounding the whole axes
axesPosition = get(gca, 'Position'); % Get the current axes position
hNewAxes = axes('Position', axesPosition, ... % Place a new axes on top...
'Color', 'none', ... % ... with no background color
'YLim', [0 10], ... % ... and a different scale
'YAxisLocation', 'right', ... % ... located on the right
'XTick', [], ... % ... with no x tick marks
'Box', 'off'); % ... and no surrounding box
ylabel(hNewAxes, 'scale 2'); % Add a label to the right y axis
这是您应该得到的:
这篇关于MATLAB图中的左右轴是否不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文