Matlab如何绘制带箭头图形

带箭头坐标轴

前段时间推出了绘制箭头坐标轴曲线的方法,许多网友联系我索取了源程序,绘制出漂亮的图形,得到大家好评。
链接:如何使用Matlab绘制箭头坐标轴曲线
在这里插入图片描述

带箭头曲线

但是有些时候我们不光要求坐标轴是箭头形式,还要求图形上有箭头标记,前段时间绘制Nyquist图,需要在Nyquist曲线上用箭头标记频率方向,在网上几经搜寻,终于在Matlab中文论坛上找到了解决方案,绘制出的Nyquist图如下所示。
当然,arrowPlot.m还可以和箭头坐标轴结合起来,绘制出更加“高端”的曲线。
在这里插入图片描述
解决方案是:Matlab中文论坛网友TimeCoder编写的arrowPlot.m函数。
arrowPlot.m函数的调用格式简单、使用方便。

function H = arrowPlot(X, Y, varargin)
%ARROWPLOT Plot with arrow on the curve.
%   ARROWPLOT(X, Y) plots X, Y vectors with 2 arrows directing the trend of data.
%
%   You can use some options to edit the properties of arrow or curve.
%   The options that you can change are as follow:
%       number:		The number of arrows, default number is 2;
%       color:		The color of arrows and curve, default color is [0, 0.447, 0.741];
%       LineWidth:	The line width of curve, default LineWidth is 0.5;
%       scale:		To scale the size of arrows, default scale is 1;
%       limit:		The range to plot, default limit is determined by X, Y data;
%       ratio:		The ratio of X-axis and Y-axis, default ratio is determined by X, Y data;
%             		You can use 'equal' for 'ratio', that means 'ratio' value is [1, 1, 1].
%
%   Example 1:
%   ---------
%      t = [0:0.01:20];
%      x = t.*cos(t);
%      y = t.*sin(t);
%      arrowPlot(x, y, 'number', 3)
%
%   Example 2:
%   ---------
%      t = [0:0.01:20];
%      x = t.*cos(t);
%      y = t.*sin(t);
%      arrowPlot(x, y, 'number', 5, 'color', 'r', 'LineWidth', 1, 'scale', 0.8, 'ratio', 'equal')
%   Copyright 2017 TimeCoder.

实例演示

例1 带箭头曲线

% 绘制带箭头图形
t = [0:0.01:20];
x = t.*cos(t);    
y = t.*sin(t);
arrowPlot(x, y, 'number', 3)   % 'number', 3 表示曲线上均匀分布3个箭头标识

在这里插入图片描述

% 绘制带箭头图形
t = [0:0.01:10];
x = cos(t);
arrowPlot(t, x, 'number', 6)

在这里插入图片描述

例2 带箭头曲线+带箭头坐标轴

当然,arrowPlot.m还可以和箭头坐标轴结合起来,绘制出更加“高端”的曲线。

% 绘制带箭头图形 + 箭头坐标轴
plot_with_arrow();     % 使用plot_with_arrow绘制箭头坐标轴
hold on
t = [0:0.01:20];
x = t.*cos(t);
y = t.*sin(t);
arrowPlot(x, y, 'number', 5, 'color', 'r', 'LineWidth', 1, 'scale', 0.8, 'ratio', 'equal');
Arrow_Xlabel([],'X/m','pp');    % x轴标签
Arrow_Ylabel([],'Y/m','pp');    % y轴标签

在这里插入图片描述

% 绘制带箭头图形 + 箭头坐标轴
plot_with_arrow();     % 使用plot_with_arrow绘制箭头坐标轴
hold on
t = [0:0.01:20];
x = t.*cos(t);
y = t.*sin(t);
arrowPlot(x, y, 'number', 5, 'color', 'r', 'LineWidth', 1, 'scale', 0.8, 'ratio', 'equal');
Arrow_Xlabel([],'X/m','pp');    % x轴标签
Arrow_Ylabel([],'Y/m','pp');    % y轴标签

在这里插入图片描述

% 绘制带箭头图形 + 箭头坐标轴
plot_with_arrow([],[],[],[],'aa');     % 使用plot_with_arrow绘制箭头坐标轴
hold on
t = linspace(0,2*pi,600);
x = cos(t);
y = sin(t);
plot(x,y,'r')       % 绘制直径1圆
plot(3*x,3*y,'r')   % 绘制直径3圆
ind = 25 + 0:100:600;
for ii = 1:length(ind)   % 循环绘制斜线
    hold on
    arrowPlot([3*x(ind(ii)) x(ind(ii))], [3*y(ind(ii)) y(ind(ii))], 'number', 2, 'color', 'r');
end
axis equal

在这里插入图片描述

联系作者

arrowPlot.m函数版权归网友TimeCoder所有,由于程序链接已遗失,有需要源程序的朋友可以联系我。
有Matlab/Simulink方面的技术问题,欢迎发送邮件至944077462@qq.com讨论。
更多Matlab/Simulink原创资料,欢迎关注微信公众号:Matlab Fans

源程序下载:
1. csdn资源: Matlab如何绘制带箭头图形
2. 扫码关注微信公众号Matlab Fans,回复BK04获取百度网盘下载链接。

在这里插入图片描述

  • 7
    点赞
  • 71
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MatlabFans_Mfun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值