How to do this temporal plot

20 ビュー (過去 30 日間)
Elliot Jenkins
Elliot Jenkins 2023 年 1 月 20 日
コメント済み: Chris 2023 年 1 月 27 日
HI,
I have time series data for a parameter for multiple sites like this graph shows. What function do I use? Also, I like making a table of data in excel and then importing it into the script so how is it best to format the table? Thanks

採用された回答

Chris
Chris 2023 年 1 月 20 日
編集済み: Chris 2023 年 1 月 27 日
Here's one way.
For importing data, perhaps something like data=transpose(readmatrix('filename.xlsx',Range','A2:N2002'));
Empty cells should be imported as NaNs then.
% Generate fake data
data = 2*rand(14,120);
for idx = 1:14
data(idx,1:randi(70)) = nan;
end
% Plot it, beginning at year 1901
xx = 1900+[1:size(data,2)];
interestingPlot(xx,data)
function interestingPlot(xx,data)
yy = 1:size(data,1);
f = pcolor(xx,yy,data);
shading flat
colorbar
% Shift the bins
f.XData = f.XData-.5;
f.YData = f.YData-.5;
ax = gca;
% Shift the axes
ax.XLim = ax.XLim-.5;
ax.YLim = ax.YLim-.5;
% Flip the y axis
ax.YDir = 'reverse';
xlabel('Date')
ylabel('Site')
colormap (flipud(hot))
end
  2 件のコメント
Elliot Jenkins
Elliot Jenkins 2023 年 1 月 25 日
Thank you so much!
Chris
Chris 2023 年 1 月 27 日
No problem. I edited the code to turn it into a function, in case you need to generate this kind of plot often.

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by