Matlab畫圖增加右邊坐標軸的刻度,與左邊一樣,如何處理?
如圖,我希望右邊的Y軸刻度與左邊一樣,如何實現? 雖然plotyy可以實現增加右邊的軸的刻度,但顏色會變,且必須是兩條或以上數量的曲線,我只有一條曲線,如何實現右邊軸上標上數字?
x = 1:0.5:4;
y = 2.*x;
plot(x,y, ".-b", "MarkerSize", 20, "LineWidth", 0.1)
grid on
xlim([0 6])
ylim([-5 12])
ax = gca;
ax.YTick = [1:0.5:9];
效果如下:
x = 1:0.5:4;
y = 2.*x;
[hAx,hLine1,hLine2] = plotyy(x,NaN(size(x)),x,NaN(size(x)));
hold on;
plot(x,y, ".-b", "MarkerSize", 20, "LineWidth", 0.1);
hAx(1).YTick = 1:0.5:9;
hAx(2).YTick = 1:0.5:9;
hAx(1).XLim = [0, 6];
hAx(2).XLim = [0, 6];
hAx(1).YLim = [-5, 12];
hAx(2).YLim = [-5, 12];
hAx(1).YColor = "k";
hAx(2).YColor = "k";
grid on;
目前版本文檔推薦用的是 yyaxis:
x = 1:.5:4;
y = 2*x;
plot(x,y,"b.-","MarkerSize",25)
xlim([0 6]), grid on, yyaxis right
set(get(gca,"YAxis"),"Color","k","TickValues",1:.5:9,"Limits",[-5 12])
老版本可以用 plotyy:
x = 1:.5:4;
y = 2*x;
ax = plotyy(x,y,nan+x,nan+y,@(x,y)plot(x,y,".-b","markersize",25));
set(ax,"YColor","k","Ytick",1:.5:9,"Ylim",[-5 12],"Xlim",[0 6]), grid on
推薦閱讀:
※請問怎麼用matlab 畫一個傾斜的橢球?
※「MatLab 模擬結論在工業界認可度低」是否屬實?
※matlab計算速度?
※這個Matlab圖像應用了什麼命令?
TAG:MATLAB |