Created
August 19, 2015 22:01
-
-
Save peteristhegreat/879c99dcfc569770dc44 to your computer and use it in GitHub Desktop.
Persistent pan, zoom, position in matlab in combination with the dragzoom tool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% This uses http://www.mathworks.com/matlabcentral/fileexchange/29276-dragzoom-drag-and-zoom-tool | |
% and makes the last zoom of an open figure window persistent for the next run. | |
% These axis settings could get pushed to an external file to make them always happen, too. | |
% Place the following at the top of your .m file | |
% Store the position of figure 1 | |
myfig = 0; | |
prevCam.keys = {'CameraPosition', 'CameraTarget', 'CameraUpVector', 'CameraViewAngle', 'Position'}; | |
prevCam.vals = 0; | |
h = findobj('type','figure'); | |
if ishandle(h) | |
% get the figure size and position | |
myfig = get(h,'Position'); | |
prevCam.vals = get(gca, prevCam.keys); | |
end | |
clearvars -except myfig prevCam | |
close all | |
format compact | |
%% make a 2d or 3d plot here | |
% ... | |
% | |
% Place the following after you finish drawing and you are about to allow interaction from the user | |
% Restore the window positon of Figure 1 | |
h = findobj('type','figure'); | |
if(myfig ~= 0) | |
set(h,'Position',myfig); | |
% restore the camera zoom, pan, and position | |
set(gca, prevCam.keys, prevCam.vals); | |
end | |
% whitebg(1,'k') % Inverts all the colors on the figure if used after the fact | |
% Invert only the background and ensure the text and axis are white | |
if(true) | |
set(gca,'color','black') | |
set(gcf,'color',[0.32 0.32 0.32]) | |
a=findobj(gcf); | |
set(gca,'XColor','white') | |
set(gca,'YColor','white') | |
set(gca,'ZColor','white') | |
alltext=findall(a,'Type','text');%'axes' 'line' | |
set(alltext,'color', 'white'); | |
end | |
drawnow | |
% Enable nice click and drag and scroll to zoom mouse features on figure | |
dragzoom(); | |
% axis vis3d | |
% set(gca,'cameraviewanglemode','manual'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment