Skip to content

Instantly share code, notes, and snippets.

@schluppeck
Last active August 29, 2015 14:22
Show Gist options
  • Save schluppeck/c45a572d02223786ca79 to your computer and use it in GitHub Desktop.
Save schluppeck/c45a572d02223786ca79 to your computer and use it in GitHub Desktop.
fix some aspect of formatting for matlab plots according to J Neurosci guidelines
function [ fHandle ] = jneurosci(fHandle, colWidth)
%jneurosci - provide some defaults for figures to get to JNeurosci style
%
% usage: [ fHandle ] = jneurosci( fHandle )
% by: lpzds1
% date: May 28, 2015
%
% inputs: fHandle, colWidth [1, 1.5, 2]
% outputs: fHandle
%
% purpose: set font style, size, tight crop, paper size, etc.
% appropriate for a jneurosci figure
%
% e.g: % make a figure with 4 subplot
% for ii = 1:4, subplot(2,2,ii), plot(sin(linspace(0,2*pi,100))), title(sprintf('figure %i', ii)), xlabel('bla'), ylabel('blabla'), end
% jneurosci(gcf, 1.5) % convert to 1.5 column format.
% saveas(gcf, 'test.pdf')
if nargin < 2 || ~any( colWidth == [1 1.5 2])
colWidth = 1;
fprintf('setting column width to: %.1f\n', colWidth);
end
if nargin < 1 || ~ishandle(fHandle)
disp('(uhoh) provide a valid figure handle, please')
return
end
if ~(exist('tightfig','file') == 2)
disp('(uhoh) you need tightfig.m to use this function')
web('http://www.mathworks.com/matlabcentral/fileexchange/34055-tightfig')
return
end
% column is:
% Figures must be submitted at the size they are to appear in The Journal
% of Neuroscience. They should be the smallest size that will convey the
% essential scientific information, and sized to 1 column (maximum width
% 8.5 cm), 1.5 columns (maximum width 11.6 cm) or 2 columns (maximum width
% 17.6 cm).
% tightfig introduces a tiny border around... so need to account for that.
switch colWidth
case 1
paperWidth = 8.5 - 0.15;
case 1.5
paperWidth = 11.6 - 0.15;
case 2
paperWidth = 17.6 - 0.15;
end
%# set size on printed paper
%# WYSIWYG mode: you need to adjust your screen's DPI (*)
set(fHandle, 'Units', 'centimeters')
figureDims = get(fHandle, 'Position');
% don't let matlab change ticks
set(findall(fHandle,'type','axes'), ...
'xtickmode','manual', ...
'ytickmode','manual')
% resize to make w equal the currentPaperPosition(3)
marginOffset = [0 0];
aspectRatio = figureDims(3) ./ figureDims(4);
newPaperPosition = [marginOffset([1 2]), paperWidth, paperWidth./aspectRatio];
set(fHandle, 'Position', [5 5 newPaperPosition([3 4])]); % on screen, away from bottom left.
set(fHandle, 'PaperPosition', newPaperPosition);
set(fHandle, 'PaperType', 'a4');
% defaults - could also pass those in?!
% text and other stuff...
f.text.fontsize = 8;
f.text.fontname = 'Helvetica';
f.text.fontangle = 'normal';
f.text.fontunits = 'points';
% tick labels
f.axis.fontsize = 7;
f.axis.fontname = 'Helvetica';
f.axis.fontangle = 'normal';
f.axis.fontunits = 'points';
% change size of figure to appropriate paper size, then call tightfig!
% this is to make sure the final figure has the right dimensions:
% axis
set(findall(fHandle,'type','axes'),...
'fontangle',f.axis.fontangle, ...
'fontsize',f.axis.fontsize, ...
'fontname',f.axis.fontname, ...
'fontunits',f.axis.fontunits);
% text
set(findall(fHandle,'type','text'),...
'fontangle',f.text.fontangle, ...
'fontsize',f.text.fontsize, ...
'fontname',f.text.fontname, ...
'fontunits',f.text.fontunits);
% now call tightfig to remove white space before exporting
fHandle = tightfig(fHandle);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment