How to set specific colors in margin of errorbars line?

조회 수: 4 (최근 30일)
Ivan Mich
Ivan Mich 2021년 8월 12일
답변: Ayush 2024년 7월 1일
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