Colorbar not plotting the right colours

I'm having trouble using the colorbar/colormap functions. I create a test plot, plotting a bar graph from 0,0 to 100,100 and created a color bar. I would like the color bar to correspond to the y values of the graph. Which means, if looking at the xaxis, the graph would be colored in the same order as the colorbar from 0->100 by matching the y-values to the colorbar values.
It seems to be plotting the value 0 corresponding to the colorbar which is purple/black every time which I believe is the z-value. Mainly see colorbar/maps used for contour plots but I would like it to work for a 2D plot.

답변 (2개)

Image Analyst
Image Analyst 2016년 10월 31일
편집: Image Analyst 2016년 10월 31일

1 개 추천

Consider creating an indexed image instead of a bar chart. Then you can write each bar as a column with the gray level of the color you want. Apply the colormap and that column of pixels will show up in the desired color.
If you want a color gradient in each bar, then that is more complicated - you'd have to write a ramp of pixel levels rather than a constant pixel level that corresponds to the tallest color.
rows = 100;
columns = 100;
indexedImage = zeros(rows, columns, 'uint8');
for col = 1 : 100
row1 = rows-col+1
indexedImage(row1:rows, col) = col;
end
imshow(indexedImage);
colormap(gca, jet(rows));
caxis([0, rows]);
colorbar;
Modify as needed.
Marc Jakobi
Marc Jakobi 2016년 10월 31일

0 개 추천

You cannot create a colorbar for bar() graphs in Matlab. What you can do is use a loop to create a separate bar graph for each color.
See this answer for an example.

댓글 수: 2

Raymond Hoang
Raymond Hoang 2016년 10월 31일
편집: Walter Roberson 2016년 10월 31일
I'm not sure how to incorporate that answer with what I'm trying to do.
I have a function that is constantly outputting a value "y" but not putting it into a matrix form.
figure(1)
hold on
ylabel 'Temperature (Degrees)'
title 'Live Temperature Plot'
i = 0;
while true
[t] = ReadData(out)
figure(1)
if(i <= 100)
xlim([0,200]);ylim([0,100])
else
xlim([i-200, i]);ylim([0,100])
end
tempplot = bar(i,tc,'BarWidth',1);
i = i + 1;
pause(0.05)
end
See this link at 6:50
Image Analyst
Image Analyst 2016년 10월 31일
I'll show you. See my attached demo.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Color and Styling에 대해 자세히 알아보기

질문:

2016년 10월 30일

댓글:

2016년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by