Adding standard deviation as a bar to a scatter plot

33 vues (au cours des 30 derniers jours)
Joseff Saunders
Joseff Saunders le 10 Déc 2018
Hello all, I'm plotting weather data and want to show the mean, standard deviation and min-max values in one plot. I've attached a photo of the ideal end result. How might I go about it using the data below as an example?
Mean_Temp_1 = [12]
Mean_Temp_2 = [15]
Mean_Temp_3 = [11]
Temp.jpg
SD_1 = [1.2]
SD_2 = [0.8]
SD_3 = [1.4]
Max_1 = [14]
Max_2 = [17]
Max_3 = [12]
Min_1 = [10]
Min_2 = [12]
Min_3 = [10]

Réponse acceptée

Jaswanth
Jaswanth le 25 Juil 2024
Hi Joseff,
To create a scatter plot in MATLAB that shows the mean, standard deviation, and min-max values for your weather data, you can use the errorbar function to add error bars representing the standard deviation and plot to add lines for the min and max values.
Please refer to the following example code demonstrating how to achieve this:
% Data
Mean_Temp = [12, 15, 11];
SD = [1.2, 0.8, 1.4];
Max_Temp = [14, 17, 12];
Min_Temp = [10, 12, 10];
% X-axis values
x = 1:3;
% Create the scatter plot with mean temperatures
figure;
scatter(x, Mean_Temp, 'filled');
hold on;
% Add error bars for standard deviation
errorbar(x, Mean_Temp, SD, 'LineStyle', 'none', 'Color', 'k', 'CapSize', 10);
% Plot min and max values as lines
for i = 1:length(x)
plot([x(i) x(i)], [Min_Temp(i), Max_Temp(i)], 'r-', 'LineWidth', 2);
end
% Customize the plot
xlabel('Data Points');
ylabel('Temperature (°C)');
title('Weather Data: Mean, Standard Deviation, and Min-Max Values');
legend('Mean Temperature', 'Standard Deviation', 'Min-Max Range', 'Location', 'Best');
grid on;
hold off;
Kindly refer to the following MathWorks documentation to know more about the functions discussed above:
Please refer to following MathWorks documentation on boxplot which may help in creating visualization similar to one shown the reference image you have posted: https://www.mathworks.com/help/stats/boxplot.html?searchHighlight=boxplot&s_tid=srchtitle_support_results_1_boxplot#bu180jd_vh
I hope the information provided above is helpful.

Plus de réponses (0)

Catégories

En savoir plus sur Errorbars dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by