How to remove ticks from the secondary axis in the example below?

조회 수: 14 (최근 30일)
blues
blues 2022년 7월 20일
댓글: blues 2022년 7월 21일
Hello - Can you help me remove the secondary axis ticks (both in x and y secondary axis) from the code below? Figure attached shows the ticks in primary and secondary axis.
close all; clear; clc; workspace;
%%
data = readmatrix('dddcb.xls', 'sheet', 1, 'Range', 'A3:B400');
first_col1 = data(1:398, 1);
second_col1 = data(1:398, 2);
dose_per_decay1 = second_col1/20000000;
figure(1)
plot(first_col1, dose_per_decay1, 'Color', '[0 0 0]', 'LineWidth',2);
% Make ticks longer and thicker
ax = gca;
properties(ax)
for k = .01 : 0.01 : .02
ax.TickLength = [k, k]; % Make tick marks longer
ax.LineWidth = 50 * k; % Make tick marks thicker
end
ay = gca;
properties(ay)
for k = .01 : 0.01 : .02
ay.TickLength = [k, k];
end
grid off
ax = gca;
ax.XGrid = 'on';
ax.YGrid = 'on';
ax.GridLineStyle = '-';
hAx = gca; % avoid repetitive function calls
set(hAx,'xminorgrid','on','yminorgrid','off') % turn off y-minor grid lines
legend({'\color[rgb]{0 0 0} 3 MeV '}, 'Fontsize', 12);
legend('boxoff')
set(gca,'TickDir','out');
set(gca, 'YScale', 'log');
set(gca, 'XScale', 'log');
set(gca,'FontSize',16, 'XMinorTick','on','YMinorTick','on');
ax = gca;
xlim([1 100]);
ylim([0.000001 100]);
xlabel('distance (\mum)', 'FontSize', 14);
ylabel('dose/decay', 'FontSize', 14);

채택된 답변

Voss
Voss 2022년 7월 20일
loglog(1:10000)
ax = gca;
set(ax, ...
'XGrid','on', ...
'YGrid','on', ...
'GridLineStyle','-', ...
'XMinorGrid','on', ...
'YMinorGrid','off', ...
'XMinorTick','off', ...
'YMinorTick','off', ...
'FontSize',16);
  댓글 수: 5
Voss
Voss 2022년 7월 21일
I don't know of a built-in way to have lines on all four sides and ticks on only two sides of the axes, so as far as I know you'll have to do a workaround of one kind or another.
Here's one way you can create the missing black lines on top and right:
loglog(1:10000)
xl = xlim();
yl = ylim();
line('XData',xl([1 2 2]),'YData',yl([2 2 1]),'Color','k');
ax = gca;
set(ax, ...
'Box','off', ...
'XGrid','on', ...
'YGrid','on', ...
'GridLineStyle','-', ...
'XMinorGrid','on', ...
'YMinorGrid','off', ...
'FontSize',16);
blues
blues 2022년 7월 21일
Thank you. This worked.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by