"hold on" 奇怪的是在 contourf() 之后不起作用

"hold on" strangely doesn't work after contourf()

我试图在当前图的顶部绘制一条垂直线,但出于某种原因,“hold on + plot()”在这种情况下不起作用。怎么做到的?

figure1=figure(4)
axes1 = axes('Parent',figure1,'YScale','log','XScale','log','Layer','top');
grid(axes1,'on');
hold(axes1,'on');
[C,h]=contourf(peaks,[10],'LineColor','none');
clabel(C,h);
hold on %doesn't work
plot([10 10],[0 10],'--k','LineWidth',2) %doesn't work
axis tight;    
axis([1 50 1 50]) 
xlabel('\lambda_x','Fontsize',20);
ylab=ylabel('y^+','Fontsize',20);
grid off
set(ylab, 'Units', 'Normalized', 'Position', [-0.1, 0.5, 0]);
set(gca,'linewidth',1.5,'FontSize',16)
colormap(flipud(gray(256)));
colorbar;

ax2 = axes('Position',axes1.Position,'YScale','log','XScale','log','XAxisLocation','top','YAxisLocation','right','Color','none','YTick',[]);
xla2=xlabel(ax2,'\lambda_x^+','Fontsize',20);
axis(ax2,[1*100 50*100 1*100 50*100]) 
set(ax2,'linewidth',1.5,'FontSize',16)

不是hold on不行。将您的情节线更改为如下内容:

plot([10 10],[1e-10 10],'--k','LineWidth',2)

请注意,0 应以对数刻度绘制在 -inf 处。这有时会导致问题。