Setting Default Errorbar properties does not affect plots
1 回表示 (過去 30 日間)
古いコメントを表示
Hello everyone. While working with Matlab, I implemented a function which sets several default graphics properties, such as label size, figure size, line colors, etc... following some custom presets, which is very useful to switch plots from presentation to journal specifications.
This is how is implemented:
function MP = MPStyle
GraphicRoot = groot;
% Lots of custom color, sizes, fonts, units, etc... are set in the MP
% structure.
MP.GeneralDefaultSettings = {...
"DefaultAxesFontName", MP.fonts.SansSerif,...
"DefaultAxesFontSize", MP.sizes.Font,...
"DefaultAxesTitleFontSizeMultiplier", MP.sizes.TitleMult,...
"DefaultAxesLabelFontSizeMultiplier", MP.sizes.LabelMult,...
"DefaultLegendFontSize", MP.sizes.Legend,...
"DefaultFigureUnits", MP.pictures.Units,...
"DefaultFigurePaperUnits", MP.pictures.Units,...
"DefaultFigurePosition", [10 10 12 9],...
"DefaultLineHandleVisibility", "off",...
"DefaultAxesXGrid", "on",...
"DefaultAxesYGrid", "on",...
"DefaultAxesLayer", "top",...
"DefaultTiledlayoutPadding", "compact",...
"DefaultScatterMarker", "diamond",...
"DefaultScatterMarkerFaceColor", MP.colors.White.rgb,...
"DefaultErrorbarColor", MP.colors.DeepGrey.rgb,... %% relevant issue for this post
"DefaultErrorbarMarker", "none",... %% relevant issue for this post
"DefaultErrorbarLineStyle", "none",... %% relevant issue for this post
"DefaultErrorbarHandleVisibility", "off",... %% relevant issue for this post
"DefaultAxesColorOrder", MP.colors.DefaultPalette};
set(GraphicRoot, MP.frfr.GeneralDefaultSettings{:}); % Apply custom graphics settings
end
As you can see, i marked a few lines in the GeneralDefaultSettings definition. While everything works and all the graphic settings are applied correctly, for some reason these four settings about errorbar do not apply when running the scripts. It usually works like this:
% Workspace cleanup
close all
clearvars
MP = MPStyle; % Imports MP colours and formatting for plots
% Rest of the script with plots
When making a plot with error bars, they all show up with different colors, as instructed by "DefaultAxesColorOrder", with a visible line ("DefaultErrorbarLineStyle" should be "none") and the error bars are counted by the legend() command (they shouldn't, as "DefaultErrorbarHandleVisibility" is "off").
Is there something I am doing wrong? I can't figure out the origin of the issue, since similar instruction work for scatter() or labels().
Thank you in advance for your help.
0 件のコメント
採用された回答
Samayochita
2025 年 2 月 10 日
編集済み: Samayochita
2025 年 6 月 19 日
Hi Francesco,
It looks like the issue is that MATLAB does not apply default properties to “errorbar” objects in the same way it does for “scatter”, “line”, or “axes”. Unlike other graphics objects, “errorbar” objects do not fully inherit their properties from “groot” defaults.
Instead, they derive some of their properties from “axes” settings and some are defined explicitly when the object is created.
Since “errorbar” is technically a combination of line objects (the main data line + vertical/horizontal error bars), it inherits the “DefaultAxesColorOrder”. That's why your error bars still have different colors. Moreover,the “HandleVisibility” property does not work as expected because “errorbar” creates multiple internal line objects (main line + error bars). These may have different visibility settings that override your “DefaultErrorbarHandleVisibility”.
One possible workaround would be to modify the properties after creating the plot. For example:
x = 1:5;
y = [2 3 5 7 11];
err = [0.2 0.3 0.5 0.7 1.1];
MP = MPStyle; % Apply graphics settings
hError = errorbar(x, y, err);
hError.LineStyle = 'none'; % Explicitly set, since DefaultErrorbar settings won't apply
hError.Color = MP.colors.DeepGrey.rgb; % Manually apply DeepGrey color
hError.Marker = 'none';
hError.HandleVisibility = 'off';
Hope this helps!
2 件のコメント
Samayochita
2025 年 6 月 24 日
Hi @Francesco, I would like to better understand the motivation for setting default errorbar properties. Could you briefly share what benefit you are looking for by using default errorbar properties?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File 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!