我应该怎么做才能不显示所有图例的图例? [英] What should I do to not show the legend for all the plots?

查看:152
本文介绍了我应该怎么做才能不显示所有图例的图例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

N=100;
n=50;
tau=0.001;
h=0.01;
lambda=tau/h;
mu=lambda/2;
u=zeros(N,n);
u1=zeros(N,n);
u2=zeros(N,n);
phi=zeros(n,1);
for i=1:n
    for j=1:N
        u(j,i)=cos(2*pi*i*(j-1)*h);
        u1(j,i)=cos(2*pi*i*((j-1)*h-tau));
    end

    for j=2:N
        u2(j,i)=u(j,i)-lambda*(u(j,i)-u(j-1,i));
    end
u2(1)=0;
phi(i,1)=2*pi*i/N;    
end
uf=zeros(n,1);
uf1=zeros(n,1);
uf2=zeros(n,1);

for i=1:n
   for j=1:N
       uf(i,1)=uf(i,1)+(u(j,i)*exp(-1i*(j-1)*phi(i,1)))/100;
       uf1(i,1)=uf1(i,1)+u1(j,i)*exp(-1i*j*phi(i,1))/100;
       uf2(i,1)=uf2(i,1)+(u2(j,i)*exp(-1i*(j-1)*phi(i,1)))/100;
   end
end
final=zeros(n,1);
for i=1:n
    final(i,1)=-(h/(1i*tau))*(log(uf2(i)/uf(i)));
end


figure;
hold on 
z=1:1:n;
b = real(final(z,1));
%plot(phi(z,1),b,'o');
c = imag(final(z,1));
%plot(phi(z,1),c,'-');
%plot(phi(z,1),0,'-');
plot(phi(z,1),b,'ro',phi(z,1),c,'ko',phi(z,1),0,'k-');
legend('Real','Imaginary');
legend ('Location','NorthWest');
xlabel('Reduced Wavenumber')
ylabel('Modified Wavenumber')

我正在y = 0处绘制一条线以供参考.我不希望他们出现在传说中.但是我得到这个数字: 我该如何解决?

I am plotting a line at y=0 for reference. I do not want them in legend. But I am getting this figure: How do I resolve this?

推荐答案

不是使用一个plot-命令绘制所有内容,而是这样做:

Instead of plotting everything with one plot-command, do it like this:

plot(phi(z,1),b,'ro'); hold on
plot(phi(z,1),c,'ro'); hold on
plot(phi(z,1),0,'k-'); hold off

legend('Real','Imaginary','Location','NorthWest');
xlabel('Reduced Wavenumber')
ylabel('Modified Wavenumber')

那您应该不会有问题.

实际原因是,在这种情况下,图例的调用方式有所不同.更加优雅的解决方案提供了 Magla的答案.

The actual reason is, that the legend is called differently in this case. The more elegant solution offers the answer of Magla.

这篇关于我应该怎么做才能不显示所有图例的图例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