Maximizar automáticamente una figura


Estoy creando algunas figuras en MATLAB y las guardo automáticamente en archivos. El problema es que por definición las imágenes son pequeñas. Una buena manera de resolver mi problema a mano es crear una imagen (figura), maximizarla y guardarla en un archivo.

Me falta este paso de maximizar automáticamente una cifra.

Alguna sugerencia? Hasta ahora sólo encontré esto:

Http://answers.yahoo.com/question/index?qid=20071127135551AAR5JYh

Http://www.mathworks.com/matlabcentral/newsreader/view_thread/238699

Pero ninguno está resolviendo mi problema.

Author: Dev-iL, 2013-03-08

9 answers

Esto funcionó para mí:

figure('units','normalized','outerposition',[0 0 1 1])

O para la cifra actual:

set(gcf,'units','normalized','outerposition',[0 0 1 1])

También he usado la función MAXIMIZE en FileExchange que usa java. Esta es la verdadera maximización.

 60
Author: yuk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-08 05:17:45

Para una Maximización real (exactamente como hacer clic en el botón maximizar en la interfaz de usuario de OS X y Windows) Puede probar lo siguiente que llama a un controlador Java oculto

figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);

El pause(n) es esencial ya que lo anterior llega fuera del Matlab scape y está situado en un subproceso Java separado. Establezca n a cualquier valor y verifique los resultados. Cuanto más rápido es el equipo en el momento de la ejecución, más pequeño puede ser n.

La "documentación" completa se puede encontrar aquí

 21
Author: The-Duck,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-03 23:27:06

Para maximizar la figura, puede imitar la secuencia de claves que realmente usaría:

  1. ALT-ESPACIO (como se indica aquí ) para acceder al menú ventana; y luego
  2. X para maximizar (esto puede variar en su sistema).

Para enviar las claves mediante programación, puede usar un procedimiento basado en Java similar a esta respuesta , de la siguiente manera:

h = figure;                                          %// create figure and get handle
plot(1:10);                                          %// do stuff with your figure
figure(h)                                            %// make it the current figure
robot = java.awt.Robot; 
robot.keyPress(java.awt.event.KeyEvent.VK_ALT);      %// send ALT
robot.keyPress(java.awt.event.KeyEvent.VK_SPACE);    %// send SPACE
robot.keyRelease(java.awt.event.KeyEvent.VK_SPACE);  %// release SPACE
robot.keyRelease(java.awt.event.KeyEvent.VK_ALT);    %// release ALT
robot.keyPress(java.awt.event.KeyEvent.VK_X);        %// send X
robot.keyRelease(java.awt.event.KeyEvent.VK_X);      %// release X

Voilà! Ventana maximizada!

 6
Author: Luis Mendo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 11:54:44

Como es propuesto por un autor arriba, si desea simular haciendo clic en el botón" maximizar " de Windows, puede utilizar el código que sigue. La diferencia con la respuesta mencionada es que usar " drawnow "en lugar de" pause " parece más correcto.

figure;
% do your job here
drawnow;
set(get(handle(gcf),'JavaFrame'),'Maximized',1);
 4
Author: HomePlaneR,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:10:09

En mi humilde opinión maximizar la ventana de la figura no es la mejor manera de guardar una figura como una imagen en mayor resolución.

Hay propiedades de figura para imprimir y guardar. Usando estas propiedades puede guardar archivos en cualquier resolución que desee. Para guardar los archivos tienes que usar la función de impresión , porque puedes establecer un valor dpi. Por lo tanto, en primer lugar establecer las siguientes propiedades de la figura:

set(FigureHandle, ...
    'PaperPositionMode', 'manual', ...
    'PaperUnits', 'inches', ...
    'PaperPosition', [0 0 Width Height])

Y en segundo lugar guardar el archivo (por ejemplo) como png con 100dpi ('-r100')

print(FigureHandle, Filename, '-dpng', '-r100');

Para obtener un archivo con 2048x1536px set Width = 2048/100 y Altura 1536/100, /100 porque guardar con 100 dpi. Si cambia el valor dpi también tiene que cambiar el divisor al mismo valor.

Como puede ver, no hay necesidad de ninguna función adicional de intercambio de archivos o procedimiento basado en java. Además, puede elegir cualquier resolución deseada.

 4
