Make contour plot with z values against year in x-axis and Date in y-axis?

1 回表示 (過去 30 日間)
shravani banerjee
shravani banerjee 2022 年 3 月 31 日
回答済み: Manish 2024 年 10 月 4 日
I have a CSV file with temperature values. The temperature values are for each day of june month from 1990-2020. See the attached file. I am plotting a contour plot of temperature values against year and day with years in x-axis and day in y-axis. Kindly help me out. Thanks in advance!

回答 (1 件)

Manish
Manish 2024 年 10 月 4 日
Hi,
I understand you want to contour plot of the temperature where years on the x-axis and day on y-axis and temperature on the z-axis.
Here is the code implementation :
data = readtable('mean_temp_june1.csv');
% Convert the date column to datetime format using the correct format
dates = datetime(data.date, 'InputFormat', 'dd-MM-yyyy');
data.date = dates;
data.day = day(data.date);
unique_years = unique(data.year);
unique_days = unique(data.day);
% Create a matrix for temperature data
temp_matrix = NaN(length(unique_days), length(unique_years));
% Fill the matrix with temperature values
for i = 1:height(data)
day_index = find(unique_days == data.day(i));
year_index = find(unique_years == data.year(i));
temp_matrix(day_index, year_index) = data.temp_min(i);
end
% Create the contour plot
figure;
contour(unique_years, unique_days, temp_matrix, 'LineColor', 'none');
colorbar;
% Add labels and title
xlabel('Year');
ylabel('Day of June');
title('Contour Plot of Temperature Values (June 1990-2020)');
% Display the plot
grid on;
Hope this solves!Happy coding!!

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by