下面是一个示例代码,演示如何使用legend函数为绘制的曲线添加图示:

% 生成数据 t = 0:0.01:5; y1 = exp(-0.5t).sin(2pit); y2 = exp(-0.2t).cos(3pit);

% 绘制曲线并添加标签 plot(t, y1, 'r', 'LineWidth', 2, 'DisplayName', 'y1(t)'); hold on; plot(t, y2, 'b', 'LineWidth', 2, 'DisplayName', 'y2(t)'); hold off;

% 添加图示 legend('Location', 'northeast', 'FontSize', 12);

运行该代码,会生成一张图形,上面有两条曲线,分别为红色和蓝色,它们的标签分别为y1(t)和y2(t),图示位于图形的右上角,字体大小为12。


原文地址: https://www.cveoy.top/t/topic/dxgu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录