java在圆上画刻度线_matlab - 在原点设置刻度标签

这是一个简单的方法:

% somthing to plot:

x = 0:0.1:2*pi;

y = abs(sin(x)+cos(x));

plot(x,y)

% get the handle for the current axes:

ax = gca;

% get the position of the zero tick on y-axis:

zeroYtick = ax.YAxis.TickValues==0;

% remove it (tick and lable)

ax.YAxis.TickValues(zeroYtick) = [];

结果:

4d4a9626-74e5-462c-837f-bc1a44167bab.png

如果您希望 0 向左偏移一点,那么它将位于绘图的角落,您可以使用注释:

% get the position of the zero tick on x-axis:

zeroXtick = ax.XAxis.TickValues==0;

% remove it (tick and lable)

ax.XAxis.TickValues(zeroXtick) = [];

% place a new zero at the origin:

dim = [0.1 0.01 0.1 0.1];

annotation('textbox',dim,'String','0',...

'FitBoxToText','on','LineStyle','none')

你会得到:

405653d9-520c-4d7e-9424-d49705f9709f.png

annotation的优势在于原点始终相对于轴的角落放置,并且您无需知道轴刻度值以正确偏移它 .

EDIT:

对于2016年前版本,您可以使用以下内容(我写得更紧凑):

ax = gca;

% remove the zero tick on y-axis (tick and lable):

ax.YTick(ax.YTick==0) = [];

% remove the zero tick on x-axis (tick and lable):

ax.XTick(ax.XTick==0) = [];

% place a new zero at the origin:

dim = [0.1 0.01 0.1 0.1];

annotation('textbox',dim,'String','0',...

'FitBoxToText','on','LineStyle','none')

EDIT 2:

保持 0 到位的另一个选择是将它粘在轴上 . 这是通过用轴手柄替换 Parent 来完成的 . 首先,我们需要一个注释句柄(从上一次编辑继续):

t = annotation('textbox',dim,'String','0',...

'FitBoxToText','on','LineStyle','none');

然后我们切换 Parent 并设置新位置:

t.Parent = ax;

t.Position(1:2) = -[0.2 0.1];

最后,我们通过将 Units 转换为像素来超级粘合它:

t.Units = 'Pixels';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值