最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

matplotlib quiver箭圖繪制案例

 更新時間:2020年04月17日 10:41:23   作者:落葉_小唱  
這篇文章主要介紹了matplotlib quiver箭圖繪制案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

quiver繪制表示梯度變化非常有用,下面是學(xué)習(xí)過程中給出的兩個例子,可以很好理解quiver的用法

from pylab import *
close()

## example 1

x = linspace(0,10,40)
y = x**2*exp(-x)

u = array([x[i+1]-x[i] for i in range(len(x)-1)])
v = array([y[i+1]-y[i] for i in range(len(x)-1)])

x = x[:len(u)] # 使得維數(shù)和u,v一致
y = y[:len(v)]

c = randn(len(u)) # arrow顏色

figure()
quiver(x,y,u,v,c, angles='xy', scale_units='xy', scale=1) # 注意參數(shù)的賦值

## example 2

x = linspace(0,20,30)
y = sin(x)

u = array([x[i+1]-x[i] for i in range(len(x)-1)])
v = array([y[i+1]-y[i] for i in range(len(x)-1)])

x = x[:len(u)] # 使得維數(shù)和u,v一致
y = y[:len(v)]

c = randn(len(u)) # arrow顏色

figure()
quiver(x,y,u,v,c, angles='xy', scale_units='xy', scale=1) # 注意參數(shù)的賦值
show()

結(jié)果如下:

補充知識:Matlab矢量圖圖例函數(shù)quiverkey

Matlab自帶函數(shù)中不包含構(gòu)造 quiver 函數(shù)注釋過程,本文參照 matplotlib 中 quiverkey 函數(shù),構(gòu)造類似函數(shù)為 Matlab 中 quiver 矢量場進行標(biāo)注。

quiverkey函數(shù)

首先看 matplotlib 中 quiverkey 如何定義的

quiverkey(*args, **kw)
Add a key to a quiver plot.
 
Call signature::
 
 quiverkey(Q, X, Y, U, label, **kw)
 
Arguments:
 
 *Q*:
 The Quiver instance returned by a call to quiver.
 
 *X*, *Y*:
 The location of the key; additional explanation follows.
 
 *U*:
 The length of the key
 
 *label*:
 A string with the length and units of the key
 
Keyword arguments:
 
 *coordinates* = [ 'axes' | 'figure' | 'data' | 'inches' ]
 Coordinate system and units for *X*, *Y*: 'axes' and 'figure' are
 normalized coordinate systems with 0,0 in the lower left and 1,1
 in the upper right; 'data' are the axes data coordinates (used for
 the locations of the vectors in the quiver plot itself); 'inches'
 is position in the figure in inches, with 0,0 at the lower left
 corner.
 
 *color*:
 overrides face and edge colors from *Q*.
 
 *labelpos* = [ 'N' | 'S' | 'E' | 'W' ]
 Position the label above, below, to the right, to the left of the
 arrow, respectively.
 
 *labelsep*:
 Distance in inches between the arrow and the label. Default is
 0.1
 
 *labelcolor*:
 defaults to default :class:`~matplotlib.text.Text` color.
 
 *fontproperties*:
 A dictionary with keyword arguments accepted by the
 :class:`~matplotlib.font_manager.FontProperties` initializer:
 *family*, *style*, *variant*, *size*, *weight*
 
Any additional keyword arguments are used to override vector
properties taken from *Q*.
 
The positioning of the key depends on *X*, *Y*, *coordinates*, and
*labelpos*. If *labelpos* is 'N' or 'S', *X*, *Y* give the position
of the middle of the key arrow. If *labelpos* is 'E', *X*, *Y*
positions the head, and if *labelpos* is 'W', *X*, *Y* positions the
tail; in either of these two cases, *X*, *Y* is somewhere in the
middle of the arrow+label key object.
 
 
Additional kwargs: hold = [True|False] overrides default hold state

可以看到主要參數(shù)有這么些個

quiver繪圖指針

圖例位置 X, Y

標(biāo)注大小 U

標(biāo)注單位字符

其他參數(shù)

1). 輸入坐標(biāo) X, Y 單位
2). (文字)標(biāo)注在圖例哪個位置
3). 標(biāo)注與圖例相對距離
4). 標(biāo)注字體顏色

使用方法:

對應(yīng)Matlab函數(shù)也應(yīng)該使用這么個流程

使用quiver繪圖

將quiver返回指針與圖例位置坐標(biāo)和大小等作為參數(shù)傳入

示例

[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;

figure; 
Qh = quiver(x,y,u,v);

quiverkey(Qh, 0.5, 2.5, 1, 'm/s', 'Color', 'r', 'Coordinates', 'data')

最終效果圖

代碼

function Q = quiverkey(Q, X, Y, U, label, varargin)
%QUIVERKEY legend for quiver
%
% QUIVERKEY(Q, X, Y, U, label) 
% 
% Arguments:
%  Q :  The quiver handle returned by a call to quiver
%  X,Y : The location of the legend
%  U :  The unit length. If U<0, the arrow will be reversed
%  label : The string with the length and units of the key
% 
% Addition arguments:
%  Coordinates = [ 'axes' | 'data'(default) ]
% 
%   'axes' & 'figure' : 'axes' and 'figure' are normalized 
%      coordinate systems with 0,0 in the lower left 
%      and 1,1 in the upper right;
%   'data' : use the axes data coordinates
% 
%  LabelDistance : Distance in 'coordinates' between the arrow and the
%     label. Deauft is 0.1 (units 'axes').
% 
%  Color : overrides face and edge colors from Q.
% 
%  LabelPosition = [ 'N' | 'S'(default) | 'E' | 'W' ]
% 
%    Position the label above, below, to the right, 
%    to the left of the arrow, respectively.
% 
%  LabelColor : defaults to black
%  
% Examples: 
% 
% [x,y] = meshgrid(0:0.2:2,0:0.2:2);
% u = cos(x).*y;
% v = sin(x).*y;
% figure; Qh = quiver(x,y,u,v);
% quiverkey(Qh, 0.5, 2.5, 1, 'm/s', 'Color', 'r', 'Coordinates', 'data')
% 
% Author:
% li12242 - Department of Civil Engineering in Tianjin University
% Email:
% li12242@tju.edu.cn
% 

%% get input argument
if nargin < 5 
 error('Input arguments" Number incorrect!')
end

if isempty(varargin) && mod(length(varargin), 2) ~= 0
 error('Input arguments donot pairs!')
else
 [CoorUnit, LabelDist, Color, LabelPosition, LabelColor] = getInput(varargin);
end


%% add legend arrow

% get original data
xData = get(Q, 'XData'); yData = get(Q, 'YData');
uData = get(Q, 'UData'); vData = get(Q, 'VData');

% get axes properties
haxes = get(Q, 'Parent');
xLim = get(haxes, 'XLim'); yLim = get(haxes, 'YLim');
NextPlot = get(haxes, 'NextPlot');

% set axes properties
set(haxes, 'NextPlot', 'add')

if strcmp(CoorUnit, 'axes')
 % position of legend arrow
 xa = xLim(1) + X*(xLim(2) - xLim(1));
 ya = yLim(1) + Y*(yLim(2) - yLim(1));
else
 xa = X; ya = Y;
end

% add legend arrow into data vector
xData = [xData(:); xa]; yData = [yData(:); ya];
uData = [uData(:); U]; vData = [vData(:); 0];

% reset data
set(Q, 'XData', xData, 'YData', yData, 'UData', uData, 'VData', vData);
set(Q, 'Color', Color)

%% add text
dx = LabelDist*(xLim(2) - xLim(1));
dy = LabelDist*(yLim(2) - yLim(1));

% set position of label
switch LabelPosition
 case 'N'
  xl = xa; yl = ya + dy;
 case 'S'
  xl = xa; yl = ya - dy;
 case 'E'
  xl = xa + dx; yl = ya;
 case 'W'
  xl = xa - dx; yl = ya;
end% switch

th = text(xl, yl, [num2str(U), ' ', label]);
set(th, 'Color', LabelColor);

% turn axes properties to original
set(haxes, 'NextPlot', NextPlot)

end% func

%% sub function

function [CoorUnit, LabelDist, Color, LabelPosition, LabelColor] = getInput(varcell)
% Input:
% varcell - cell variable
% Output:
% 
nargin = numel(varcell);

%% set default arguments

CoorUnit = 'data';
LabelDist = 0.05; % units 'axes'
Color = 'k';
LabelPosition = 'S';
LabelColor = 'k';

%% get input arguments
contour = 1;
while contour < nargin
 switch varcell{contour}
  case 'Coordinates'
   CoorUnit = varcell{contour+ 1};
  case 'LabelDistance'
   LabelDist = varcell{contour+ 1};
  case 'Color'
   Color = varcell{contour+ 1};
  case 'LabelPosition'
   LabelPosition = varcell{contour+ 1};
  case 'LabelColor'
   LabelColor = varcell{contour+ 1};
  otherwise
   error('Unknown input argument.')
 end% switch
 contour = contour + 2;
end% while

end% fun

以上這篇matplotlib quiver箭圖繪制案例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • No module named ‘win32gui‘ 的解決方法(踩坑之旅)

    No module named ‘win32gui‘ 的解決方法(踩坑之旅)

    這篇文章主要介紹了No module named ‘win32gui‘ 的解決方法(踩坑之旅),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • Django日志及中間件模塊應(yīng)用案例

    Django日志及中間件模塊應(yīng)用案例

    這篇文章主要介紹了Django日志及中間件模塊應(yīng)用案例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-09-09
  • 使用python在本地電腦上快速處理數(shù)據(jù)

    使用python在本地電腦上快速處理數(shù)據(jù)

    這篇文章主要介紹了使用python在本地電腦上快速處理數(shù)據(jù)的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • Python批量生成幻影坦克圖片實例代碼

    Python批量生成幻影坦克圖片實例代碼

    這篇文章主要給大家介紹了關(guān)于如何利用Python批量生成幻影坦克圖片的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用Python具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • Python函數(shù)中apply、map、applymap的區(qū)別

    Python函數(shù)中apply、map、applymap的區(qū)別

    這篇文章主要介紹了 Python函數(shù)中apply、map、applymap的區(qū)別 ,文章圍繞 Python函數(shù)中apply、map、applymap的相關(guān)資料展開詳細內(nèi)容,需要的朋友可以參考一下
    2021-11-11
  • Django為窗體加上防機器人的驗證碼功能過程解析

    Django為窗體加上防機器人的驗證碼功能過程解析

    這篇文章主要介紹了Django為窗體加上防機器人的驗證碼功能過程解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-08-08
  • Python函數(shù)參數(shù)定義及傳遞方式解析

    Python函數(shù)參數(shù)定義及傳遞方式解析

    這篇文章主要介紹了Python函數(shù)參數(shù)定義及傳遞方式解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-06-06
  • python自動計算圖像數(shù)據(jù)集的RGB均值

    python自動計算圖像數(shù)據(jù)集的RGB均值

    這篇文章主要為大家詳細介紹了python自動計算圖像數(shù)據(jù)集的RGB均值,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • 超詳細注釋之OpenCV更改像素與修改圖像通道

    超詳細注釋之OpenCV更改像素與修改圖像通道

    這篇文章主要介紹了OpenCV更改像素與修改圖像通道,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-09-09
  • 使用Python解析JSON的實現(xiàn)示例

    使用Python解析JSON的實現(xiàn)示例

    本文主要介紹了使用Python解析JSON的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-12-12

最新評論

宁海县| 洞头县| 荣昌县| 饶阳县| 迁安市| 旅游| 德州市| 武山县| 措美县| 扶余县| 瑞昌市| 嘉黎县| 延安市| 四川省| 旺苍县| 郑州市| 沅陵县| 宜黄县| 临湘市| 万源市| 阿合奇县| 六安市| 贺兰县| 醴陵市| 稷山县| 水城县| 赞皇县| 漠河县| 高清| 济宁市| 孟连| 江川县| 长子县| 平江县| 临城县| 保山市| 景东| 班戈县| 泸西县| 牟定县| 那坡县|