Setting Default Errorbar properties does not affect plots
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Francesco
el 5 de Feb. de 2025
Comentada: Samayochita
el 24 de Jun. de 2025
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 comentarios
Respuesta aceptada
Samayochita
el 10 de Feb. de 2025
Editada: Samayochita
el 19 de Jun. de 2025
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 comentarios
Samayochita
el 24 de Jun. de 2025
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?
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!