MATLAB: How to plot z values against year in x-axis and months in y-axis

contourMATLAB

I have a CSV file with rainfall values of a place. The rainfall values are places with respect to year (rows) and month(columns). See the attached file. I need to plot a contour plot of rainfall values against year and months with years in x-axis and months in y-axis. KINDLY HELP ME OUT. Thanks in advance!

Best Answer

  • try this
    T = readtable('RAINFALL_1980.csv');
    years = T.YEAR;
    months = T.Properties.VariableNames(2:end);
    values = T{:,2:end}';
    y = years;
    m = 1:12;
    [Y,M] = meshgrid(y,m);
    f = figure();
    ax = axes();
    surf(Y,M,values);
    xlim([min(years) max(years)]);
    ylim([1 12]);
    ax.YTickLabel = months(ax.YTick);