Synchronize axes limits with direct relation
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I would like to create a figure with two axes (left and right). Suppose on the left axis is Celsius, on the right Fahrenheit. Between those two units is always a direct relation. So whenever I change the left axis limits with ylim([a b]) I would like to see the limits on the right axis limits change accordingly/automatically. I have seen the option to link axes, however that seem work only if axes have the same limits. Any suggestion how I might tackle this problem?
1 Kommentar
jonas
am 6 Okt. 2018
I think you need to write a callback for this. Defining callbacks is one of the things I want to learn, so I might use this as an example and report back if I am successful :)
Akzeptierte Antwort
Weitere Antworten (1)
jonas
am 7 Okt. 2018
This is the best I could do. I could not find a way to execute the callback when updating the axes limits from the command window, perhaps someone more knowledgeable can chime in here as I feel this should be possible. This script will update the 2nd yaxis upon pressing the figure window.
figure;
%%Left axes
ax(1) = axes('color','none');
%%Passive right axes, should update with left
ax(2) = axes('color','none','yaxislocation','right','xcolor','none');
%%set figure callback
set(gcf,'WindowButtonDownFcn',{@FigCallback,ax})
axes(ax(1))
%%Executes when clicking the figure window
function FigCallback(scr,evnt,ax,~)
set(ax(2),'ylim',((ax(1).YLim.*(9/5)) + 32))
axes(ax(1))
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!