Code covered by the BSD License  

Highlights from
ConvertPlot4Publication

4.75

4.8 | 9 ratings Rate this file 64 Downloads (last 30 days) File Size: 39.5 KB File ID: #34741

ConvertPlot4Publication

by

 

23 Jan 2012 (Updated )

Adjusts figures for consistent appearance and saves them in multiple formats

| Watch this File

File Information
Description

ConvertPlot4Publication - This function formats figures and outputs files for a publication

This function formats a figure in a way that they are ready for a
publication, i.e. width and height of the figure, textsize, textfont, alignment of
subplots and backcolor and finally saves this figure in various formats (such as
MATLAB .fig, PDF, EPS, PNG, or PSFrag).

You can use this function to save all your figures which you might later
want to use for a publications. This way all your plots will be readily
available in different output formats and consistent formatting.

Syntax: ConvertPlot4Publication(filename,varargin)

Inputs:
   filename (Required) - A string containting the name of the output files.
   OPTIONS (Optional) - additional options are added in 'key' and 'value'
                    pairs
   Key | Value
   ----------------------------------------------------------------------
   'figure' | Figure to create the files from.
                 | default is gcf (current figure handle)
   'height' | Height of final figure in inch. If no value is given
                 | the current figure width is taken.
   'width' | Width of final figure in inch. Default is 3.45in
|(IEEE journal column width).
   'backcolor' | [none] - Changes the backcolor of the figure. Default is
| none.
   'samexaxes' | [on, off] - Defines if in case of stacked subplots
                 | only the x-axis from the lowest subplot is taken. Default is off.
                 | default is gcf (current figure handle)
   'tickdir' | [in, out] - Direction of ticks.
   'box' | [on, off] - Box around each plot is switched on or
                 | off.
   'fontname' | Fontname used for each text element. Default value is 'Times New Roman'.
   'fontsize' | Fontsize of each text element, including axis and legends. Default value is 10.
   'linewidth' | Linewidth of each line. Default is 1.
   'keepheights' | [on, off] - Do not change axes heights (default: off)
   'keepvertical'| [on, off] - Do not rearange vertical position of the axes. (default: off)
   'pdf' | [on, off] - PDF output (default: on)
   'png' | [on, off] - PNG output (default: on)
   'eps' | [on, off] - EPS output (default: on)
   'psfrag' | [on, off] - Psfrag output (default: off)
   'fig' | [on, off] - MATLAB .fig output (default: on)

Outputs:
   none

