Reputation: 1523
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:
But surf gives you this by default:
Upvotes: 8
Views: 4301
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)
figure(1)
pcolor(peaks)
figure(2)
surf(peaks)
view(2)
pcolor
surf
Upvotes: 9
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.
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
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