Author: serial,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-13 07:22:23

A partir de R2018a, figure así como uifigure los objetos contienen una propiedad llamada WindowState. Esto se establece en 'normal' de forma predeterminada, pero al establecerlo en 'maximized' se obtiene el resultado deseado.

En conclusión:

hFig.WindowState = 'maximized'; % Requires R2018a

Por cierto, para abordar su problema original , si desea exportar el contenido de las figuras a imágenes sin tener que preocuparse de que los resultados sean demasiado pequeños, recomendaría encarecidamente el export_fig utilidad.

 4
Author: Dev-iL,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-25 14:27:12

Puedes probar esto:

screen_size = get(0, 'ScreenSize');
f1 = figure(1);
set(f1, 'Position', [0 0 screen_size(3) screen_size(4) ] );
 2
Author: ifryed,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-14 11:53:50

Esta es la forma más corta

figure('Position',get(0,'ScreenSize'))
 0
Author: user48711,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-14 11:17:31
%% maximizeFigure
%
% Maximizes the current figure or creates a new figure. maximizeFigure() simply maximizes the 
% current or a specific figure
% |h = maximizeFigure();| can be directly used instead of |h = figure();|
%
% *Examples*
%
% * |maximizeFigure(); % maximizes the current figure or creates a new figure|
% * |maximizeFigure('all'); % maximizes all opened figures|
% * |maximizeFigure(hf); % maximizes the figure with the handle hf|
% * |maximizeFigure('new', 'Name', 'My newly created figure', 'Color', [.3 .3 .3]);|
% * |hf = maximizeFigure(...); % returns the (i.e. new) figure handle as an output|
%
% *Acknowledgements*
% 
% * Big thanks goes out to Yair Altman from http://www.undocumentedmatlab.com/
%
% *See Also*
% 
% * |figure()|
% * |gcf()|
%
% *Authors*
%
% * Daniel Kellner, medPhoton GmbH, Salzburg, Austria, 2015-2017
%%

function varargout = maximizeFigure(varargin)

warning('off', 'MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame')

% Check input variables
if isempty(varargin)
    hf = gcf; % use current figure
elseif strcmp(varargin{1}, 'new')
    hf = figure(varargin{2:end});
elseif strcmp(varargin{1}, 'all')
    hf = findobj('Type', 'figure');
elseif ~isa(varargin{1}, 'char') && ishandle(varargin{1}) &&...
        strcmp(get(varargin{1}, 'Type'), 'figure')
    hf = varargin{1};
else
    error('maximizeFigure:InvalidHandle', 'Failed to find a valid figure handle!')
end

for cHandle = 1:length(hf)   
    % Skip invalid handles and plotbrowser handles
    if ~ishandle(cHandle) || strcmp(get(hf, 'WindowStyle'), 'docked') 
        continue
    end

    % Carry the current resize property and set (temporarily) to 'on'
    oldResizeStatus = get(hf(cHandle), 'Resize');
    set(hf(cHandle), 'Resize', 'on');

    % Usage of the undocumented 'JavaFrame' property as described at:
    % http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/
    jFrame = get(handle(hf(cHandle)), 'JavaFrame');

    % Due to an Event Dispatch thread, the pause is neccessary as described at:
    % http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/
    pause(0.05) 

    % Don't maximize if the window is docked (e.g. for plottools)
    if strcmp(get(cHandle, 'WindowStyle'), 'docked')
        continue
    end

    % Don't maximize if the figure is already maximized
    if jFrame.isMaximized
        continue
    end

    % Unfortunately, if it is invisible, it can't be maximized with the java framework, because a
    % null pointer exception is raised (java.lang.NullPointerException). Instead, we maximize it the
    % straight way so that we do not end up in small sized plot exports.
    if strcmp(get(hf, 'Visible'), 'off')
        set(hf, 'Units', 'normalized', 'OuterPosition', [0 0 1 1])
        continue
    end

    jFrame.setMaximized(true);

    % If 'Resize' will be reactivated, MATLAB moves the figure slightly over the screen borders. 
    if strcmp(oldResizeStatus, 'off')
        pause(0.05)
        set(hf, 'Resize', oldResizeStatus)
    end
end

if nargout
    varargout{1} = hf;
end
 0
Author: braggPeaks,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-31 13:26:20