主要是图例的位置参数有错,程序可改为:x = -pi:pi/20:pi;plot(x,cos(x),'-ro',x,sin(x),'-.b')h = legend('cos x','sin x','Location','NW');