SetFigPaper

Function to modify the style of the graphical representations of MATLAB
244.0 次下载
更新时间 2023/4/10

编者注: This file was selected as MATLAB Central Pick of the Week

View SetFigPaper on File Exchange View SetFigPaper on Mathworks Blog Donate Donate

SetFigPaper

Introduction

With this function it is possible to modify multiple style parameters of MATLAB graphic representations. It is only necessary to include the function call after the graphic representation code, that's all.

It can be used in two ways:

  • Name-Value pair arguments: setfigpaper('Width',[20,0.65],'Interpreter','Latex'). Only the parameters you want to modify are necessary.
  • Only values: setfigpaper([20,0.65],10,'Helvetica','Latex'). With explicit order: (Width,FontSize,FontName,Interpreter,Grayscale,LineWidth,Figure).

The available options are:

Name Description
Width Simple: one integer. With aspect ratio: array with two elements, the width and the aspect ratio.
FontSize The font size in all texts in the figure.
FontName Font family.
Interpreter Text interpreter syntax, 'Latex', 'tex' or 'none'. If you don't want to modify the interpreter the value must be [] (empty value).
Grayscale Change all colours to grayscale. [boolean]
LineWidth Set line width only for axes, not for data.
Figure Apply to a specific figure.

Examples

Grayscale

Example 1

setfigpaper('GrayScale',true)

Code: MathWorks Plot Gallery Team (2020). MATLAB Plot Gallery - Wind (https://www.mathworks.com/matlabcentral/fileexchange/35250-matlab-plot-gallery-wind), MATLAB Central File Exchange. Retrieved May 14, 2020.

Original setfigpaper

Example 2

setfigpaper('GrayScale',true)

Code: MathWorks Plot Gallery Team (2020). MATLAB Plot Gallery - Subplot (2) (https://www.mathworks.com/matlabcentral/fileexchange/35298-matlab-plot-gallery-subplot-2), MATLAB Central File Exchange. Retrieved May 14, 2020.

Original setfigpaper

Interpreter

Example 1

setfigpaper('Interpreter','Latex')

Code: MathWorks Plot Gallery Team (2020). MATLAB Plot Gallery - Heatmap Chart (https://www.mathworks.com/matlabcentral/fileexchange/63457-matlab-plot-gallery-heatmap-chart), MATLAB Central File Exchange. Retrieved May 14, 2020.

Original setfigpaper

Example 2

setfigpaper('Interpreter','Latex')

Code: MathWorks Plot Gallery Team (2020). MATLAB Plot Gallery - Line Plot 2D (2) (https://www.mathworks.com/matlabcentral/fileexchange/35256-matlab-plot-gallery-line-plot-2d-2), MATLAB Central File Exchange. Retrieved May 14, 2020.

Original setfigpaper

FontName

  • Only work with 'Tex' interpreter

Example 1

setfigpaper('FontName','Courier')

Code: https://www.mathworks.com/help/matlab/ref/wordcloud.html

Original setfigpaper

Example 2

setfigpaper('FontName','Times New Roman')

Code: MathWorks Plot Gallery Team (2020). MATLAB Plot Gallery - Heatmap Chart (https://www.mathworks.com/matlabcentral/fileexchange/63457-matlab-plot-gallery-heatmap-chart), MATLAB Central File Exchange. Retrieved May 14, 2020.

Original setfigpaper

FontSize

Example 1

setfigpaper('FontSize',6)

Code: https://www.mathworks.com/help/matlab/ref/parallelplot.html

Original setfigpaper

Example 2

setfigpaper('FontSize',15)

Code: MathWorks Plot Gallery Team (2020). MATLAB Plot Gallery - Directed Graph Plot (https://www.mathworks.com/matlabcentral/fileexchange/63456-matlab-plot-gallery-directed-graph-plot), MATLAB Central File Exchange. Retrieved May 14, 2020.

Original setfigpaper

LineWidth

Example 1

setfigpaper('LineWidth',2)

Code: MathWorks Plot Gallery Team (2020). MATLAB Plot Gallery - Set Axes Positions (https://www.mathworks.com/matlabcentral/fileexchange/63458-matlab-plot-gallery-set-axes-positions), MATLAB Central File Exchange. Retrieved May 14, 2020.

Original setfigpaper

Example 2

setfigpaper('LineWidth',1.5)

Code: MathWorks Plot Gallery Team (2020). MATLAB Plot Gallery - Scatter Plot 3D (https://www.mathworks.com/matlabcentral/fileexchange/35288-matlab-plot-gallery-scatter-plot-3d), MATLAB Central File Exchange. Retrieved May 14, 2020.

Original setfigpaper

Troubleshooting

In some representations, it is necessary to carry out previous steps for the function to work correctly.

  • pie and pie3: If you use LaTeX interpreter with default labels (percentage) you need to fix the plot before call setfigpaper. Solution:

     p = pie([1 3 0.5 2.5 2]);
     txt = findobj(p,'Type','Text');
     arrayfun(@(x) set(x,'String',strrep(x.String,'%','\%')),txt,...
     'UniformOutput',false)
     setfigpaper
  • pareto: If you use LaTeX interpreter with default ticklabels (percentage) you need to fix the plot before call setfigpaper. Solution:

     [H,ax]  = pareto([200 120 555 608], {'Fred','Ginger','Norman','Max'});
     ax(2).YTickLabel = arrayfun(@(x) strrep(x,'%','\%'),ax(2).YTickLabel);
     setfigpaper

Incompatibility Issues

Setfigpaper is developed in MATLAB 2020. In some versions not all options are available. The function checks the version so that the incompatible code is not executed.

If you find any error or the modification does not apply to any item, please inform me and I will try to solve it.

Legend meaning:

  • #f03c15 Fixed by version checking.
  • #efb810 It runs but doesn't affect.

MATLAB 2018b (9.5) and earlier

   Axes/Object Description Line code
#f03c15 Heatmap Unable to assign an interpreter to text within the map. set(ax.Heatmap,'Interpreter',type);
#f03c15 GraphPlot Cannot modify node font. set(grap,'nodefontname',...
#efb810 Polar Axes Grayscale cannot be applied to all elements.

Author

Jose M. Requena Plens, 2020. (info@jmrplens.com | joreple@upv.es)

Original concept: Noe Jimenez, 2014. (noe.jimenez@csic.es | nojigon@i3m.upv.es)

Donate Donate

引用格式

Requena-Plens, Jose M. SetFigPaper (https://www.github.com/jmrplens/SetFigPaper), GitHub. 2020.

MATLAB 版本兼容性
创建方式 R2020a
兼容任何版本
平台兼容性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

无法下载基于 GitHub 默认分支的版本

版本 已发布 发行说明
1.0.3

Readme update

1.0.2

Fixed: The title in colorbar was not modified.
Added option: Apply to a specific figure.

1.0.1

Fix compatibility issues. If you find any error or the modification does not apply to any item, please inform me and I will try to solve it.

1.0.0

要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库
要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库