How to set specific colors in margin of errorbars line?

3 次查看(过去 30 天)
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?

回答(1 个)

Ayush
Ayush 2024-7-1
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:
  1. Plot the main line with a thicker width to create the illusion of a margin.
  2. Plot the error bars using the desired colour.
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.

类别

Help CenterFile Exchange 中查找有关 Errorbars 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by