How to make vertical stripes line contour plot?

32 views (last 30 days)
Subhodh Sharma on 23 Aug 2021
Commented: Subhodh Sharma on 24 Aug 2021
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.

Adam Danz on 23 Aug 2021
Edited: Adam Danz on 24 Aug 2021
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
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));
figure()
axes()
hold on
h =patch(x, y, vals, 'EdgeColor','none');
% set colormap
nbins = 255;
rgb = [rgb; rot90(rgb(1:floor(nbins/2),:),2)];
colormap(flipud(rgb))
cb = colorbar();
caxis([-3,3])
plot(dt,vals,'ko:','MarkerFaceColor',[.4 .4 .4], 'MarkerSize',4)
axis tight
ylim([-3,3]) Subhodh Sharma on 24 Aug 2021