Skip to content

Commit 9d2de54

Browse files
committed
Optimization of figure exporting
1 parent 5a21520 commit 9d2de54

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

CellExplorer.m

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8093,13 +8093,13 @@ function CloseGoTo_dialog(cellIDs)
80938093
elseif any(choice == [12,13,14])
80948094
% Multiple plots
80958095
% Creates summary figures and saves them to '/summaryFigures' or a custom path
8096-
exportPlots.dialog = dialog('Position', [300, 300, 300, 370],'Name','Multiple plots','WindowStyle','modal', 'resize', 'on', 'visible','off'); movegui(exportPlots.dialog,'center'), set(exportPlots.dialog,'visible','on')
8097-
uicontrol('Parent',exportPlots.dialog,'Style','text','Position',[5, 350, 290, 20],'Units','normalized','String','Select plots to export','HorizontalAlignment','center','Units','normalized');
8096+
exportPlots.dialog = dialog('Position', [300, 300, 300, 370],'Name','Multi plot','WindowStyle','modal', 'resize', 'on', 'visible','off'); movegui(exportPlots.dialog,'center'), set(exportPlots.dialog,'visible','on')
8097+
uicontrol('Parent',exportPlots.dialog,'Style','text','Position',[5, 350, 290, 20],'Units','normalized','String','Select plots','HorizontalAlignment','center','Units','normalized');
80988098
% [selectedActions,tf] = listdlg('PromptString',['Plot actions to perform on ' num2str(length(cellIDs)) ' cells'],'ListString',plotOptions','SelectionMode','Multiple','ListSize',[300,350]);
80998099
exportPlots.popupmenu.plotList = uicontrol('Parent',exportPlots.dialog,'Style','listbox','Position',[5, 110, 290, 245],'Units','normalized','String',plotOptions,'HorizontalAlignment','left','Units','normalized','min',1,'max',100);
81008100
exportPlots.popupmenu.saveFigures = uicontrol('Parent',exportPlots.dialog,'Style','checkbox','Position',[5, 80, 240, 25],'Units','normalized','String','Save figures','HorizontalAlignment','left','Units','normalized');
81018101
uicontrol('Parent',exportPlots.dialog,'Style','text','Position',[5, 62, 140, 20],'Units','normalized','String','File format','HorizontalAlignment','center','Units','normalized');
8102-
exportPlots.popupmenu.fileFormat = uicontrol('Parent',exportPlots.dialog,'Style','popupmenu','Position',[5, 40, 140, 25],'Units','normalized','String',{'png','pdf'},'HorizontalAlignment','left','Units','normalized');
8102+
exportPlots.popupmenu.fileFormat = uicontrol('Parent',exportPlots.dialog,'Style','popupmenu','Position',[5, 40, 140, 25],'Units','normalized','String',{'png','pdf (slower but vector graphics)'},'HorizontalAlignment','left','Units','normalized');
81038103
uicontrol('Parent',exportPlots.dialog,'Style','text','Position',[155, 62, 140, 20],'Units','normalized','String','File path','HorizontalAlignment','center','Units','normalized');
81048104
exportPlots.popupmenu.savePath = uicontrol('Parent',exportPlots.dialog,'Style','popupmenu','Position',[155, 40, 140, 25],'Units','normalized','String',{'Clustering path','Cell Explorer','Define path'},'HorizontalAlignment','left','Units','normalized');
81058105
uicontrol('Parent',exportPlots.dialog,'Style','pushbutton','Position',[5, 5, 140, 30],'String','OK','Callback',@ClosePlot_dialog,'Units','normalized');
@@ -8147,11 +8147,16 @@ function ClosePlot_dialog(~,~)
81478147
selectedActions = exportPlots.popupmenu.plotList.Value;
81488148

81498149
if exportPlots.popupmenu.saveFigures.Value == 0
8150-
delete(exportPlots.dialog);
8151-
saveFig = false;
8150+
saveFig.save = false;
81528151
else
8153-
saveFig = true;
8152+
saveFig.save = true;
8153+
saveFig.path = exportPlots.popupmenu.savePath.Value;
8154+
saveFig.fileFormat = exportPlots.popupmenu.fileFormat.Value;
8155+
if saveFig.path == 3 && ~exist('dirNameCustom','var')
8156+
dirNameCustom = uigetdir;
8157+
end
81548158
end
8159+
delete(exportPlots.dialog);
81558160
if choice == 12 && ~isempty(selectedActions)
81568161
% Displayes a new dialog where a number of plot can be combined and plotted for the highlighted cells
81578162
plot_columns = min([length(cellIDs),5]);
@@ -8289,37 +8294,34 @@ function ClosePlot_dialog(~,~)
82898294

82908295
% Saving figure
82918296
savefigure(fig,savePath1,[cell_metrics.sessionName{cellIDs(j)},'.CellExplorer_cell_', num2str(cell_metrics.UID(cellIDs(j)))])
8292-
82938297
end
82948298
end
8295-
if saveFig
8296-
delete(exportPlots.dialog);
8297-
end
8299+
82988300
function savefigure(fig,savePathIn,fileNameIn)
8299-
if saveFig
8300-
if exportPlots.popupmenu.savePath.Value == 1
8301+
if saveFig.save
8302+
if saveFig.path == 1
83018303
savePath = fullfile(savePathIn,'summaryFigures');
83028304
if ~exist(savePath,'dir')
83038305
mkdir(savePathIn,'summaryFigures')
83048306
end
8305-
elseif exportPlots.popupmenu.savePath.Value == 2
8307+
elseif saveFig.path == 2
83068308
[dirName,~,~] = fileparts(which('CellExplorer.m'));
83078309
savePath = fullfile(dirName,'summaryFigures');
83088310
if ~exist(savePath,'dir')
83098311
mkdir(dirName,'summaryFigures')
83108312
end
8311-
elseif exportPlots.popupmenu.savePath.Value == 3
8312-
if ~exist('dirName','var')
8313-
dirName = uigetdir;
8313+
elseif saveFig.path == 3
8314+
if ~exist('dirNameCustom','var')
8315+
dirNameCustom = uigetdir;
83148316
end
8315-
savePath = dirName;
8317+
savePath = dirNameCustom;
83168318
end
8317-
if exportPlots.popupmenu.fileFormat.Value == 1
8319+
if saveFig.fileFormat == 1
83188320
saveas(fig,fullfile(savePath,[fileNameIn,'.png']))
83198321
else
8320-
set(fig,'Units','Inches');
8322+
set(fig,'Units','Inches','Renderer','painters');
83218323
pos = get(fig,'Position');
8322-
set(fig,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
8324+
set(fig,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
83238325
print(fig, fullfile(savePath,[fileNameIn,'.pdf']),'-dpdf');
83248326
end
83258327
end

0 commit comments

Comments
 (0)