sciencectn
sciencectn

Reputation: 1523

Change figure view in matlab

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

Upvotes: 8

Views: 4301

Answers (3)

RTL
RTL

Reputation: 3587

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

Upvotes: 9

rayryeng
rayryeng

Reputation: 104493

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.

Upvotes: 9

Fantastic Mr Fox
Fantastic Mr Fox

Reputation: 33864

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])

Upvotes: 5

Related Questions