我正在尝试在 pgfPlots 中创建替代图钉,其图钉头可以直接定位在给定的坐标上。我通过提示 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}
我唯一的问题是,在编译图片时,pgfPlots 抱怨说! Illegal parameter number in definition of \pgfplots@stored@current@data.
我想知道你是否能帮助我。谢谢!