pgfPlots - 引脚定位

pgfPlots - 引脚定位

我正在尝试在基于表格的图中自动组织图钉。我使用 Excel 计算出图钉的定位,看起来应该是这样的:

引脚定位

其中蓝点标示针头的位置,橙点为数据点。

当我尝试在 pgfplots 中重现图片时,图钉到处都是:

LaTex 输出

尤其是引脚长度相差很大,我想解决这个问题。我想知道能否帮助我 - 这里的问题是什么?我肯定错过了一些简单的东西......

更一般地讲,有没有办法明确设置针头的坐标?因为如果有,那就是解决方案。

请查看以下代码

\documentclass[a4paper]{article}
\usepackage{tikz,pgf,pgfplots}

\begin{document}

\begin{figure}[!t]
        \begin{tikzpicture}
        \begin{axis}[   xlabel={\footnotesize\em X},
                xlabel style={anchor=south west,yshift=17},
                xticklabel style={font=\footnotesize},
                ylabel={\footnotesize\em Y},
                yticklabel=\pgfmathparse{\tick}\scriptsize{\pgfmathprintnumber\pgfmathresult$\%$},
                xmin=0.421,xmax=0.639,ymin=-4,ymax=5,
                /pgf/number format/.cd,1000 sep={},
                axis y line=middle,axis x line=bottom,width=0.8\textwidth,height=7cm,enlarge y limits=false]
            \addplot[scatter,only marks,mark=*,color=orange,fill=orange!50,
                nodes near coords=,point meta=explicit symbolic,
                visualization depends on={value \thisrowno{3} \as \pLength},
                visualization depends on={value \thisrowno{4} \as \pAngle},
                nodes near coords style={anchor=center,
                pin={[pin distance=\pLength pt,inner sep=0pt]\pAngle:
                \color{gray}\tiny\pgfplotspointmeta}}] 
                table[meta index=0,x index=1,y index=2,col sep=colon,row sep=\\]
            {
                cCode:vaMean:grRate:pLength:pAngle\\
                I:0.446011762:-2.9880240861209:8.26474505554416:90.1\\
                II:0.455298114:1.2986048756457:3.18056215634951:90.1\\
                III:0.459821107:1.03930315289819:3.38202979151282:270.1\\
                IV:0.478092071:2.97840738844084:4.10340709813473:270.1\\
                V:0.479941849:1.59702265223951:4.13824942003477:90.1\\
                VI:0.480351642:3.3524711569842:1.43986932160824:90.1\\
                VII:0.482134436:3.41371582423841:5.46711724631697:270.1\\
                VIII:0.487873856:1.3736762782294:2.42233198954666:270.1\\
                IX:0.488058429:1.12091598470426:4.69402955698523:90.1\\
                X:0.490288988:3.66314447629007:1.24379618497246:90.1\\
                XI:0.493991973:-1.25051294335446:0.76223461068095:270.1\\
                XII:0.496483346:2.81876845145779:3.74569480304638:270.1\\
                XIII:0.496578281:2.74933539863973:3.18985801134241:90.1\\
                XIV:0.497345964:1.86893648942637:3.08093456928143:90.1\\
                XV:0.499370689:2.67844071345076:4.55738553770126:270.1\\
                XVI:0.502424362:1.72083490469372:2.60374634690766:270.1\\
                XVII:0.50307426:1.15915862949923:4.82072421309031:90.1\\
                XVIII:0.507599953:2.74844889291042:2.3303411922447:90.1\\
                XIX:0.50851257:1.33583504217506:3.14043101590589:270.1\\
                XX:0.509140071:0.536888638528221:1.36895495352874:270.1\\
                XXI:0.509217915:2.21404920181979:3.85315065871641:90.1\\
                XXII:0.509324677:1.27464354722165:3.79488025052805:90.1\\
                XXIII:0.510640527:1.89735665578492:3.66796559296177:270.1\\
                XXIV:0.51548214:1.76580788859743:2.50506611016136:270.1\\
                XXV:0.517327022:2.75427777656798:3.41191034257464:90.1\\
                XXVI:0.519588259:2.63849847441633:2.5692928145534:90.1\\
                XXVII:0.528357937:2.82775229414536:4.38685396107011:270.1\\
                XXVIII:0.528587169:2.61135563698679:3.19116514402158:270.1\\
                XXIX:0.531593537:1.81428295417492:4.48997880514404:90.1\\
                XXX:0.531884844:2.58147037948711:2.75970334554338:90.1\\
                XXXI:0.531887782:2.30394853634762:3.83444582063914:270.1\\
                XXXII:0.535236966:3.76308497475767:4.24819434203687:270.1\\
                XXXIII:0.536880756:3.28694570596116:3.10324049159614:90.1\\
                XXXIV:0.537372027:1.39764100169776:3.98094538558486:90.1\\
                XXXV:0.537422271:2.6517091363921:4.11504641540926:270.1\\
                XXXVI:0.537740102:3.31111471420164:3.777476475367:270.1\\
                XXXVII:0.53850478:2.74906278761283:3.64861775748367:90.1\\
                XXXVIII:0.541010064:2.05319355327866:3.37768809197323:90.1\\
                XXXIX:0.541064286:2.75060170843188:4.17222394799738:270.1\\
                XL:0.543672322:1.42410936348899:1.86161164861503:270.1\\
                XLI:0.544310883:4.84761449858964:1.65360974261695:90.1\\
                XLII:0.548386998:1.71388480693158:3.79119257386861:90.1\\
                XLIII:0.549618573:3.5151233587387:4.82860844073453:270.1\\
                XLIV:0.551123217:2.04957718512414:2.39366239885079:270.1\\
                XLV:0.552072636:4.32972636096622:2.24649370656534:90.1\\
                XLVI:0.553937891:2.1169112873416:3.45656022256868:90.1\\
                XLVII:0.55979324:2.4813662243069:3.70331399938861:270.1\\
                XLVIII:0.559994624:1.53744271728727:1.79428754079037:270.1\\
                XLIX:0.560414521:3.15819763827853:3.48688778803509:90.1\\
                L:0.562085143:1.56884333352155:4.08326369953721:90.1\\
                LI:0.565707559:2.13162841707417:3.29557409722667:270.1\\
                LII:0.565737053:4.99291390357776:5.12101486734895:270.1\\
                LIII:0.568041137:1.21210608358574:5.479240446815:90.1\\
                LIV:0.568569852:2.78647995954384:2.95977969791187:90.1\\
                LV:0.578651727:3.09532310640572:4.09932438143875:270.1\\
                LVI:0.578695613:2.54268015098729:2.57583331877697:270.1\\
                LVII:0.5864431:3.00436395636275:3.92242428830296:90.1\\
                LVIII:0.587564097:3.07021346380359:2.88917505893958:90.1\\
                LIX:0.593162823:3.20817934281747:4.0513389257739:270.1\\
                LX:0.60120432:3.66776644697246:3.43330090854631:270.1\\
                LXI:0.606071673:3.20489520159223:3.94037078459432:90.1\\
                LXII:0.612622664:1.90637522399615:4.30483274117389:90.1\\
                LXIII:0.631068092:3.63164798487343:4.05220808446666:270.1\\
            };
        \end{axis}
    \end{tikzpicture}
