【问题标题】:How to create diagonal arrow in a figure using 'latex arrow symbol'?如何使用“乳胶箭头符号”在图中创建对角箭头?
【发布时间】:2017-10-06 02:43:12
【问题描述】:

我想在我从矩阵中读取的图中显示特定单元格的方向。

在附图中,我可以创建左方向箭头,但我不知道如何在西南方向插入对角箭头。

显然,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 选项会增加复杂性,并且需要为每个其他问题定位箭头。如果可以使用乳胶箭头符号,问题将变得更加容易。

【问题讨论】:

  • 您是否考虑过只绘制矢量,而不是使用 Latex 文本?
  • 不,我不知道。你能详细说明一下吗?
  • How to draw an arrow in Matlab? 的可能重复项,尤其是Marsei's answer
  • 你能描述/说明为什么它会因对角线而失败吗?
  • @Mario:我认为您应该考虑查看quiver 函数。你不需要丑陋的情节。另外,我认为您也应该考虑使用pcolor。然后,您可以摆脱您的 for 循环、矩形和注释。

标签: matlab plot matlab-figure


【解决方案1】:

如上所述,您可以使用quiver 来绘制箭头。此外,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')

还有一个典型的结果:

【讨论】:

    猜你喜欢
    • 2014-07-31
    • 1970-01-01
    • 2016-11-17
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    相关资源
    最近更新 更多