Change shape view in Matlab

Is there a way to use the surf() style data format to create a heat map?

I have a bunch of scattered data of the form z=f(x,y) (so I used TriScatteredInterp to work with a meshgrid ) and I would like to visualize z with a heat map. surf already doing something similar to what I want, except that you need to manually rotate the graph to look down from top to bottom looking at the XY plane.

Basically, I would like something similar to this: Heat maps

But surfing gives you this by default: enter image description here

+7
matlab matlab-figure
source share
3 answers

Although the answers here already show how to do this using surfing, rendering a 3D surface is a bit like overkill ...

pcolor creates the necessary images directly

(with slightly better results - surf has a gap next to the axes)

the code

 figure(1) pcolor(peaks) figure(2) surf(peaks) view(2) 

results


pcolor pcolor Result


surf surf result

+8
source share

By adding Ben to your answer, you can use the view command. view allows you to rotate the plot to any angle of the camera that you want.

In general, you invoke the command as follows:

 view(AZ, EL); 

AZ is azimuthal or horizontal rotation, and EL is vertical elevation. They are both in degrees.

In your case, as soon as you plot the surf graph, use view(0, 90); before moving on to the next subplot . view(0, 90); is a standard two-dimensional view, and it looks right above your head.


In doing so, you avoid manually turning the graph, then using campos to determine which camera position is in your area. view(0, 90); should provide you with what you need.

Sidenote

Execution of view(2); also gives a default 2D view(0, 90); equal to view(0, 90); that we talked about. Performing view(3); , you will get a default 3D view, as shown in your graphs. FWIW, the default azimuth and altitude for the 3D plot is AZ = -37.5, EL = 30 , in degrees, of course.

+7
source share

Rotate the view the way you want. Then enter campos into the terminal. This will show you the position of the camera. Then you can use campos( your_desired ) to set the camera position for future scenes.

For example, the representation of x, y usually:

 campos([4.0000 2.5000 86.6025]) 
+4
source share

All Articles