フィルターのクリア

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 Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by