How to set grid space in plot ?

16 visualizaciones (últimos 30 días)
Rahim Rahim
Rahim Rahim el 23 de Jul. de 2022
Respondida: Voss el 23 de Jul. de 2022
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 ... !

Respuestas (1)

Voss
Voss el 23 de Jul. de 2022
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

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by