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

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by