- errorbar: https://www.mathworks.com/help/matlab/ref/contourf.html?searchHighlight=contourf&s_tid=srchtitle_support_results_1_contourf#d126e250644
- plot: https://www.mathworks.com/help/matlab/ref/view.html?searchHighlight=view&s_tid=srchtitle_support_results_1_view#d126e1827914:~:text=view(90%2C0)-,Display%20Surface%20in%20a%202%2DD%20View,-Change%20the%20View
Adding standard deviation as a bar to a scatter plot
33 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Joseff Saunders
le 10 Déc 2018
Réponse apportée : Jaswanth
le 25 Juil 2024
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]
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]
0 commentaires
Réponse acceptée
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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Errorbars dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!