Changing Some MATLAB Plotting Defaults
Steve Eddins
on 10 Mar 2025
Over the last 5 years or so, the highest-traffic post on my MATLAB Central image processing blog was not actually about image processing; it was about changing the default line thickness in plots.
Now I have written about some other MATLAB plotting behavior that I have recently changed to suit my own preferences. See this new blog post.
Here is a standard MATLAB plot:
x = 0:pi/100:2*pi;
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2)
I don't like some aspects of this plot, and so I have put the following code into my startup file.
set(groot,"DefaultLineLineWidth",2)
set(groot,"DefaultAxesXLimitMethod","padded")
set(groot,"DefaultAxesYLimitMethod","padded")
set(groot,"DefaultAxesZLimitMethod","padded")
set(groot,"DefaultAxesXGrid","on")
set(groot,"DefaultAxesYGrid","on")
set(groot,"DefaultAxesZGrid","on")
With those defaults changed, here is my preferred appearance:
plot(x,y1,x,y2)
9 Comments
Time DescendingResults of my margins poll indicate a fairly even split between users that like the margins as is and those who think that they are too large:
I also think that many aspects of the default figure are not ideal.
Perhaps the best way forward would be for MathWorks to develop three to five default plot styles that get shipped with MATLAB. That way, each user could pick one of the available graphics themes in the settings. (Beyond what is possible with the Figure Copy Template in preferences.)
As it is, I often spend a lot of time modifying figure details and would much prefer to use a built-in theme.
A long-time small annoyance I have with the default/factory settings mechanism is the confusing labels such as "DefaultLineLineWidth" that I find quite user-non-friendly.
A better approach (IMHO) would have been to support dot-seperated values, as in:
set(groot,"Default.Line.LineWidth",2)
Perhaps this could be retroffitted into MATLAB, by having the engine ignore in-string dots in the setter method, and generate them in the getter. Just a thought....
I am a bit puzzled that the yticks changed ?
Sign in to participate