フィルターのクリア

Heat Map or color map of overlapping multiple line plots

25 ビュー (過去 30 日間)
Mark
Mark 2023 年 7 月 12 日
コメント済み: Mark 2023 年 7 月 12 日
I have 300 line plots of altitude profile of temperature and would like to visualise it in such a way which it is more quantitative instead of just plotting the line plots. I found this plots below interesting which I would like to plot but not sure how to do it. I also like to plot mean, median and mode temperature as given in the sample plot. I think my plots for mode is also wrong.
Here is my current MATLAB Code. I tried to reproduce my data here.
% Generate sample data
numProfiles = 300; % Number of temperature profiles
numAltitudes = 101; % Number of altitude points (from 0km to 100km with 1km increment)
altitude = 0:1:100; % Altitude values in km
temperatures = zeros(numAltitudes, numProfiles);
% Generate temperatures with increased variation in specific altitude ranges
baseTemperature = 200 + altitude' * 3; % Base temperature profile
% Generate variations for each profile
for i = 1:numProfiles
variation = zeros(numAltitudes, 1);
% Add varying magnitudes of variation at different altitude points
for j = 1:numAltitudes
if altitude(j) < 20
variation(j) = randn * 50; % Large variation
elseif altitude(j) < 50
variation(j) = randn * 10; % Increased variation
elseif altitude(j) < 70
variation(j) = randn * 3; % Moderate variation
else
variation(j) = randn * 1; % Very small variation
end
end
temperatures(:, i) = baseTemperature + variation;
end
% Plotting
figure;
hold on;
% Compute mean, median, and mode
meanTemperature = mean(temperatures, 2);
medianTemperature = median(temperatures, 2);
modeTemperature = mode(temperatures, 2);
colors = lines(numProfiles); % Generate a color map with distinct colors
% Plot mean, median, and mode
for i = 1:numProfiles
plot(meanTemperature, altitude, 'k-', 'LineWidth', 2);
plot(medianTemperature, altitude, 'r-', 'LineWidth', 2);
plot(modeTemperature, altitude, 'b-', 'LineWidth', 2);
plot(temperatures(:, i),altitude, 'Color', colors(i, :)); % Assign distinct color to each plot
end
% Customize the plot
ylabel('Altitude (km)');
xlabel('Temperature (K)');
% Additional legends with custom line colors
legend({'Mean', 'Median', 'Mode'}); lineColors = {'k', 'r', 'b'}; lineStyles = {'-', '-', '-'};
grid on;

回答 (1 件)

Aditya Singh
Aditya Singh 2023 年 7 月 12 日
Hi Mark,
To my understanding you have a large dataset and want to visualize it.
If you want a comprehensive overview of the temperature variations across different profiles and altitudes, then a color plot is better. Since we have 300 profiles, the x-axis scales form 0 to 300. The data would then look like
The mean, median and mode of the data is represented in the corner.
The data can also be plotted as a scatter plot, it give more insight to the values at each point and is more readable than the line plot.
The green line is the mode, red is the meadian and the black is the mean of the data. You can refer the below code for calculating and plotting the mean, median and mode of the data.
meanTemperature = mean(temperatures, 2);
medianTemperature = median(temperatures, 2);
modeTemperature = mode(temperatures, 2);
% Calculate mean, median, and mode temperature for each altitude point
meanTemperature = mean(temperatures, 2);
medianTemperature = median(temperatures, 2);
modeTemperature = mode(temperatures, 2);
figure;
hold on;
for i = 1:numProfiles
plot(temperatures(:, i), altitude, 'Color', rand(1,3)); % Random color for each plot
%scatter(temperatures(:, i), altitude, 50, rand(1,3), 'filled');
%uncomment the above for scatter plot
end
% Plot mean, median, and mode temperature
plot(meanTemperature, altitude, 'k-', 'LineWidth', 2); % Mean temperature with solid line
plot(medianTemperature, altitude, 'r--', 'LineWidth', 2); % Median temperature with dashed line
plot(modeTemperature, altitude, 'g:', 'LineWidth', 2); % Mode temperature with dotted line
% Customize the plot
ylabel('Altitude (km)');
xlabel('Temperature (K)');
legend('Temperature Profiles', 'Mean Temperature', 'Median Temperature', 'Mode Temperature');
grid on;
On the line plot, the mean,median and mode looks like
For more information, please refer to:
Hope it helps!
  1 件のコメント
Mark
Mark 2023 年 7 月 12 日
Thanks @Aditya Singh. This will be of some help. Will you be able to plot something like this figure.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by