- Plot the main line with a thicker width to create the illusion of a margin.
- Plot the error bars using the desired colour.
How to set specific colors in margin of errorbars line?
6 views (last 30 days)
Show older comments
I use errorbar funtion in order to put errorbars in a plot. I would like to set a different color to the margin of the line.
I use
errorbar(x,y,z,'r-','LineWidth',3)
I would like for example to have red line with black margins..
Could you help me?
0 Comments
Answers (1)
Ayush
on 1 Jul 2024
Hi,
You can achieve a red line with a black margin effect by plotting the error bars and the main line separately and then customizing the properties of each. The two steps involved are:
Refer to an example code below for better understanding:
x = 1:10;
y = rand(1, 10);
z = 0.1 * rand(1, 10);
% Plot the main line with a thicker width for the margin
hLine = plot(x, y, 'k-', 'LineWidth', 5); % Black margin
hold on;
% Plot the main line with the desired color
plot(x, y, 'r-', 'LineWidth', 3); % Red line
% Plot the error bars
hErrorbar = errorbar(x, y, z, 'k', 'LineStyle', 'none'); % Black error bars
% Adjust the appearance of the error bars
hErrorbar.LineWidth = 1.5;
hold off;
The plot function is used twice to create the main line with a black margin and a red line. The errorbar function plots the error bars with black colour, and the LineWidth property is adjusted to create the desired appearance.
0 Comments
See Also
Categories
Find more on Errorbars in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!