\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[format=hang]{caption}
\usetikzlibrary{trees}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=newest}
\usetikzlibrary{patterns} % for "schraffierte" lines
\usetikzlibrary{calc}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Neyman Pearson Alpha Representation},
grid=major,
grid style={dashed,gray!30},
xlabel={x values},
ylabel={y values},
%xmin=0, xmax=20,
ymin=0,ymax=0.1,
%ymode=log,
%ymin=0, ymax=1.35,
%xtick={0,50,100,150,200,250,300},
%ytick={0,0.2,0.4,0.6,0.8,1.0},
legend pos=north west,
enlarge y limits={abs=1cm,upper}
%ymajorgrids=true,
%grid style=dashed,
%xmajorgrids=true
%grid style=dashed
]
\addplot[
name path=U,
color=blue,]
coordinates {(-44.848214732850224, 6.894645067806492e-07)
(-44.57635519136731, 1.5335076456603906e-06)
(-44.30449564988441, 3.179761069727552e-06)
(-44.0326361084015, 6.148889876285282e-06)
(-43.760776566918594, 1.10937371897585e-05)
(-43.48891702543568, 1.8683210673628567e-05)
(-43.21705748395278, 2.9387382547012065e-05)
(-42.94519794246987, 4.319955281138747e-05)
(-42.673338400986964, 5.938929762902865e-05)
(-42.40147885950405, 7.6414292131392e-05)
(-42.12961931802115, 9.209294148968027e-05)
(-41.85775977653824, 0.00010404711057331556)
(-41.585900235055334, 0.00011030078629595235)
(-41.31404069357242, 0.000109832023101698)
(-41.04218115208951, 0.00010287647076595105)
(-40.77032161060661, 9.087623596113042e-05)
(-40.4984620691237, 7.610817275377553e-05)
(-40.22660252764079, 6.1139158343419e-05)
(-39.95474298615788, 4.829391104205787e-05)
(-39.68288344467498, 3.9283191743289394e-05)
(-39.41102390319207, 3.506482999018231e-05)
(-39.13916436170916, 3.593973512414593e-05)
(-38.86730482022625, 4.1837267341224136e-05)
(-38.59544527874335, 5.270683195305673e-05)
(-38.32358573726044, 6.888846794696949e-05)
(-38.05172619577753, 9.129590100201937e-05)
(-37.77986665429462, 0.00012125802380135891)
(-37.50800711281171, 0.00015997575355931602)
(-37.23614757132881, 0.00020774924641827892)
(-36.964288029845896, 0.0002633194172860166)
(-36.69242848836299, 0.0003237125694420689)
(-36.42056894688008, 0.00038480332949224596)
(-36.14870940539718, 0.00044248219468474024)
(-35.876849863914266, 0.0004940100416894872)
(-35.60499032243136, 0.0005390422705063198)
(-35.33313078094845, 0.0005799601905271269)
(-35.06127123946554, 0.0006214447783767588)
(-34.789411697982636, 0.000669484983196033)
(-34.51755215649973, 0.0007301148849723863)
(-34.24569261501682, 0.0008081455980307046)
(-33.97383307353391, 0.0009061070438093106)
(-33.70197353205101, 0.0010236101457950836)
(-33.430113990568096, 0.0011573380751522366)
(-33.15825444908519, 0.001301771800645149)
(-32.88639490760228, 0.0014505148345369924)
(-32.61453536611938, 0.0015978141053263684)
(-32.342675824636466, 0.0017397661732941152)
(-32.07081628315356, 0.0018748563292110927)
(-31.79895674167065, 0.0020038228887075613)
(-31.527097200187743, 0.002129161236098114)
(-31.255237658704836, 0.0022547023562183616)
(-30.98337811722193, 0.0023855774178484293)
(-30.71151857573902, 0.0025285899766276363)
(-30.439659034256113, 0.0026926765921573524)
(-30.167799492773206, 0.00288887445804216)
(-29.895939951290295, 0.003129194197836001)
(-29.62408040980739, 0.003424169947660831)
(-29.35222086832448, 0.0037796132328049093)
(-29.080361326841576, 0.00419391247774378)
(-28.808501785358665, 0.004657547392463743)
(-28.536642243875757, 0.005155882892785484)
(-28.26478270239285, 0.0056748192834542455)
(-27.992923160909942, 0.006207176081131369)
(-27.721063619427035, 0.006756775612226696)
(-27.449204077944128, 0.007337799203189873)
(-27.17734453646122, 0.007969040513738574)
(-26.905484994978313, 0.00866521532100629)
(-26.633625453495405, 0.009429141241895941)
(-26.361765912012498, 0.010248409255211706)
(-26.08990637052959, 0.011098165291282299)
(-25.818046829046683, 0.011948834174854277)
(-25.54618728756377, 0.012775473432696447)
(-25.274327746080864, 0.013564961502489842)
(-25.002468204597957, 0.014318515537620006)
(-24.73060866311505, 0.01504932688106691)
(-24.45874912163214, 0.01577720533513981)
(-24.186889580149234, 0.016523040202726998)
(-23.915030038666327, 0.017305294223862868)
(-23.64317049718342, 0.018139130197882335)
(-23.371310955700512, 0.01903713368814644)
(-23.099451414217604, 0.020009880093378396)
(-22.827591872734697, 0.021065122382592012)
(-22.55573233125179, 0.022205680276165596)
(-22.283872789768882, 0.023427282626250205)
(-22.01201324828597, 0.024717916958975725)
(-21.740153706803063, 0.026059563521907726)
(-21.468294165320156, 0.027432039346067815)
(-21.19643462383725, 0.028817759609924547)
(-20.92457508235434, 0.030205979006977562)
(-20.652715540871434, 0.031595456311677615)
(-20.380855999388526, 0.03299508621844504)
(-20.10899645790562, 0.03442244945498294)
(-19.83713691642271, 0.035900330037910655)
(-19.565277374939804, 0.03745128013792869)
(-19.293417833456896, 0.039090641736528306)
(-19.02155829197399, 0.040819184343076124)
(-18.749698750491078, 0.04261738316454194)
(-18.47783920900817, 0.04444375273099176)
(-18.205979667525263, 0.0462390700417067)
(-17.934120126042355, 0.04793669038575741)
(-17.662260584559448, 0.04947692033720996)
(-17.39040104307654, 0.050821426341573765)
(-17.118541501593633, 0.05196293488080258)
(-16.846681960110725, 0.05292671075011648)
(-16.574822418627818, 0.05376327258266576)
(-16.30296287714491, 0.054535177157891974)
(-16.031103335662003, 0.05530261359505334)
(-15.759243794179095, 0.05611190883346318)
(-15.487384252696188, 0.05698852332171388)
(-15.215524711213277, 0.05793375508292683)
(-14.94366516973037, 0.05892395066356531)
(-14.671805628247462, 0.05991250342435047)
(-14.399946086764555, 0.060836424770028444)
(-14.128086545281647, 0.06162872194262811)
(-13.85622700379874, 0.0622348344112881)
(-13.584367462315832, 0.06262782880200887)
(-13.312507920832925, 0.0628156850968826)
(-13.040648379350017, 0.06283635869855936)
(-12.768788837867106, 0.0627414657077605)
(-12.496929296384202, 0.06257464701471209)
(-12.225069754901291, 0.06235316087418032)
(-11.953210213418387, 0.06205995644183585)
(-11.681350671935476, 0.06164932159687028)
(-11.409491130452572, 0.06106413732294054)
(-11.137631588969661, 0.06025859825559626)
(-10.865772047486757, 0.059218125758380154)
(-10.593912506003846, 0.05796879474188302)
(-10.322052964520942, 0.05657214215003382)
(-10.050193423038031, 0.055106922897218656)
(-9.77833388155512, 0.053644999900476185)
(-9.506474340072216, 0.052231205097004206)
(-9.234614798589305, 0.05087497071166143)
(-8.962755257106402, 0.0495557356631435)
(-8.69089571562349, 0.048237801582604)
(-8.419036174140587, 0.04688685367184368)
(-8.147176632657676, 0.04548117883831581)
(-7.875317091174772, 0.044014514450935294)
(-7.603457549691861, 0.04249186470277042)
(-7.331598008208957, 0.04092235254788325)
(-7.059738466726046, 0.0393134742027195)
(-6.787878925243142, 0.03766949318539168)
(-6.516019383760231, 0.035994197833888936)
(-6.24415984227732, 0.03429589578668497)
(-5.972300300794416, 0.03259120527860428)
(-5.700440759311505, 0.030904533927404994)
(-5.428581217828601, 0.029262175547531293)
(-5.15672167634569, 0.027682928162831397)
(-4.884862134862786, 0.026169535488865126)
(-4.613002593379875, 0.02470557578011672)
(-4.341143051896971, 0.023260172086468446)
(-4.06928351041406, 0.021799127615922266)
(-3.797423968931156, 0.02029790220358859)
(-3.525564427448245, 0.018751069902600576)
(-3.253704885965341, 0.017174857059627163)
(-2.98184534448243, 0.015602698679161907)
(-2.709985802999519, 0.014076468612177265)
(-2.438126261516615, 0.01263689697357968)
(-2.166266720033704, 0.01131586176838851)
(-1.8944071785508, 0.010131818660062642)
(-1.622547637067889, 0.009088561672300974)
(-1.3506880955849851, 0.008176971035822633)
(-1.0788285541020741, 0.007379039853001706)
(-0.8069690126191702, 0.0066730224962892335)
(-0.5351094711362592, 0.006038217049122166)
(-0.26324992965335525, 0.0054580872739756385)
(0.008609611829555774, 0.004921235581618104)
(0.2804691533124597, 0.004420724404616035)
(0.5523286947953707, 0.003952784447570136)
(0.8241882362782817, 0.003515762593755623)
(1.0960477777611857, 0.0031095297634107662)
(1.3679073192440967, 0.002735047682159299)
(1.6397668607270006, 0.002393735207100456)
(1.9116264022099116, 0.002086592905844755)
(2.1834859436928156, 0.0018133856968128588)
(2.4553454851757266, 0.0015722674285204863)
(2.7272050266586305, 0.0013600351293569237)
(2.9990645681415415, 0.0011728913294078399)
(3.2709241096244455, 0.001007358143673619)
(3.5427836511073565, 0.0008609314361960009)
(3.8146431925902604, 0.0007321993069101023)
(4.086502734073171, 0.0006204143192520276)
(4.3583622755560825, 0.0005247814086312176)
(4.630221817038986, 0.0004438605817209732)
.............)
};
\addplot[
name path=S,
color=red,]
coordinates {(-8.983669518808362, 8.168426471830885e-07)
(-8.801753562288608, 1.859536502224723e-06)
(-8.619837605768852, 3.94044940676042e-06)
(-8.437921649249098, 7.77921398354473e-06)
(-8.256005692729344, 1.4322432791774316e-05)
(-8.074089736209588, 2.4621298715551884e-05)
(-7.892173779689834, 3.957606800243734e-05)
(-7.71025782317008, 5.958016287984825e-05)
(-7.528341866650325, 8.416967243238451e-05)
(-7.34642591013057, 0.00011183065594377776)
(-7.164509953610816, 0.00014009532938004163)
(-6.982593997091061, 0.00016596140950969377)
(-6.800678040571306, 0.00018653909685872476)
(-6.618762084051552, 0.000199736813928316)
(-6.436846127531797, 0.00020478663126920958)
(-6.254930171012042, 0.00020247360309094385)
(-6.073014214492288, 0.00019501915460398594)
(-5.8910982579725335, 0.00018563658507737645)
(-5.7091823014527785, 0.0001778312092408758)
(-5.5272663449330235, 0.00017458772696581182)
(-5.345350388413269, 0.00017767067266827793)
(-5.163434431893514, 0.00018730015446731966)
(-4.981518475373759, 0.00020238161471916374)
(-4.799602518854005, 0.00022125966731574562)
(-4.61768656233425, 0.0002427268092853403)
(-4.435770605814495, 0.00026688409995188667)
(-4.253854649294741, 0.0002955005352321601)
(-4.071938692774986, 0.00033172055096266343)
(-3.890022736255231, 0.00037922296819117705)
(-3.708106779735477, 0.0004411384574387679)
(-3.526190823215722, 0.0005191251230454707)
(-3.344274866695968, 0.0006129577659436089)
(-3.162358910176213, 0.0007208072751246381)
(-2.980442953656458, 0.0008401136873167292)
(-2.7985269971367037, 0.0009686874041650691)
(-2.6166110406169487, 0.0011055450198407296)
(-2.4346950840971946, 0.0012511081455186875)
.......};
\addplot [name path=line] coordinates {(1.63621746301651,0)(1.63621746301651,0.15)};
\addplot[name path=alpha,red!100] fill between[of= U and line ,soft clip={domain=1.63621746301651 :\infty}];
\addplot[name path=alpha,red!100] fill between[of= S and line ,soft clip={domain=1.63621746301651 : -\infty}];
\legend{U,S}
\end{axis}
\end{tikzpicture}
\end{document}
我正在寻找红色曲线下方的阴影区域,小于乳胶中黑色垂直线指示的阈值线。
我在 \addplot 中为 U 定义了坐标。
为了遮蔽红色区域(U>阈值),我使用了以下代码行
\addplot[name path=alpha,red!100] fill between[of= U and line ,soft clip {domain=1.63621746301651 :\infty}];
但是当我尝试使用以下代码对小于阈值线的 S 曲线下的区域进行着色时
\addplot[name path=alpha,red!100] fill between[of= S and line ,soft clip {domain=1.63621746301651 : -\infty}];
答案1
使用fillbetween
,垂直填充通常比水平填充效果好得多。也就是说,您可能不应该使用您命名line
为其中一个图的垂直图来填充区域,而是添加另一个代表是= 0 并将此图命名为line
。这样,您可以轻松填充其他两个图下方的区域。然后,您可以使用选项domain
将此区域限制为X= 1.63621746301651(或您想要选择的任何值)。
我稍微缩短了你的代码并简化了曲线的坐标列表。
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Neyman Pearson Alpha Representation},
grid=major,
grid style={dashed, gray!30},
xlabel={x values},
ylabel={y values},
ymin=0, ymax=0.1,
legend pos=north west,
enlarge y limits={abs=1cm, upper}
]
\addplot[
name path=U,
color=blue,
smooth
] coordinates {
(-44.848214732850224, 6.894645067806492e-07)
(-37.50800711281171, 0.00015997575355931602)
(-20.380855999388526, 0.03299508621844504)
(-13.312507920832925, 0.0628156850968826)
(-6.380855999388526, 0.03299508621844504)
(11.50800711281171, 0.00015997575355931602)
(26.848214732850224, 6.894645067806492e-07)
};
\addplot[
name path=S,
color=red,
smooth
] coordinates {
(-8.983669518808362, 8.168426471830885e-07)
(-2.4346950840971946, 0.0012511081455186875)
(0.4346950840971946, 0.012511081455186875)
(6.4346950840971946, 0.10511081455186875)
(12.4346950840971946, 0.012511081455186875)
(14.4346950840971946, 0.0012511081455186875)
(20.983669518808362, 8.168426471830885e-07)
};
\addplot[no markers] coordinates {(1.63621746301651,0) (1.63621746301651,0.15)};
\addplot[name path=line, draw=none] {0};
\addplot[name path=alpha, red!20]
fill between[of=U and line, soft clip={domain=1.63621746301651 : 100}];
\addplot[name path=alpha, blue!20]
fill between[of=S and line, soft clip={domain=1.63621746301651 : -100}];
\legend{U,S}
\end{axis}
\end{tikzpicture}
\end{document}