How to set specific colors in margin of errorbars line?

4 Ansichten (letzte 30 Tage)
Ivan Mich
Ivan Mich am 12 Aug. 2021
Beantwortet: Ayush am 1 Jul. 2024
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?

Antworten (1)

Ayush
Ayush am 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:
  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.

Kategorien

Mehr zu Errorbars finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by