Change figure view in matlab
Asked Answered
E

3

8

Is there some way of using 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 make it work with meshgrid) and I'd like to visualize z with a heat map. surf already does something similar to what I want, except you have to manually rotate the graph so the view is top down looking at the XY plane.

Basically, I'd like something similar to this: Heat maps

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

Episternum answered 10/6, 2014 at 23:58 Comment(0)
A
9

Although the answers here already show how to do this with surf, rendering the 3d surface feels a little like overkill...

pcolor creates the required images directly

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

code

figure(1)
pcolor(peaks)

figure(2)
surf(peaks)
view(2)

results


pcolor pcolor Result


surf surf Result

Ardene answered 11/6, 2014 at 11:51 Comment(1)
Wow pcolor. Didn't know about that function. Thanks!Stockist
S
9

Adding to Ben's answer, you can use the view command. view allows you to rotate your plot to whatever camera angle you wish.

In general, you call the command like so:

view(AZ, EL);

AZ is the azimuth or horizontal rotation, while EL is the vertical elevation. These are both in degrees.

In your case, once you plot your surf plot, use view(0, 90); before you go to the next subplot. view(0, 90); is the default 2-D view, and this looks directly overhead.


By doing this, you avoid having to rotate your plot manually, then using campos to determine what the camera position is at given your plot. view(0, 90); should give you what you need.

Sidenote

Doing view(2); also gives you the default 2D view, which is equal to view(0, 90); as we talked about. By doing view(3);, this gives you the default 3D view as seen in your plots. FWIW, the default azimuth and elevation for a 3D plot is AZ = -37.5, EL = 30, in degrees of course.

Stockist answered 11/6, 2014 at 0:29 Comment(0)
A
9

Although the answers here already show how to do this with surf, rendering the 3d surface feels a little like overkill...

pcolor creates the required images directly

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

code

figure(1)
pcolor(peaks)

figure(2)
surf(peaks)
view(2)

results


pcolor pcolor Result


surf surf Result

Ardene answered 11/6, 2014 at 11:51 Comment(1)
Wow pcolor. Didn't know about that function. Thanks!Stockist
C
5

Rotate the view to what you want. Then type campos in the terminal. This shows you the camera position. You can then use campos( your_desired ) to set the camera position for future plots.

For example, the x, y view is usually:

campos([4.0000    2.5000   86.6025])
Chair answered 11/6, 2014 at 0:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.