我在 python 中绘制了这个图:
当我使用 latex 绘图时,我得到了除“95% 置信区间”之外的所有标签。我试过了,\addlegendentry{}
但没用。
也许添加
\path [fill=color0, draw opacity=0, fill opacity=0.6,label=blabla]
以便它识别 95% 曲线?
!TeX program = lualatex
\documentclass{standalone}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{pgfplots, pgfplotstable}
\usetikzlibrary{positioning}
\pgfplotsset{compat=1.16,width=0.98\textwidth}
%\pgfplotsset{compat=1.16,width=0.98\textwidth}
\usepgfplotslibrary{groupplots}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage[english,spanish]{babel} % multilenguaje
\decimalpoint
\definecolor{myblue}{RGB}{0,0,143}
\definecolor{myred}{RGB}{128,0,0}
\begin{document}
\begin{tikzpicture}
\definecolor{color0}{rgb}{0,0.75,0.75}
\definecolor{color1}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}
\definecolor{color2}{rgb}{0.501960784313725,0,0.501960784313725}
\definecolor{color3}{rgb}{1,0.843137254901961,0}
\begin{groupplot}[group style={group size=1 by 2}]
\nextgroupplot[
legend cell align={left},
legend style={at={(0.5,0.3)}, anchor=north west, draw=black},
tick align=outside,
tick pos=left,
xtick align=inside,
ytick align=inside,
x grid style={white!69.01960784313725!black},
xlabel={$\mathbf{x}$},
xmin=-2, xmax=10,
xtick style={color=black},
y grid style={white!69.01960784313725!black},
ylabel={$f(\mathbf{x})$},
ymin=0.141649898838692, ymax=1.46190886017113,
ytick style={color=black}
]
\path [fill=color0, draw opacity=0, fill opacity=0.6]
(axis cs:-2,0.866792369503652)
--(axis cs:-1.54395439543954,0.919530186350506)
--(axis cs:-1.54515451545155,0.919558548611325)
--(axis cs:-1.54635463546355,0.919586912138129)
--(axis cs:-1.54755475547555,0.919615276934969)
--(axis cs:-1.54875487548755,0.919643643002155)
--(axis cs:-1.54995499549955,0.919672010335886)
--(axis cs:-1.55115511551155,0.91970037894041)
--(axis cs:-1.55235523552355,0.919728748808043)
--(axis cs:-1.55355535553555,0.919757119944978)
--(axis cs:-1.55475547554755,0.919785492353284)
--(axis cs:-1.55595559555956,0.919813866025442)
--(axis cs:-1.55715571557156,0.919842240965596)
--(axis cs:-1.55835583558356,0.919870617173895)
--(axis cs:-1.55955595559556,0.919898994648742)
--(axis cs:-1.56075607560756,0.919927373388266)
--(axis cs:-1.56195619561956,0.919955753398611)
--(axis cs:-1.56315631563156,0.91998413467223)
--(axis cs:-1.56435643564356,0.920012517217042)
--(axis cs:-1.56555655565557,0.920040901027542)
--(axis cs:-1.56675667566757,0.920069286103877)
--(axis cs:-1.56795679567957,0.920097672444508)
--(axis cs:-1.56915691569157,0.920126060053246)
--(axis cs:-1.57035703570357,0.920154448926605)
--(axis cs:-1.57155715571557,0.920182839066768)
--(axis cs:-1.57275727572757,0.920211230472008)
--(axis cs:-1.57395739573957,0.920239623144404)
--(axis cs:-1.57515751575158,0.920268017082363)
--(axis cs:-1.57635763576358,0.920296412282115)
--(axis cs:-1.57755775577558,0.920324808753618)
--(axis cs:-1.57875787578758,0.920353206485544)
--(axis cs:-1.57995799579958,0.920381605483879)
--(axis cs:-1.58115811581158,0.920410005744882)
--(axis cs:-1.58235823582358,0.920438407272788)
--(axis cs:-1.58355835583558,0.920466810065772)
--(axis cs:-1.58475847584758,0.920495214122185)
--(axis cs:-1.58595859585959,0.920523619444161)
--(axis cs:-1.58715871587159,0.92055202602805)
--(axis cs:-1.58835883588359,0.920580433878065)
--(axis cs:-1.58955895589559,0.920608842992342)
--(axis cs:-1.59075907590759,0.920637253369196)
--(axis cs:-1.59195919591959,0.920665665008923)
--(axis cs:-1.59315931593159,0.920694077915495)
--(axis cs:-1.59435943594359,0.92072249208154)
--(axis cs:-1.5955595559556,0.920750907511129)
--(axis cs:-1.5967596759676,0.92077932420829)
--(axis cs:-1.5979597959796,0.920807742165403)
--(axis cs:-1.5991599159916,0.920836161386821)
--(axis cs:-1.6003600360036,0.920864581868738)
--(axis cs:-1.6015601560156,0.920893003615276)
--(axis cs:-1.6027602760276,0.920921426622798)
--(axis cs:-1.6039603960396,0.920949850895393)
--(axis cs:-1.60516051605161,0.92097827642937)
--(axis cs:-1.60636063606361,0.921006703223108)
--(axis cs:-1.60756075607561,0.921035131280686)
--(axis cs:-1.60876087608761,0.921063560602238)
--(axis cs:-1.60996099609961,0.92109199118225)
--(axis cs:-1.61116111611161,0.921120423026795)
--(axis cs:-1.61236123612361,0.921148856130204)
--(axis cs:-1.61356135613561,0.92117729049283)
--(axis cs:-1.61476147614761,0.92120572612059)
--(axis cs:-1.61596159615962,0.921234163009839)
--(axis cs:-1.61716171617162,0.921262601158891)
--(axis cs:-1.61836183618362,0.921291040569876)
--(axis cs:-1.61956195619562,0.921319481241166)
--(axis cs:-1.62076207620762,0.921347923171066)
--(axis cs:-1.62196219621962,0.921376366363514)
--(axis cs:-1.62316231623162,0.921404810813083)
--(axis cs:-1.62436243624362,0.921433256527688)
--(axis cs:-1.62556255625563,0.921461703501694)
--(axis cs:-1.62676267626763,0.921490151735422)
--(axis cs:-1.62796279627963,0.921518601225234)
--(axis cs:-1.62916291629163,0.92154705197703)
--(axis cs:-1.63036303630363,0.921575503989253)
--(axis cs:-1.63156315631563,0.921603957260118)
--(axis cs:-1.63276327632763,0.92163241179175)
--(axis cs:-1.63396339633963,0.921660867580591)
--(axis cs:-1.63516351635164,0.921689324628724)
--(axis cs:-1.63636363636364,0.921717782938365)
--(axis cs:-1.63756375637564,0.921746242503935)
--(axis cs:-1.63876387638764,0.921774703329466)
--(axis cs:-1.63996399639964,0.921803165413383)
--(axis cs:-1.64116411641164,0.921831628755713)
--(axis cs:-1.64236423642364,0.92186009335687)
--(axis cs:-1.64356435643564,0.921888559215109)
--(axis cs:-1.64476447644764,0.921917026332473)
--(axis cs:-1.64596459645965,0.921945494707352)
--(axis cs:-1.64716471647165,0.921973964339977)
--(axis cs:-1.64836483648365,0.922002435228662)
--(axis cs:-1.64956495649565,0.922030907377359)
--(axis cs:-1.65076507650765,0.922059380778831)
--(axis cs:-1.65196519651965,0.922087855444605)
--(axis cs:-1.65316531653165,0.922116331361625)
--(axis cs:-1.65436543654365,0.922144808539502)
--(axis cs:-1.65556555655566,0.922173286972881)
--(axis cs:-1.65676567656766,0.922201766663922)
--(axis cs:-1.65796579657966,0.922230247608921)
--(axis cs:-1.65916591659166,0.922258729811977)
--(axis cs:-1.66036603660366,0.922287213271364)
--(axis cs:-1.66156615661566,0.922315697989231)
--(axis cs:-1.66276627662766,0.922344183960127)
--(axis cs:-1.66396639663966,0.922372671188031)
--(axis cs:-1.66516651665167,0.922401159673226)
--(axis cs:-1.66636663666367,0.922429649413967)
--(axis cs:-1.66756675667567,0.922458140408538)
--(axis cs:-1.66876687668767,0.922486632659142)
--(axis cs:-1.66996699669967,0.922515126166)
--(axis cs:-1.67116711671167,0.922543620925533)
--(axis cs:-1.67236723672367,0.922572116941714)
--(axis cs:-1.67356735673567,0.922600614212821)
--(axis cs:-1.67476747674767,0.922629112739226)
--(axis cs:-1.67596759675968,0.922657612521065)
--(axis cs:-1.67716771677168,0.922686113556656)
--(axis cs:-1.67836783678368,0.922714615844408)
--(axis cs:-1.67956795679568,0.922743119388172)
--(axis cs:-1.68076807680768,0.922771624190134)
--(axis cs:-1.68196819681968,0.92280013024115)
--(axis cs:-1.68316831683168,0.922828637546953)
--(axis cs:-1.68436843684368,0.922857146107929)
--(axis cs:-1.68556855685569,0.922885655920371)
--(axis cs:-1.68676867686769,0.922914166988332)
--(axis cs:-1.68796879687969,0.922942679310205)
--(axis cs:-1.68916891689169,0.922971192884237)
--(axis cs:-1.69036903690369,0.9229997077126)
--(axis cs:-1.69156915691569,0.923028223791677)
--(axis cs:-1.69276927692769,0.923056741125537)
--(axis cs:-1.69396939693969,0.923085259712432)
--(axis cs:-1.6951695169517,0.923113779550806)
--(axis cs:-1.6963696369637,0.923142300640763)
--(axis cs:-1.6975697569757,0.92317082298445)
--(axis cs:-1.6987698769877,0.923199346583944)
--(axis cs:-1.6999699969997,0.923227871430156)
--(axis cs:-1.7011701170117,0.923256397528899)
--(axis cs:-1.7023702370237,0.923284924882128)
--(axis cs:-1.99279927992799,0.930225049939748)
--(axis cs:-1.99399939993999,0.930253877748194)
--(axis cs:-1.995199519952,0.93028270677811)
--(axis cs:-1.996399639964,0.930311537026441)
--(axis cs:-1.997599759976,0.93034036849834)
--(axis cs:-1.998799879988,0.930369201189014)
--(axis cs:-2,0.93039803510041)
--cycle;
\addlegendentry{$f(\mathbf{x})$}
\addplot [very thick, myblue]
table {%
-2 0.201661669808349
-1.998799879988 0.201857010241904
-1.997599759976 0.202052610231707
-1.996399639964 0.202248470186105
-1.995199519952 0.202444590514115
-1.99399939993999 0.202640971625421
-1.99279927992799 0.20283761393038
-1.99159915991599 0.203034517840017
-1.99039903990399 0.20323168376603
-1.98919891989199 0.203429112120788
-1.98799879987999 0.203626803317334
-1.98679867986799 0.203824757769386
-1.98559855985599 0.204022975891336
-1.98439843984398 0.204221458098251
-1.98319831983198 0.204420204805877
-1.98199819981998 0.204619216430635
-1.98079807980798 0.204818493389626
-1.97959795979598 0.20501803610063
-1.97839783978398 0.205217844982106
-1.97719771977198 0.205417920453195
-1.97599759975998 0.20561826293372
-1.97479747974797 0.205818872844185
-1.97359735973597 0.20601975060578
-1.97239723972397 0.206220896640376
-1.97119711971197 0.206422311370533
-1.96999699969997 0.206623995219493
-1.96879687968797 0.206825948611187
-1.96759675967597 0.207028171970234
-1.96639663966397 0.207230665721941
-1.96519651965197 0.207433430292303
-1.96399639963996 0.207636466108007
-1.96279627962796 0.20783977359643
-1.96159615961596 0.208043353185642
-1.96039603960396 0.208247205304404
-1.95919591959196 0.208451330382171
-1.95799579957996 0.208655728849093
-1.95679567956796 0.208860401136015
-1.95559555955596 0.209065347674477
-1.95439543954395 0.209270568896716
-1.95319531953195 0.209476065235668
-1.95199519951995 0.209681837124966
-1.95079507950795 0.209887884998943
-1.94959495949595 0.210094209292632
-1.94839483948395 0.210300810441766
-1.94719471947195 0.210507688882781
-1.94599459945995 0.210714845052814
-1.94479447944794 0.210922279389708
-1.94359435943594 0.211129992332006
-1.94239423942394 0.21133798431896
-1.94119411941194 0.211546255790526
-1.93999399939994 0.211754807187366
-1.93879387938794 0.211963638950851
-1.93759375937594 0.212172751523059
-1.93639363936394 0.212382145346776
-1.93519351935194 0.2125918208655
-1.93399339933993 0.212801778523439
-1.93279327932793 0.213012018765511
-1.93159315931593 0.213222542037347
-1.93039303930393 0.213433348785292
-1.92919291929193 0.213644439456404
-1.92799279927993 0.213855814498454
-1.92679267926793 0.214067474359931
-1.92559255925593 0.214279419490039
-1.65796579657966 0.89344797874546
-1.65676567656766 0.893429877850131
-1.65556555655566 0.893411776675203
-1.65436543654365 0.8933936752207
-1.65316531653165 0.893375573486665
-1.65196519651965 0.893357471473129
-1.65076507650765 0.893339369180134
-1.64956495649565 0.893321266607708
-1.64836483648365 0.893303163755883
-1.64716471647165 0.893285060624704
-1.64596459645965 0.8932669572142
-1.64476447644764 0.893248853524408
-1.64356435643564 0.893230749555362
-1.64236423642364 0.893212645307104
-1.64116411641164 0.893194540779664
-1.63996399639964 0.893176435973068
-1.63876387638764 0.89315833088737
-1.63756375637564 0.89314022552259
-1.63636363636364 0.893122119878772
-1.63516351635164 0.893104013955948
-1.63396339633963 0.89308590775415
-1.63276327632763 0.893067801273421
-1.63156315631563 0.893049694513792
-1.63036303630363 0.893031587475295
-1.62916291629163 0.893013480157977
-1.62796279627963 0.892995372561856
-1.62676267626763 0.89297726468698
-1.62556255625563 0.892959156533381
-1.62436243624362 0.892941048101095
-1.62316231623162 0.892922939390155
-1.62196219621962 0.892904830400596
-1.62076207620762 0.892886721132456
-1.61956195619562 0.89286861158577
-1.61836183618362 0.892850501760577
-1.61716171617162 0.892832391656903
-1.61596159615962 0.892814281274786
-1.61476147614761 0.89279617061427
-1.61356135613561 0.892778059675382
-1.61236123612361 0.89275994845816
-1.61116111611161 0.892741836962635
-1.60996099609961 0.892723725188851
-1.60876087608761 0.892705613136836
0.352235223522352 0.862765773532674
0.353435343534354 0.862747256697451
0.354635463546355 0.862728739647085
0.355835583558356 0.862710222381603
0.357035703570357 0.862691704901058
0.358235823582358 0.86267318720548
0.359435943594359 0.862654669294919
0.360636063606361 0.862636151169424
0.361836183618362 0.862617632829018
0.363036303630363 0.862599114273761
0.364236423642364 0.862580595503683
0.365436543654366 0.862562076518831
0.366636663666367 0.862543557319245
0.367836783678368 0.862525037904971
0.369036903690369 0.862506518276044
0.37023702370237 0.862487998432511
0.371437143714372 0.862469478374414
0.372637263726373 0.862450958101794
0.373837383738374 0.862432437614691
0.375037503750375 0.862413916913148
0.376237623762377 0.862395395997207
0.377437743774378 0.862376874866916
0.378637863786379 0.862358353522303
0.37983798379838 0.862339831963421
0.381038103810381 0.86232131019031
0.382238223822382 0.86230278820301
0.383438343834384 0.862284266001564
0.384638463846385 0.862265743586015
0.385838583858386 0.862247220956401
0.387038703870387 0.862228698112771
0.388238823882388 0.862210175055166
0.389438943894389 0.862191651783613
0.390639063906391 0.86217312829817
0.391839183918392 0.862154604598879
0.393039303930393 0.862136080685774
0.394239423942394 0.862117556558909
0.395439543954396 0.862099032218308
0.396639663966397 0.862080507664025
0.397839783978398 0.862061982896101
0.399039903990399 0.862043457914575
0.4002400240024 0.862024932719492
0.401440144014402 0.862006407310892
0.402640264026403 0.861987881688819
0.403840384038404 0.861969355853311
0.405040504050405 0.861950829804415
0.406240624062407 0.861932303542172
0.407440744074408 0.861913777066622
0.408640864086409 0.861895250377808
0.40984098409841 0.861876723475768
0.411041104110411 0.861858196360552
0.412241224122412 0.861839669032198
0.413441344134414 0.861821141490745
0.414641464146415 0.861802613736239
0.415841584158416 0.861784085768725
0.417041704170417 0.861765557588237
0.418241824182418 0.861747029194823
};
\addlegendentry{$a_{EI}$}
\addplot [thick, black, mark=triangle*, mark size=3, mark options={solid,fill=green,draw=black}, only marks]
table {%
-2 0.898595202302031
};
\addlegendentry{Siguiente mejor estimación}
\end{groupplot}
\node at ({$(current bounding box.south west)!0.5!(current bounding box.south east)$}|-{$(current bounding box.south west)!0.98!(current bounding box.north west)$})[
scale=0.6,
anchor=north,
text=black,
rotate=0.0
]{};
%Proceso gaussiano y función de adquisicióndespués de 2 pasos
\end{tikzpicture}
\end{document}
答案1
未\path
添加到图例中。您可以使用
\addlegendimage{fill=color0, draw opacity=0, fill opacity=0.6,area legend}
在图例中添加新的“虚拟情节”。
\documentclass{standalone}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{pgfplots, pgfplotstable}
\usetikzlibrary{positioning}
\pgfplotsset{compat=1.16,width=0.98\textwidth}
%\pgfplotsset{compat=1.16,width=0.98\textwidth}
\usepgfplotslibrary{groupplots}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage[english,spanish]{babel} % multilenguaje
\decimalpoint
\definecolor{myblue}{RGB}{0,0,143}
\definecolor{myred}{RGB}{128,0,0}
\begin{document}
\begin{tikzpicture}
\definecolor{color0}{rgb}{0,0.75,0.75}
\definecolor{color1}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}
\definecolor{color2}{rgb}{0.501960784313725,0,0.501960784313725}
\definecolor{color3}{rgb}{1,0.843137254901961,0}
\begin{groupplot}[group style={group size=1 by 2}]
\nextgroupplot[
legend cell align={left},
legend style={at={(0.5,0.3)}, anchor=north west, draw=black},
tick align=outside,
tick pos=left,
xtick align=inside,
ytick align=inside,
x grid style={white!69.01960784313725!black},
xlabel={$\mathbf{x}$},
xmin=-2, xmax=10,
xtick style={color=black},
y grid style={white!69.01960784313725!black},
ylabel={$f(\mathbf{x})$},
ymin=0.141649898838692, ymax=1.46190886017113,
ytick style={color=black}
]
\path [fill=color0, draw opacity=0, fill opacity=0.6]
(axis cs:-2,0.866792369503652)
--(axis cs:-1.54395439543954,0.919530186350506)
--(axis cs:-2,0.93039803510041)
--cycle;
\addlegendentry{$f(\mathbf{x})$}
\addplot [very thick, myblue]
table {%
-2 0.201661669808349
-1.998799879988 0.201857010241904
-1.997599759976 0.202052610231707
};
\addlegendentry{$a_{EI}$}
\addplot [thick, black, mark=triangle*, mark size=3, mark options={solid,fill=green,draw=black}, only marks]
table {%
-2 0.898595202302031
};
% add this
\addlegendimage{fill=color0, draw opacity=0, fill opacity=0.6,area legend}
\addlegendentry{Siguiente mejor estimación}
\end{groupplot}
\node at ({$(current bounding box.south west)!0.5!(current bounding box.south east)$}|-{$(current bounding box.south west)!0.98!(current bounding box.north west)$})[
scale=0.6,
anchor=north,
text=black,
rotate=0.0
]{};
%Proceso gaussiano y función de adquisicióndespués de 2 pasos
\end{tikzpicture}
\end{document}