【问题标题】:Matlab, gplot custom linewidth for some lines, but not allMatlab,gplot为某些行自定义线宽,但不是全部
【发布时间】:2013-06-28 10:00:39
【问题描述】:

过去,有人问过一个关于在 gplot 中自定义线宽的问题(请参阅In MatLab, how to adjust the line width drawn by the function 'gplot'?)。我正在处理一个稍微复杂的版本,这使我无法使用那里给出的解决方案。因此,我想问如何做到以下几点:我想调整gplot的一些调用的线宽,而不是其他的。我就是多次调用 gplot 并使用 hold on 将它们绘制在一个图中。我正在尝试绘制具有多种边(A 和 A2)的图形。其中有 k 条路径。我目前正在使用以下代码:

figure
hold on
gplot(A,coor,'k*:')
gplot(A2,coor,'k-')
plot(coor(T,1),coor(T,2),'k.','MarkerSize',20)
plot(coor(T,1),coor(T,2),'bo','MarkerSize',20)
% a line where I define my own colors (not shown, since not relevant)
set(gca,'ColorOrder',colors)
hold all
for i=1:k
    gplot(Path,coor)
end
hold off

但我想绘制线宽较大的路径,同时将 A 和 A2 保持在标准线宽 1。

有人可以帮助我吗?非常感谢!

【问题讨论】:

    标签: matlab


    【解决方案1】:

    你可以在添加额外线之前和之后获取轴的孩子,并且只将新的设置为具有更大的线宽:

    figure
    hold on
    gplot(A,coor,'k*:')
    gplot(A2,coor,'k-')
    plot(coor(T,1),coor(T,2),'k.','MarkerSize',20)
    plot(coor(T,1),coor(T,2),'bo','MarkerSize',20)
    ChildrenBefore=get(gca,'children');
    % a line where I define my own colors (not shown, since not relevant)
    set(gca,'ColorOrder',colors)
    hold all
    for i=1:k
        gplot(Path,coor)
    end
    hold off
    ChildrenAfter=get(gca,'children');
    NewChildren=setdiff(ChildrenAfter,ChildrenBefore);
    set(intersect(findall(gcf,'type','line'),NewChildren),'LineWidth',5)
    

    【讨论】:

    • @dro,请将此问题标记为答案,这就是 SO 的工作原理!
    猜你喜欢
    • 2013-05-20
    • 2018-05-06
    • 2021-12-26
    • 1970-01-01
    • 2012-07-25
    • 1970-01-01
    • 2014-07-13
    • 2015-12-21
    • 2019-05-07
    相关资源
    最近更新 更多