Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 368
sciencectn Avatar asked Jun 10 '14 23:06

sciencectn


People also ask

How do you change the view in MATLAB?

To select a preconfigured layout, on the Home tab, in the Environment section, click Layout and select a layout. To restore the MATLAB desktop to its default layout, select Default.

How do I view a figure in MATLAB?

To display values for a data point, drag the cross hairs to a specific point on the figure or move the figure by zooming and panning. The application retrieves the values and displays them.

How do you change the axis of a figure in MATLAB?

Change Axis LimitsCreate a line plot. Specify the axis limits using the xlim and ylim functions. For 3-D plots, use the zlim function. Pass the functions a two-element vector of the form [min max] .


2 Answers

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

like image 109
RTL Avatar answered Sep 28 '22 01:09

RTL


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.

like image 38
rayryeng Avatar answered Sep 28 '22 01:09

rayryeng