如何使用 'latex arrow symbol' 在图形中创建对角线箭头?
How to create diagonal arrow in a figure using 'latex arrow symbol'?
我想在从矩阵读取的图形中显示特定单元格的方向。
在附图中,我可以创建左方向箭头,但我不知道如何在西南方向插入对角线箭头。
显然,latex arrow symbol 对左箭头、右箭头、上箭头和下箭头工作正常,但对角箭头无效。
在附图中,我需要通过青色单元在西南方向插入箭头。如何做到这一点?
这是我正在尝试的脚本,
for row=1:size(data,1)
for col=1:size(data,2);
if data(row,col)==1
rectangle('Position',[col-0.5 row 1 1], 'FaceColor','y','EdgeColor','k', 'LineWidth', 0.1)
text(col-0.95,row+0.6,'\leftarrow', 'fontsize', 6);
elseif data(row,col)==2
rectangle('Position',[col-0.5 row 1 1], 'FaceColor','c','EdgeColor','k', 'LineWidth', 0.1)
text(col-0.95,row+0.6,'\swarrow', 'fontsize', 6);
else
rectangle('Position',[col-0.5 row 1 1], 'FaceColor','w','EdgeColor','k', 'LineWidth', 0.1)
end
end
set(gca,'Visible','off')
end
编辑:
Annotation
选项会增加复杂性,并且需要为每个其他问题定位箭头。如果可以使用乳胶箭头符号,问题就会变得容易得多。
如上所述,您可以使用 quiver
to draw the arrows. Also, pcolor
绘制所有矩形并为其着色的更好方法。
这是一个代码示例,它使用它们来创建您想要的东西:
data = randi(3,10)-1; % some random data
% plot the rectangles:
pcolor([data data(:,end);
data(end,:) 0])
% set the colors to w-y-c:
colormap([1 1 1;
1 1 0;
0 1 1]);
[r, c] = ndgrid(1:size(data,1),1:size(data,2)); % a grid of all the cells
% logical indexing for the arrows:
leftarrow = (data==1);
swarrow = (data==2);
% plot all the arrows in black:
hold on
quiver([r r]+0.1,[c c]+0.5,[-leftarrow.' -swarrow.'],...
[zeros(size(data)) -swarrow.'],'AutoScaleFactor',0.5,'Color','k')
hold off
set(gca,'Visible','off')
一个典型的结果:
我想在从矩阵读取的图形中显示特定单元格的方向。
在附图中,我可以创建左方向箭头,但我不知道如何在西南方向插入对角线箭头。
显然,latex arrow symbol 对左箭头、右箭头、上箭头和下箭头工作正常,但对角箭头无效。
在附图中,我需要通过青色单元在西南方向插入箭头。如何做到这一点?
这是我正在尝试的脚本,
for row=1:size(data,1)
for col=1:size(data,2);
if data(row,col)==1
rectangle('Position',[col-0.5 row 1 1], 'FaceColor','y','EdgeColor','k', 'LineWidth', 0.1)
text(col-0.95,row+0.6,'\leftarrow', 'fontsize', 6);
elseif data(row,col)==2
rectangle('Position',[col-0.5 row 1 1], 'FaceColor','c','EdgeColor','k', 'LineWidth', 0.1)
text(col-0.95,row+0.6,'\swarrow', 'fontsize', 6);
else
rectangle('Position',[col-0.5 row 1 1], 'FaceColor','w','EdgeColor','k', 'LineWidth', 0.1)
end
end
set(gca,'Visible','off')
end
编辑:
Annotation
选项会增加复杂性,并且需要为每个其他问题定位箭头。如果可以使用乳胶箭头符号,问题就会变得容易得多。
如上所述,您可以使用 quiver
to draw the arrows. Also, pcolor
绘制所有矩形并为其着色的更好方法。
这是一个代码示例,它使用它们来创建您想要的东西:
data = randi(3,10)-1; % some random data
% plot the rectangles:
pcolor([data data(:,end);
data(end,:) 0])
% set the colors to w-y-c:
colormap([1 1 1;
1 1 0;
0 1 1]);
[r, c] = ndgrid(1:size(data,1),1:size(data,2)); % a grid of all the cells
% logical indexing for the arrows:
leftarrow = (data==1);
swarrow = (data==2);
% plot all the arrows in black:
hold on
quiver([r r]+0.1,[c c]+0.5,[-leftarrow.' -swarrow.'],...
[zeros(size(data)) -swarrow.'],'AutoScaleFactor',0.5,'Color','k')
hold off
set(gca,'Visible','off')
一个典型的结果: