Matlab中使用的双轴 [英] double axis used in matlab

查看:97
本文介绍了Matlab中使用的双轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Matlab中使用plotyy在同一图中绘制两个数据集.左右轴的范围不同.但是我只是发现在右轴上似乎显示了两组不同的比例尺.我认为其中之一确实是从左轴开始的.

I am using a plotyy in matlab to plot two data set in a same figure. The left and right axis are of the different range. But I just find that on the right axis, there seems to be two different set of scale shown. I think one of them is really from the left axis.

t=-1:0.02:1; 
y=sin(t); 
y1=2*sech(t); 
[AX, H] =plotyy(t, y, t, y1); 
ylim(AX(2), [0 3.25]); 
set(AX(2), 'YTickMode', 'auto')

在网上搜索后,我发现关闭此框也可以解决问题.但是问题是,如果顶部水平线也消失了,则关闭该框.无论如何,这是为了去除多余的刻度并保持框架吗?谢谢.

After searching that online, I found that to turn off the box will solve the problem too. But the problem is to turn the box off will case the top horizontal line gone also. Is that anyway to remove the extra scale and keep the frame? Thanks.

推荐答案

我认为没有简单的方法可以执行所需的操作.如果关闭此框(以消除右侧的蓝色刻度),则顶部水平线将消失:

I don't think there's simple a way to do what you want. If you turn off the box (to get rid of the blue ticks on the right hand side) then the top horizontal line will disappear:

set(AX(1), 'Box','off')

如果需要,可以使用以下方法重新绘制线条:

If you want you could re-draw the line back in with:

line([-1, 1], [1, 1])

或更笼统地说:

lims = get(AX(1),{'XLim','YLim'});
line(lims{1}, lims{2}([2 2]))

这篇关于Matlab中使用的双轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