MATLAB Answers

How to make vertical stripes line contour plot?

9 次查看(过去 30 天)
Hello everyone,
I have a one dimensional monthly data for 5 years (i.e, 60 points). The data are varying in range between -3 to +3. I want to make a contour plot
of vertical striped lines each of same width corresponding to the value of the each data points.
To clarify more---
in X axis-------there are months.
in Y axis--- Vertical stripe lines of same width and height (may be 4 units). The vertical colour lines intensity shouldd be representing the data value.
first line==(same colour thorught the height). (if data has positive value in this point )
second line==(same color different intensity) (if data has positive value in this point )
So the plot must show the colorbar too.
Any sort of help would be really great.
Thanking you in advance.

采纳的回答

Adam Danz
Adam Danz 2021-8-23
编辑:Adam Danz 2021-8-24
dt = datetime(01,01,2000) + calmonths(0:59); % row vector
vals = rand(size(dt))*6-3; % vector (row or col)
plot(dt,vals,'ks')
hold on
dateInt = diff(dt);
dateInt = dateInt([1:end, end])/2;
x = dt + dateInt.*[-1;-1;1;1];
[ymin,ymax] = bounds(vals);
y = repmat([ymin;ymax;ymax;ymin],1,numel(vals));
cvals = 3*ones(numel(vals),1).*-(vals(:)<0);
yline(0)
hold on
patch(x, y, cvals, 'FaceAlpha', 0.25, 'EdgeColor','none')
colormap([0 0 1; 1 0 0])
cb = colorbar();
caxis([-3,3])
Alpha scaled to y-values
See "fadescale" to scale the fade.
figure()
dt = datetime(01,01,2000) + calmonths(0:59); % row vector
vals = rand(size(dt))*6-3; % vector (row or col)
vals = sin(linspace(-pi,pi,numel(dt)))*2 + rand(1,numel(dt))*2-1;
% Compute patch verts
dateInt = diff(dt);
dateInt = dateInt([1:end, end])/2;
x = dt + dateInt.*[-1;-1;1;1];
[ymin,ymax] = bounds(vals);
y = repmat([ymin;ymax;ymax;ymin],1,numel(vals));
% Plot, start with underlying patches
figure()
axes()
hold on
h =patch(x, y, vals, 'EdgeColor','none');
% set colormap
nbins = 255;
fadescale = 0.7; % higher is more faded (0:1)
rgb = [ones(ceil(nbins/2),1),linspace(fadescale,1,ceil(nbins/2))' .* [1,1]];
rgb = [rgb; rot90(rgb(1:floor(nbins/2),:),2)];
colormap(flipud(rgb))
cb = colorbar();
caxis([-3,3])
% Add data
plot(dt,vals,'ko:','MarkerFaceColor',[.4 .4 .4], 'MarkerSize',4)
axis tight
ylim([-3,3])
  11 个评论

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by