matlab绘图plot常用设置

目录

图像的大小和位置

一个窗口画多张子图片

保存图片


图像的大小和位置

MATLAB 中设置 Figure 和 Axes 的位置和尺寸 - 知乎 (zhihu.com)https://zhuanlan.zhihu.com/p/446968474示例:

plot(t,y, 'Color', [0,0,1],'Linewidth',1.5);
set(gca,'Position', [.13 .60 .80 .30]);
set(gca,'linewidth',1.2,'fontsize',14,'fontname','Times');
xlim([0 2.5]);
ylim([-0.1 0.1]);
legend({'Heave Position'});
title('Trajectory 1 Heave Motion');
xlabel('Time (s)');
ylabel('Heave(m)');

一个窗口画多张子图片

(25条消息) Matlab如何在一个窗口绘制多张子图_matlab一个窗口画多个图_沉沙丶的博客-CSDN博客https://blog.csdn.net/sy243772901/article/details/115541794(26条消息) Matlab调整子图位置及大小_matlab设置画布大小_Lu_gl的博客-CSDN博客https://blog.csdn.net/Lu_gl/article/details/125875757

示例:

%上图

subplot(2,1,1)
plot(t,y, 'Color', [0,0,1],'Linewidth',1.5);
set(gca,'linewidth',1.2,'fontsize',14,'fontname','Times');
xlim([0 2.5]);
ylim([-0.1 0.1]);
legend({'Heave Position'});
title('Trajectory 1 Heave Motion');
xlabel('Time (s)');
ylabel('Heave(m)');

%下图

subplot(2,1,2)
plot(t,y2 /pi, 'Color', [1,0,0],'Linewidth',1.5);
set(gca,'linewidth',1.2,'fontsize',14,'fontname','Times');
xlim([0 2.5]);
ylim([-0.65 0.25]);
legend({'Pitch angle (nomalized by pi)'});
title('Trajectory 2 Pitch Motion');
xlabel('Time (s)');
ylabel('Angle');

保存图片

print函数

使用plot函数后紧接着用print函数来保存图像。print的格式为: print(figure_handle,fileformat,filename),其中的三个参数:

(1)figure_handle:图形句柄,如果图形窗口标题栏是“Figure 3”,则句柄就是3;也可以直接用gcf获取当前窗口句柄

(2)fileformat:单引号字符串,指定存储格式:

png格式: ‘-dpng’

jpeg格式: ‘-djpeg’,

tiff格式: ‘-dtiff’

bmp格式: ‘-dbitmap’

gif格式:’-dgif’

emf无损格式:’-dmeta’

(3)filename:'文件名'

批量保存图片示例:

name=['轨迹1_',num2str(k)];
print(gcf,'-dpng',name);

  • 19
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MATLAB设置图例可以使用legend函数。可以在legend函数中指定需要显示的线条和对应的标签。以下是一个示例代码: ```matlab x = 1:10; y1 = x.^2; y2 = x.^3; plot(x, y1, 'r', 'LineWidth', 2); hold on; plot(x, y2, 'b', 'LineWidth', 2); legend('y = x^2', 'y = x^3', 'FontSize', 12, 'Location', 'northwest'); ``` 在这个示例中,我们使用plot函数绘制了两条曲线,并使用legend函数设置了图例。legend函数的输入参数是一个字符数组,包含了每条曲线对应的标签。我们还可以通过设置'FontSize'和'Location'参数来调整图例的字体大小和位置。 另外,如果想要在图例中显示更多的信息,可以使用多列的方式设置图例。例如: ```matlab x = 1:10; y1 = x.^2; y2 = x.^3; plot(x, y1, 'r', 'LineWidth', 2); hold on; plot(x, y2, 'b', 'LineWidth', 2); legend({'y = x^2', 'y = x^3'; 'red line', 'blue line'}, 'FontSize', 12, 'Location', 'northwest'); ``` 在这个示例中,我们将图例的标签和额外的信息用一个cell数组包裹起来,并使用多行来设置图例的显示。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [MATLAB Plot Gallery - Line Plot 2D(二):用图例创建线图-matlab开发](https://download.csdn.net/download/weixin_38685793/19195105)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Matlab绘图设置任意位置的图例,多个图例设置](https://blog.csdn.net/weixin_44231148/article/details/126619418)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值