\end{figure}

\end{document}

感谢您的关注和时间!

答案1

好吧,我找到了答案(部分)——首先,我重塑了数据表原始表,使其具有针头的明确坐标。然后我提示 pgfPlots 使用\pgfplotsinvokeforeach表中每个数据点的循环将针头绘制为线条(参见下面的代码)。

\documentclass[a4paper]{article}
\usepackage{tikz,pgf,pgfplots}

\begin{document}

\pgfplotstableread[format=inline,header=false,col sep=colon,row sep=\\,trim cells]
{
    I:0.446011762:-2.9880240861209:0.431587068017638:5.27670838149988\\
    II:0.455298114:1.2986048756457:0.44974698864902:4.47916218772325\\
    III:0.459821107:1.03930315289819:0.465723859529442:-2.34272148749\\
    IV:0.478092071:2.97840738844084:0.485253863805204:-1.12499345984906\\
    V:0.479941849:1.59702265223951:0.472719244902049:5.73526576936157\\
    VI:0.480351642:3.3524711569842:0.47783859722981:4.79233828554661\\
    VII:0.482134436:3.41371582423841:0.491676350809691:-2.05339309518493\\
    VIII:0.487873856:1.3736762782294:0.492101620732979:-1.04865202189559\\
    IX:0.488058429:1.12091598470426:0.479865806063827:5.81493839227544\\
    X:0.490288988:3.66314447629007:0.488118155236971:4.90693876685309\\
    XI:0.493991973:-1.25051294335446:0.495322322687491:-2.012746393086\\
    XII:0.496483346:2.81876845145779:0.503020813389756:-0.926920646570606\\
    XIII:0.496578281:2.74933539863973:0.491010931329615:5.93918855155179\\
    XIV:0.497345964:1.86893648942637:0.491968721502756:4.94986636617729\\
    XV:0.499370689:2.67844071345076:0.507324823253287:-1.87893788295715\\
    XVI:0.502424362:1.72083490469372:0.506968754356863:-0.882907476482473\\
    XVII:0.50307426:1.15915862949923:0.494660513286719:5.97987550020855\\
    XVIII:0.507599953:2.74844889291042:0.503532742414953:5.07878653584342\\
    XIX:0.50851257:1.33583504217506:0.513993653333209:-1.80459119058207\\
    XX:0.509140071:0.536888638528221:0.511529346912031:-0.83206422996342\\
    XXI:0.509217915:2.21404920181979:0.502492901857261:6.06719399185363\\
    XXII:0.509324677:1.27464354722165:0.502701364853565:5.06951801781802\\
    XXIII:0.510640527:1.89735665578492:0.517042331394537:-1.77060335054719\\
    XXIV:0.51548214:1.76580788859743:0.519854302940516:-0.73925440613102\\
    XXV:0.517327022:2.75427777656798:0.511372118097201:6.16618292250732\\
    XXVI:0.519588259:2.63849847441633:0.515103999370461:5.20778737571398\\
    XXVII:0.528357937:2.82775229414536:0.536014437655311:-1.55909498536577\\
    XXVIII:0.528587169:2.61135563698679:0.534156800046128:-0.579804646613566\\
    XXIX:0.531593537:1.81428295417492:0.523757049629098:6.3042549206919\\
    XXX:0.531884844:2.58147037948711:0.527068255469558:5.34116952176299\\
    XXXI:0.531887782:2.30394853634762:0.538580149058263:-1.53049144409804\\
    XXXII:0.535236966:3.76308497475767:0.542651460089007:-0.485102896910843\\
    XXXIII:0.536880756:3.28694570596116:0.531464582343812:6.39018147105294\\
    XXXIV:0.537372027:1.39764100169776:0.530423970095446:5.3785803239576\\
    XXXV:0.537422271:2.6517091363921:0.544604378235804:-1.46333101144464\\
    XXXVI:0.537740102:3.31111471420164:0.544333038843973:-0.466356007741136\\
    XXXVII:0.53850478:2.74906278761283:0.532136743931542:6.39767498793528\\
    XXXVIII:0.541010064:2.05319355327866:0.535114889161921:5.43087650074004\\
    XXXIX:0.541064286:2.75060170843188:0.548346186805322:-1.42161588490664\\
    XL:0.543672322:1.42410936348899:0.546921445616615:-0.437499449730071\\
    XLI:0.544310883:4.84761449858964:0.541424791010084:6.50122172261556\\
    XLII:0.548386998:1.71388480693158:0.541770122060243:5.50507160648515\\
    XLIII:0.549618573:3.5151233587387:0.558046080279432:-1.31347772760648\\
    XLIV:0.551123217:2.04957718512414:0.555300943883099:-0.344081567971259\\
    XLV:0.552072636:4.32972636096622:0.548151766810119:6.57621664592685\\
    XLVI:0.553937891:2.1169112873416:0.547905058395114:5.57346624526933\\
    XLVII:0.55979324:2.4813662243069:0.566256738970963:-1.22194213461337\\
    XLVIII:0.559994624:1.53744271728727:0.56312624494152:-0.256842090647591\\
    XLIX:0.560414521:3.15819763827853:0.554328756834837:6.64508011548116\\
    L:0.562085143:1.56884333352155:0.554958507039754:5.65210081389408\\
    LI:0.565707559:2.13162841707417:0.571459417953811:-1.16394066070738\\
    LII:0.565737053:4.99291390357776:0.574674905510172:-0.128093164021497\\
    LIII:0.568041137:1.21210608358574:0.558478063224594:6.69133818504242\\
    LIV:0.568569852:2.78647995954384:0.563404064536424:5.74625514945458\\
    LV:0.578651727:3.09532310640572:0.585806394123945:-1.00399503140653\\
    LVI:0.578695613:2.54268015098729:0.583191287957088:-0.0331492445721757\\
    LVII:0.5864431:3.00436395636275:0.579597181626535:6.9267822704734\\
    LVIII:0.587564097:3.07021346380359:0.582521537815586:5.95938412227903\\
    LIX:0.593162823:3.20817934281747:0.600233739747023:-0.843153412415941\\
    LX:0.60120432:3.66776644697246:0.607196557464351:0.234470767641138\\
    LXI:0.606071673:3.20489520159223:0.599194432097489:7.14525998466017\\
    LXII:0.612622664:1.90637522399615:0.60510931730638:6.21120140853649\\
    LXIII:0.631068092:3.63164798487343:0.638140525714344:-0.420553927728943\\
}\picTable

