Generating a filled contour colormap
2 views (last 30 days)
Show older comments
Hello,
Here is my issue. I want to make a countour with filled in level
example: say 5 level That should mean I have 5 color transitions from say Red (hot) to Blue (cold). The data I have is 1200 x 1600 monochrome png file (0-255). Range of the data was (50-125). I'm am able to generate a countour plot that has levels image one, which gave me the countours percent of max. Then I tried to fill in the countours image two and I can't get the fill to work properly. I also tryied the surf function, which gave the 3d surf but I was not able to rotate the data in the figure window to a top down view (plot would not rotate at all). Any help would be useful
Code
Z1 = imread ('\\zfcae\RenderedScene.png');
Z2 = Z1 (1:end,1:end, 1);
B = double(flipud(Z2));
Z = (smoothdata(B));
[X,Y] = meshgrid(1:1600,1:1200);
f1 = figure;
contour (Z, 10);
f2 = figure;
contourf(X,Y,Z,10)
colormap jet
f3 = figure;
h = surf (Z);
set(h,'LineStyle','none')
--- Output in sequence---
0 Comments
Answers (3)
Bjorn Gustavsson
on 4 Jun 2019
Instead of using surf you can use pcolor, then you get the "from-above-view" automatically. You shold have a function for doing exactly what you want: contourf, should be a drop-in replacement of contour - check the help of either to adjust the contour-levels and what-not...
HTH
0 Comments
Michael
on 4 Jun 2019
1 Comment
Bjorn Gustavsson
on 4 Jun 2019
Oh, I missed that you tried contourf. It should be a drop-in replacement. Does the same single-coloured thing happen if you excplicityl command the function to draw contours at specified levels?
contourf(X,Y,Z,[linspace(50,125,7)])
Have you some other function shading the contourf in matlab, what does:
which contourf -all
return?
Pcolor maps the range of your data (Z) to the entire current colourmap. You could mimick
contourf (but will still not get exactly the same result (not the single-coloured version, but the one you want) as contourf) by reducing the numbers of colours in the colormap:
colormap(jet(7)) % or whichever colourmap you choose...
HTH
Michael
on 4 Jun 2019
1 Comment
Bjorn Gustavsson
on 5 Jun 2019
Seems like you've gotten a reasonably working solution - for now. I'm still a good bit curious since contourf should work. That you get an error after contourf -all is no surprice since what I wanted to know is the information about which version of contourf your matlab-session is using at that time, so could you tell us what you get after:
which contourf -all
that will tell us what version is is.
Can you share the troublesome data so that we can test in other versions?
See Also
Categories
Find more on Colormaps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!