필터 지우기
필터 지우기

How to set grid space in plot ?

조회 수: 17 (최근 30일)
Rahim Rahim
Rahim Rahim 2022년 7월 23일
답변: Voss 2022년 7월 23일
I want to add a grid on my plot. Unofrtunetely, I found only Grid normal and Grid miror,
I want to add a grid that appear every 5 value on y-axis, This is my code:
function DisplayNumber(x,y1,y2,Name,Method)
plot(x,y1,'-s','MarkerSize',9,...
'MarkerEdgeColor','green',...
'MarkerFaceColor',[0 0.4470 0.7410])
hold on
legend({'cos(x)','cos(2x)','cos(3x)','cos(4x)'},...
'Location','northwest','NumColumns',2)
p=plot(x,y2,'-s','MarkerSize',9,...
'MarkerEdgeColor','yellow',...
'MarkerFaceColor',[0.6350 0.0780 0.1840])
hold off
xtickangle(0)
max(y1);
Max= max( max(y1),max(y2));
ylim([0 Max+10]);
Max=max(x);
xlim([1 Max+1]);
legend( strcat(Method,"-AHP"),strcat(Method,"-MOWOA-NIS"));
ylabel('Rank reversal ratio %');
xlabel('Number of networks');
xticks(0 : 20)
grid on
set(gcf,'Units','Inches');
pos = get(gcf,'Position');
set(gcf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
print(gcf,Name,'-dpdf','-r0')
end
I tried yticks(0:5:Max+10) but it did not work ... !

답변 (1개)

Voss
Voss 2022년 7월 23일
What's the problem with yticks(0:5:Max+10)?
DisplayNumber(0:9,100*rand(1,10),100*rand(1,10),'output.pdf','')
function DisplayNumber(x,y1,y2,Name,Method)
plot(x,y1,'-s','MarkerSize',9,...
'MarkerEdgeColor','green',...
'MarkerFaceColor',[0 0.4470 0.7410])
hold on
% legend({'cos(x)','cos(2x)','cos(3x)','cos(4x)'},...
% 'Location','northwest','NumColumns',2)
p=plot(x,y2,'-s','MarkerSize',9,...
'MarkerEdgeColor','yellow',...
'MarkerFaceColor',[0.6350 0.0780 0.1840]);
hold off
xtickangle(0)
max(y1);
Max= max( max(y1),max(y2));
ylim([0 Max+10]);
yticks(0:5:Max+10)
Max=max(x);
xlim([1 Max+1]);
legend( strcat(Method,"-AHP"),strcat(Method,"-MOWOA-NIS"));
ylabel('Rank reversal ratio %');
xlabel('Number of networks');
xticks(0 : 20)
grid on
set(gcf,'Units','Inches');
pos = get(gcf,'Position');
set(gcf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
print(gcf,Name,'-dpdf','-r0')
end

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by