\begin{figure}[!t]
        \begin{tikzpicture}
        \begin{axis}[   xlabel={\footnotesize\em X},
                xlabel style={anchor=south west,yshift=17},
                xticklabel style={font=\footnotesize},
                ylabel={\footnotesize\em Y},
                yticklabel=\pgfmathparse{\tick}\scriptsize{\pgfmathprintnumber\pgfmathresult$\%$},
                xmin=0.421,xmax=0.649,ymin=-4,ymax=7.5,
                /pgf/number format/.cd,1000 sep={},
                axis y line=middle,axis x line=bottom,width=0.8\textwidth,height=7cm,enlarge y limits=false]

            \pgfplotstablegetrowsof\picTable
            \pgfmathsetmacro\rowcount{\pgfplotsretval-1}

            \addplot[scatter,only marks,mark=*,color=orange,fill=orange!50,
                nodes near coords=,point meta=explicit symbolic,
                nodes near coords style={anchor=center}] 
                table[x index=1,y index=2]{\picTable};

            \pgfplotsextra
            {
                \pgfplotsinvokeforeach{0,...,\rowcount}
                {
                    \pgfplotstablegetelem{#1}{[index]0}\of\picTable
                    \let\lblCurr=\pgfplotsretval
                    \pgfplotstablegetelem{#1}{[index]1}\of\picTable
                    \let\Xcurr=\pgfplotsretval
                    \pgfplotstablegetelem{#1}{[index]2}\of\picTable
                    \let\Ycurr=\pgfplotsretval
                    \pgfplotstablegetelem{#1}{[index]3}\of\picTable
                    \let\pXcurr=\pgfplotsretval
                    \pgfplotstablegetelem{#1}{[index]4}\of\picTable
                    \let\pYcurr=\pgfplotsretval

                    \node(dNode) at (axis cs:\Xcurr,\Ycurr){};
                    \node(pNode) at (axis cs:\pXcurr,\pYcurr){\color{gray}\tiny \lblCurr};
                    \draw circle[color=orange,fill=orange!50] (dNode);
                    \draw[gray,smooth,inner sep=0] (dNode) -- (pNode);
                }
            }
        \end{axis}
    \end{tikzpicture}
\end{figure}

\end{document}

唯一的缺点是,在编译时,图片会提示一连串错误! Illegal parameter number in definition of \pgfplots@stored@current@data.,但这并不妨碍它被完整绘制。

相关内容