Using a colormap to match a contour to a histogram
Mostrar comentarios más antiguos
I am regenerating cscan TOF data ( contourf(xscale, yscale, cscan, 40,'linestyle','--') ) and I would am trying to display a histogram of the data such that the bar colors will be the same a shown in the histogram (say red in the contour = 400 ns would have the histogram bar at 400 also be red). Is there an easy way to assign the bars using the colormap?
Respuesta aceptada
Más respuestas (1)
Jess Lovering
el 3 de Oct. de 2019
Editada: Jess Lovering
el 3 de Oct. de 2019
Here is an example of what I think you are trying to do. It doesn't calculate the bar values for the contours - I assume you have an associated value for each contour already available. Please let me know if this example is what you are looking for.
figure
subplot(2,1,1)
Z = peaks;
[M c]=contour(Z);
cmap = colormap;
crange = caxis;
cmin = crange(1);
cmax = crange(2);
m = length(cmap);
subplot(2,1,2)
hold on
contour_levels = -6:8;
bar_vals = rand(1,length(contour_levels)); % I assume you have these calculated
for ii = 1:length(contour_levels)
contour_i = contour_levels(ii);
cp = (contour_i-cmin)/(cmax-cmin);
ci = round((length(cmap)-1)*cp)+1;
color(ii,1:3) = cmap(ci,:);
bh = bar(contour_levels(ii),bar_vals(ii))
bh.FaceColor = cmap(ci,:);
end
Categorías
Más información sobre Contour Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!