How can I place a quiver plot on top of a surface plot?

3 次查看(过去 30 天)
When I place a quiver plot on a 2-D surface plot (pcolor), resizing or printing the figure window causes the quiver plot to disappear. I would like to place a quiver plot on top of a surface plot.

采纳的回答

MathWorks Support Team
The quiver plot disappears because both the surface plot and quiver plot are located in the XY-plane (Z = 0) and the renderer is set to 'painters'. You can avoid this issue by changing the renderer as follows:
set(gcf, 'renderer', 'zbuffer')
If you would like to keep the renderer to 'painters', you can place the surface plot at a -Z offset. For example:
xord = -2:.2:2;
yord = -2:.2:2;
[x,y] = meshgrid(xord,yord);
z = x .* exp(-x.^2 - y.^2);
[px,py] = gradient(z,.2,.2);
quiver(x,y,px,py)
hold on
h = pcolor(x,y,z);
set(h,'ZData',-1+zeros(size(z))) % Move the surface plot to Z = -1
colormap(gray)
shading interp

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

标签

尚未输入任何标签。

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by