How to make axis line invisible but keep ytick and yticklabel visible in double Y-axis figures

5 次查看(过去 30 天)
figure
x = linspace(0,10);
y = sin(3*x);
yyaxis left
plot(x,y)
ax = gca;
pause(1e-6)
set(gca,'XColor','k','YColor','k','Color','w',...
'TickLength',[0.01,0.01],'TickDir','out',...
'FontName','Times',...
'TickLabelInterpreter','Latex',...
'LineWidth',1.5,'FontSize',12.5,'FontWeight','Bold',...
'GridLineStyle','-','XGrid','on','YGrid','on');
set(gca,'Color','#EBEBEB','GridColor',[1,1,1],...
'GridAlpha',1,'GridLineWidth',1.1);
% try to hide left-Yaxis line
ax.XRuler.Axle.Visible = 'off';
ax.YRuler.Axle.Visible = 'off';
z = sin(3*x).*exp(0.5*x);
yyaxis right
plot(x,z)
ylim([-150 150])
ax = gca;
pause(1e-6)
set(gca,'XColor','k','YColor','k','Color','w',...
'TickLength',[0.01,0.01],'TickDir','out',...
'FontName','Times',...
'TickLabelInterpreter','Latex',...
'LineWidth',1.5,'FontSize',12.5,'FontWeight','Bold',...
'GridLineStyle','-','XGrid','on','YGrid','on');
set(gca,'Color','#EBEBEB','GridColor',[1,1,1],...
'GridAlpha',1,'GridLineWidth',1.1);
% try to hide right-Yaxis line
ax.XRuler.Axle.Visible = 'off';
ax.YRuler.Axle.Visible = 'off';

采纳的回答

Ayush Modi
Ayush Modi 2024-3-12
Hi Hongyun,
You can use the "Visible" property for each Y-axis separately to disable the axis-line. Here is an example to demonstrate how you can achieve this:
ax.YAxis(1).Axle.Visible = 'off';
ax.YAxis(2).Axle.Visible = 'off';
Note: There seems to be a bug. This is only working in MATLAB editor. Axis-line is still visible in "Live Editor". You can report it to the Technical Support team by creating a Service Request: https://mathworks.com/support/contact_us.html

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 启动和关闭 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!