Example:

      %Generate some data
      y1 = randn(1000,1);
      y2 = randn(1000,1);
      
      %Plot using two subplots
      figure
      subplot(2,1,1)
      plot(y1)
      ylabel('Y1')
      subplot(2,1,2)
      plot(y2)
      ylabel('Y2')
      xlabel('X')

      %Export using the default options (output
      ConvertPlot4Publication('testPlot')

      %Export again, this time changing the font and using the same x-axis
      ConvertPlot4Publication('testPlot2', 'fontsize', 8, 'fontname', 'Arial', 'samexaxes', 'on', 'eps', 'off')

Other m-files required: matlabfrag.m, export_fig.m (from matlabcentral)
Subfunctions: none
MAT-files required: none

Authors: Tobias Wartzek, Christoph Brueser

Acknowledgements

Matlabfrag and Export Fig inspired this file.

MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
15 Jan 2014 Jonne  
04 Oct 2013 Eneko

Hi
Many thanks for this excellent function, it is really helping me a lot.

However, I am experiencing the same problem as the one Bahaa has commented below. When trying to use the function with an asymmetric figure, the results are not as if they were symmetric.

I have been trying to do the next example:

%********************
figure
subplot(3,1,[1 3 5])
plot(x,y)
subplot(3,1,[2 4])
plot(x2,y2)
subplot(3,1,6)
plot(x3,y3)
ConvertPlot4Publication('Figure', 'fontsize', 9, 'eps', 'off', 'png', 'off', 'fig', 'off')
%********************

I wanted to know if there is any possibility for this to be done or if the Figure must be symmetric.

Many thanks in advance,

Eneko

04 Oct 2013 Eneko  
03 Oct 2013 Eneko  
17 Mar 2013 Henrik

Hi
I have a problem with this function in combination with legendflex: http://www.mathworks.com/matlabcentral/fileexchange/31092-legendflex-a-more-flexible-legend
For some reason it sees the legend as a subplot.. Here's an example of the problem:

y1 = randn(1000,1);
plot(y1)
legh={'leg1'};
legendflex(legh,'xscale',0.5)
ConvertPlot4Publication('testPlot')

23 Nov 2012 Cevin

Hi Christoph,
very nice and handy tool you created. I got the same issue as Markus observed with the colorbar.
Is there a workaround for that?
Everything else works very well.
Thanks
Cevin

20 Sep 2012 Bahaa

Hi Christoph,
thank you a lot for the wonderful code.
I have noticed that it cannot deal with asymmetric partitioning in the figure as below. and wanted to report this to you.
%-----------------------------
h=figure;
subplot 211
xlabel('x'), ylabel('y'),grid on
subplot 223
xlabel('x'), ylabel('y'),grid on
subplot 224
xlabel('x'), ylabel('y'),grid on
ConvertPlot4Publication('testPlot','pdf','off','eps','off','fig','off')
%---------------------------------
thank you again
-Bahaa

13 Aug 2012 Uwe

Hey Christoph,

first of all many thanks for this wonderful script!
Can it handle 2 y-axes somehow. I try to create a graph with plotyy but it always cuts the right side and moves both y axes to the left.

Thanks,
Uwe

19 Mar 2012 Christoph Brueser

@Jeff: Thanks for the bug report. I fixed this issue in the latest update (currently in review with MathWorks).

@Markus: Thanks again. You are right, the function currently handles colorbars like any other axis object. I will have to add some special code so that it will treat them correctly. Hopefully, I can include a fix in the next update.

18 Mar 2012 Markus

Nice tool,Thanks.

However,I encountered some problems to process surf with a colorbar. The Background color changed and colorbar and surf got separate.

k = 5;
n = 2^k-1;
[x,y,z] = sphere(n);
c = hadamard(2^k);
surf(x,y,z,c);
colormap([1 1 0; 0 1 1])
axis equal

ConvertPlot4Publication('testPlot')

16 Mar 2012 Jeff Parker

Thanks Christoph for the update! Now it seems to reverse the vertical order of the plots with subplot, even for the example in the beginning comments.

16 Mar 2012 Jeff Parker  
13 Mar 2012 Jannick

Thanks it however still returns an error in snapnow with my r2008a version, namely:
??? Attempt to reference field of non-structure array.

Error in ==> snapnow at 41
iCell = data.lastGo;

Without snapnow it works fine.

13 Mar 2012 Christoph Brueser

Hi Jannick,

the ~ syntax for return argument was newly introduced in MATLAB R2009b. It is used to mark unwanted return values. If you have a version prior to R2009b, you can just replace the ~ in this line by a dummy variable name. I.e.

[dummy, idx] = sort(posMat(:,2),1,'descend');

13 Mar 2012 Jannick

I get an error in ConvertPlot4Publication in line 151.

[~, idx] = sort(posMat(:,2),1,'descend');

This also seems to be strange syntax.

12 Mar 2012 Christoph Brueser

Hello Jeff, thanks for your feedback.

I've just submitted an updated version of the file which should now properly handle grids of subplots (i.e. it will no longer just stack them on top of each other, but maintain the correct column order).

The update should be online as soon as Mathworks approves it.

08 Mar 2012 Jeff Parker

I really like this, although I can't get it work for a 2x2 grid of subplots. It only gives me a single column. It seems to try to stack the columns on top of each other.

Updates
12 Mar 2012

Updated ConvertPlot4Publications to support axes grids created with subplot.

19 Mar 2012

Fixed a bug introduced during the last update which would reverse the vertical order of subplots (thanks to Jeff Parker for pointing this out). Changed the default figure background to white.

Contact us