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:
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.
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.
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] .
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With