Change default figure properties?

조회 수: 115 (최근 30일)
Robert Ralich
Robert Ralich 2012년 5월 3일
댓글: Mara Gati 2022년 4월 24일
Is there any way to change the default figure properties in MATLAB?
For example, I want all my figures to have a certain axis font size, background color, xlabel/ylabel font size, and line width. Nothing fancy, just want to change some basic default settings.
I know how to do this for each individual plot in my scripts. However, I am generating several different types of plots (plot, hist, surf, etc) and a lot of them from several different scripts.
Thanks for any help with this.
  댓글 수: 2
Richa  Singh
Richa Singh 2021년 1월 23일
Yes, there is.. I am using it for all my matlab figures.
set(groot,'defaultLineLineWidth',2.5)
set(0,'DefaultaxesLineWidth', 1.5)
set(0,'DefaultaxesFontSize', 14)
set(0,'DefaultaxesFontWeight', 'bold')
set(0,'DefaultTextFontSize', 14)
set(0,'DefaultaxesFontName', 'Times new Roman')
set(0,'DefaultlegendFontName', 'Times new Roman')
set(0,'defaultAxesXGrid','on')
set(0,'defaultAxesYGrid','on')
Ask Finderup
Ask Finderup 2022년 1월 17일
Do you know how to the reset those properties?

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff
Geoff 2012년 5월 3일
I don't know if there's a way to change the defaults, but you'll save a lot of work if you create a function to apply your 'default' settings to any supplied figure. Pass in a handle to that figure.
function = SetFigureDefaults( f )
% Put all your common code in here
end
That will make your code a whole lot more readable. You can hide this function in your script so that it's not visible to the outside world. That way you can take advantage of this approach in many other scripts without getting confused.
  댓글 수: 4
Robert Ralich
Robert Ralich 2012년 5월 4일
Got it, seems to work. I have to set all these properties in a script (.m file) and call it after every figure.
Thank you very much for your help.
Mara Gati
Mara Gati 2022년 4월 24일
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 5월 4일
편집: Wendy Fullam 2013년 2월 4일
  댓글 수: 5
David Christhilf
David Christhilf 2017년 8월 29일
That seems to no longer work in R2017a.
I would very much like to kill the 'autoupdate' feature of 'legend' in one single global action. It seems there should be some way to set the default for the 'legend' aspect of 'plot'.
Steven Lord
Steven Lord 2017년 8월 29일
David, you asked this as a separate question and the comment you left indicates you found a solution.
Ah, I see why you said this no longer works. The URL changed for the page to which Walter link; the updated address is:
https://www.mathworks.com/help/matlab/creating_plots/default-property-values.html
Or you can search for the phrase "default property values" and that should work regardless of which release you're using. The version of that page appropriate for the release you're using should be among the first page of hits, if not the first hit.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by