How to make vertical stripes line contour plot?

8 visualizaciones (últimos 30 días)
Subhodh Sharma
Subhodh Sharma el 23 de Ag. de 2021
Comentada: Subhodh Sharma el 24 de Ag. de 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.
Thanking you in advance.

Respuesta aceptada

Adam Danz
Adam Danz el 23 de Ag. de 2021
Editada: Adam Danz el 24 de Ag. de 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
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 comentarios
Adam Danz
Adam Danz el 24 de Ag. de 2021
By overlay line do you mean the gray line in my example?
What specific problems are you having? An error? Line not appearing?
Are you plotting the stripes first and then adding the line? If you're plotting the line first, it's under the stripes so you can't see it.
Subhodh Sharma
Subhodh Sharma el 24 de Ag. de 2021
@Adam Danz Thanks. worked

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by