How to color individual points on errorbar plot?

Hi,
I want to color the individual points of this errorbar plot. I tried doing it in the following way but it doesn't work.
means=[1 1 2 3 4];
standarddeviation=[0.1 0.2 0.2 0.3 0.35];
color=['b' 'm' 'b' 'm' 'b'];
errorbar(means, standarddeviation,'.','MarkerEdgeColor', color,'MarkerSize',20),;
I also tried plotting it in a for loop but that doesn't work at all.
means=[1 1 2 3 4];
standarddeviation=[0.1 0.2 0.2 0.3 0.35];
color=['m','m','k','g','r'];
for i = 1:numel(means)
errorbar(means(i), standarddeviation(i),'.'),'MarkerEdgeColor', color(i),;
hold on
end
Can someone help me fix this?

 Réponse acceptée

You need to plot with respect to an independent variable.
Try this:
means=[1 1 2 3 4];
standarddeviation=[0.1 0.2 0.2 0.3 0.35];
color=['m','m','k','g','r'];
figure
hold on
for i = 1:numel(means)
errorbar(i, means(i), standarddeviation(i),'.','MarkerEdgeColor', color(i))
end
hold off
xlim([0 6])
I chose the loop index ‘i’ for the independent variable here.
.

3 commentaires

Nehal Trivedi
Nehal Trivedi le 27 Sep 2022
Déplacé(e) : Star Strider le 28 Sep 2022
Hello @Star Strider. I wanted to change the colour of the errorbar meaning I want the vertical lines in red colour and the plot in blue colour. I have written a code for it but not able to generate it. I am generating the data from excel. How can it be done?
clc
clear all
load('Calibration.mat')
Height= WorkoutData.TankHeightcm;
Voltage= WorkoutData.Average;
err= WorkoutData.StandardDeviation;
figure(1)
errorbar(Voltage,Height,err)
grid on
xlabel('Sensor reading [V]');
ylabel('Tank height [cm]');
legend('Tank 1','FontSize',8, 'Location','northeast');
Nehal Trivedi
Nehal Trivedi le 27 Sep 2022
Déplacé(e) : Star Strider le 28 Sep 2022
I have generated this plot in Origin Pro. I wanted to generate in similar way.
The only way I can think of to do that is to plot the line first and then the errorbars (although it is possible to do that in reverse, depending on wwhat you want) —
x = 0:10:90;
y = linspace(1, 9, 10);
err = ones(size(x));
figure
plot(x, y, '-sb', 'MarkerFaceColor','b', 'MarkerEdgeColor','b')
hold on
errorbar(x, y, err, '.r', 'MarkerSize',1);
hold off
grid
axis([-10 100 -1 11])
In order to plot the errorbars without the connecting line, plot them using a marker. Here I chose a red dot, with the dot vanishingly small.
.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by