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?
解决方案
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
And here's what you should get:
这篇关于MATLAB 图中的左右轴不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文