필터 지우기
필터 지우기

How to plot monthly values of precipitation over multiple years and have years plotted on x-axis

조회 수: 1 (최근 30일)
I have a table with headings of year, month, and value where the value is the total precipitation of the month. I would like to make a bar chart that has the year plotted on the x-axis, but I'd also like to color-code each year's worth of data (12 bars, one for each month) to make it clear where one year starts and another ends. How do I do this?

채택된 답변

Thomas Burbey
Thomas Burbey 2017년 11월 1일
How do I reshape my array that is in the form (year, month, data value): 1991, 1, 45.2 1991, 2, 84.3 1991, 3, 23.3 1991, 4, 97.1 ... 2016, 12, 17.4 Into the form jan feb mar apr may .... dec 1991 45.2 84.3 23.3 97.4 .... ... 2016 .... 17.4

추가 답변 (1개)

KL
KL 2017년 11월 1일
reshape your data by keeping year on the rows, months on columns (hence, 12 columns and as many rows as many years you have), then you can simply call bar and add legend as your table variable names.
h = bar([yourtable.year; yourtable.year2]);
legend(h,yourTable.Properties.VariableNames);
  댓글 수: 2
Thomas Burbey
Thomas Burbey 2017년 11월 1일
Okay, but I'm uncertain how to reshape the array to get my values in the table with years for rows and months as columns.
KL
KL 2017년 11월 1일
if you have an array in the form,
array = [year, month, value];
then,
val = reshape(array(:,3),12,[])';

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by