Setting default line widths for all plotting functions
조회 수: 379 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
Steven Lord
2023년 8월 16일
Looking at your second question first, if you look at the end of the fimplicit function's documentation page, there's a link to "ImplicitFunctionLine Properties". On that page, the value of the Type property is 'implicitfunctionline'. By the "Specify Default Values" section on this documentation page that means you should set the property:
P = "default" + "implicitfunctionline" + "LineWidth"
This sort of implicitly answers your first question. Let's try it.
h = fimplicit(@(x,y) x.^2 - y.^2 - 1);
d = h.LineWidth % show the factory default
title("LineWidth of " + d)
set(groot, P, 10*d);
figure
h = fimplicit(@(x,y) x.^2 - y.^2 - 1);
d = h.LineWidth % show the factory default
title("LineWidth of " + d + " after changing default")
For your third question I believe the answer is no. However, if you're okay with changing the properties of all objects with a LineWidth property after the fact, you could use the findall or findobj functions and ask for all objects that have a LineWidth.
h = findall(groot, ... % All graphics objects that are "descendants" of groot (i.e. all of them)
'-property', 'LineWidth') % that possess a LineWidth property
Note that in addition to the lines created by fimplicit h lists two axes (which the axes properties page states controls "Line width of axes outline, tick marks, and grid lines, specified as a positive numeric value in point units. One point equals 1/72 inch.") and two text objects (the titles, for which the text properties page says the LineWidth property controls "Width of box outline, specified as a scalar numeric value in point units. One point equals 1/72 inch.")
So let's look at what would happen if you changed all those LineWidths to something much larger. It might not look exactly as you want, since the axes has a LineWidth.
f = figure;
h = fimplicit(@(x,y) x.^2 - y.^2 - 1);
t = title('Example');
titleLineWidthBefore = t.LineWidth
hasLineWidth = findall(f, '-property', 'LineWidth')
set(hasLineWidth, 'LineWidth', 10)
The LineWidth change did affect the text object returned by title, but since that object's EdgeColor is 'none' we don't see any visible change.
t.EdgeColor
titleLineWidthAfter = t.LineWidth
추가 답변 (1개)
Adam Danz
2023년 8월 16일
편집: Adam Danz
2023년 8월 16일
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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!