Setting default line widths for all plotting functions
Mostrar comentarios más antiguos
MATLAB's default linewidths are all too narrow for my taste. I have a startup.m file with many lines like
set(groot,'DefaultLineLineWidth',2)
set(groot,'DefaultContourLineWidth',1.5)
set(groot,'DefaultFunctionContourLineWidth',2)
Every time I learn about a new plot type, I have to add an additional line to my startup file. Today I needed to use fimplicit. So far, I haven't figured out what to set to fix this. This leads me to three questions.
- What's the line I need to add to my startup file?
- How would I reverse engineer this to find out without posting here?
- Is there a master linewidth that I could set which would set all line widths for all time, no matter what function was used to create them?
Respuesta aceptada
Más respuestas (1)
This issues comes up from time to time. As @Steven Lord mentioned, there is no global setting that would apply to all LineWidth properties.
Here's an alternative approach inspired by the work of another user who recently faced this problem. I've generalized and slightly improved the solution below.
It makes the following assumptions
- All LineWidth properties will be listed in the groot factory list
- All LineWidth properties can be identified as ending in "LineWidth" as Steven Lord explained.
- All factory properties ending in LineWidth affect the LineWidth property of an object and can accept a value of 1.
- All LineWidth factory properties can be converted to default property names
This was tested in R2023a which lists 46 linewidth names
% List all factory properties
factoryNames = fieldnames(get(groot,'factory'));
% Identify and extract the factory properties that end with "LineWidth"
factoryLineWidthIndex = endsWith(factoryNames,'LineWidth');
factoryLineWidthNames = factoryNames(factoryLineWidthIndex)
% Convert the factory property list to default property names
defaultLineWidthNames = regexprep(factoryLineWidthNames,'^factory','default')
% Loop through the default line width names and set their value to 1
for i = 1:numel(defaultLineWidthNames)
set(groot,defaultLineWidthNames{i},1)
end
Test it
fig = figure();
ax = axes();
hold on
h = plot([1,2]);
xl = xline(1.5);
cb = colorbar();
h.LineWidth
xl.LineWidth
cb.LineWidth
ax.LineWidth
close(fig)
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


