如上所述,我想放大一個用plotyy
創建的圖形。 當我這樣做時,yTicks
不會更新到可見的新限制。 所以可能發生,如果你縮小太多,你沒有看到任何yTicks
。 我發現ActionPostCallback
函數,但我沒有得到它的工作,而xTicks
罰款。Matlab:當我放大一個plotyy圖形時,yTicks不會自動更新
代碼:在
figure, plotyy(1:10,1:2:20,1:10,1:0.5:5.5)
結果:
如上所述,我想放大一個用plotyy
創建的圖形。 當我這樣做時,yTicks
不會更新到可見的新限制。 所以可能發生,如果你縮小太多,你沒有看到任何yTicks
。 我發現ActionPostCallback
函數,但我沒有得到它的工作,而xTicks
罰款。Matlab:當我放大一個plotyy圖形時,yTicks不會自動更新
代碼:在
figure, plotyy(1:10,1:2:20,1:10,1:0.5:5.5)
結果:
出於某種原因plotyy默認設置的軸的 'Ytickmode' 爲手動。
由於plotyy爲兩個數據集創建了兩組軸,因此設置每個軸的「Ytickmode」應解決此問題。
這可以通過
AX=plotyy(...) %this will create an axis with 2 elements one for each axis
AX(1).YTickMode='auto';
AX(2).YTickMode='auto';
由於這種行爲似乎並不存在於 '正常' plot
調用,這看起來像一個內部錯誤通過plotyy
創建軸對象。作爲一種選擇,您可以將多個軸疊加在一起,因此可以利用「默認」(缺少更好的單詞)縮放行爲。這種方法還可以讓您獨立完全控制兩個軸的行爲並避免看起來很多的plotyy
的缺陷。
我已經稍微改編了one of my previous answers作爲這種情況的一個例子。
% Sample data
x = 1:10;
y1 = 1:2:20;
y2 = 1:0.5:5.5;
% Create axes & store handles
h.myfig = figure;
h.ax1 = axes('Parent', h.myfig, 'Box', 'off');
if ~verLessThan('MATLAB', '8.4')
% MATLAB R2014b and newer
h.ax2 = axes('Parent', h.myfig, 'Position', h.ax1.Position, 'Color', 'none', 'YAxisLocation', 'Right');
else
% MATLAB 2014a and older
ax1position = get(h.ax1, 'Position');
h.ax2 = axes('Parent', h.myfig, 'Position', ax1position, 'Color', 'none', 'YAxisLocation', 'Right');
end
% Preserve axes formatting
hold(h.ax1, 'on');
hold(h.ax2, 'on');
% Plot data
plot(h.ax1, x, y1, 'b');
plot(h.ax2, x, y2, 'g');
linkaxes([h.ax1, h.ax2], 'x');
和樣本圖像:
請注意,我只掛了x
,但你可以用linkaxes
呼叫鏈路既x
和y
軸。
您可能需要將YTickMode
屬性設置爲auto
。
h = plotyy(1:10,1:2:20,1:10,1:0.5:5.5)
set(h, 'YTickMode','Auto')
完整代碼:
figure
subplot(121)
h1 = plotyy(1:10,1:2:20,1:10,1:0.5:5.5)
title('Original')
subplot(122)
h2 = plotyy(1:10,1:2:20,1:10,1:0.5:5.5)
title('Zoom')
set(h2, 'YTickMode','Auto')
來完成編輯我的第一篇文章 – TAK