改变 x 轴时出现奇怪的行为

改变 x 轴时出现奇怪的行为

我在绘制带有阴影标准偏差的光谱图时遇到了问题。当我更改 x 轴时,整个图都会移动。当我注释该命令时,问题不会发生fillbetween

.tex 文件生成以下图:

\documentclass[border=5pt,tikz]{standalone}

\usepackage{siunitx}
\DeclareSIUnit\wn{\cm\tothe{-1}}

\usepackage{pgfplots}

\pgfplotsset{
    compat=newest,
    every tick label/.append style={font=\small},
    every axis label/.append style={font=\large},
    every axis/.append style={
        line width=0.5pt,
        /pgf/number format/.cd,
        1000 sep={\,},
        fixed, 
        fixed zerofill, 
        precision=0,
        /tikz/.cd,  
    },
    plot/.style={
        scale only axis=true, 
        scale=\sc, 
    },
}

\usepgfplotslibrary{fillbetween}
\usetikzlibrary{calc}

\begin{filecontents}[overwrite]{test.txt}
    1798.4659   -623.74385  25.02907    1529.28699  526.19624
    1794.9556   -824.69024  109.88828   2466.0702   947.84577
    1791.4446   232.28997   208.95093   2950.31435  1195.23253
    1787.9329   637.87702   129.32749   2318.68689  508.95173
    1784.4204   671.70455   5.66989 694.03919   139.90193
    1780.9073   680.23565   1263.64017  -98.31002   3.59483
    1777.3937   435.4566    323.12696   234.94493   312.73434
    1773.8793   364.06563   225.12514   -243.96275  425.04961
    1770.3643   1541.3548   210.53594   341.36613   844.63141
    1766.8485   1622.80397  1220.35489  213.45418   224.43378
    1763.3322   403.11491   1451.66363  -447.01252  61.99557
    1759.8152   -299.69626  1084.95254  -305.17535  18.60067
    1756.2932   345.51488   706.07757   -158.79893  46.52245
    1752.7749   826.30086   465.49932   262.27365   132.95934
    1749.2559   760.56702   398.97423   112.96787   585.50746
    1745.7319   675.62063   313.42367   -268.05235  551.12506
    1742.2115   848.51027   89.44034    -278.56652  15.33996
    1738.6904   741.56728   398.44219   -780.59223  962.44612
    1735.1646   226.04409   742.06927   -131.09094  632.906
    1731.6422   709.8435    228.89424   -325.1798   1243.35952
    1728.1191   574.94586   374.58018   -479.3193   198.65009
    1724.5912   -249.22314  10.00062    -428.55986  49.40305
    1721.0626   -598.97896  429.44412   -574.07206  213.36102
    1717.5375   -315.6156   556.63195   -857.69492  435.60639
    1714.0118   -342.74989  897.23513   -1177.37619 885.51123
    1710.4812   -787.91201  103.86753   -1694.15508 1724.69927
    1706.95 700.08488   1289.83041  -1870.87529 1380.23194
    1703.4221   296.71034   272.57398   -1659.81962 695.72217
    1699.8895   -168.71538  276.45206   -1419.50491 57.31659
    1696.3605   -190.18309  73.70346    -1168.01523 394.41275
    1692.8265   -1029.59181 125.35351   -892.24296  45.16138
    1689.2919   -615.03288  114.76616   -1241.64015 434.94018
    1685.7565   -781.9989   687.41408   -1948.77215 654.8101
    1682.2206   -1342.65663 221.59928   -2028.84726 734.30428
    1678.6838   -1298.64373 52.11089    -2297.40831 1187.30743
    1675.1508   308.98957   458.42056   -2676.35528 473.97259
    1671.6128   1368.2934   14.90204    -3223.43235 79.57228
    1668.0741   2674.19376  478.0271    -3250.55654 374.71409
    1664.5348   5469.28532  1518.01064  -2599.06204 254.17894
    1660.9948   10152.1124  2552.82059  -2784.97822 1502.50968
    1657.454    14899.25395 1.06285 -2644.85824 552.39092
    1653.9127   27730.50679 5663.09526  -2048.70457 1203.4249
    1650.3706   44097.38373 1288.06856  -1111.61501 4.53725
    1646.8279   57569.12734 10277.93052 -809.44069  144.49123
    1643.2845   68312.71643 21910.28609 -166.45737  202.66277
    1639.7405   70038.23058 28516.65634 361.61935   156.84022
    1636.1915   65396.29585 24470.32252 2089.34616  14.20975
    1632.6461   56736.2807  15128.34758 4256.29571  345.91244
    1629.1  53556.41146 10306.53944 9266.82951  567.15737
    1625.5532   55575.07421 12658.95053 20492.07308 1933.82826
    1622.0057   60365.15523 20413.90762 41062.45581 6569.56471
    1618.4576   62005.67799 27088.35875 70882.50816 11155.35544
    1614.9047   60703.4824  26615.24106 93862.62855 7750.769
    1611.3551   56980.51285 23452.55433 94041.27427 1852.32409
    1607.8008   52853.13208 20388.6033  74280.66758 5352.03094
    1604.2499   50832.2577  18744.06677 47831.67093 4122.26813
    1600.6984   51129.58444 18689.40569 29457.97127 969.00226
    1597.142    47857.73211 18547.72651 19976.95122 447.55585
    1593.5848   41628.88906 14746.15815 16182.90608 137.94403
    1590.0314   32932.8982  8320.45457  16137.20566 833.43019
    1586.4772   25063.14472 3799.94925  18230.02742 2199.95811
    1582.918    18979.35647 628.74093   19386.45827 1734.39845
    1579.3582   15658.64839 2620.63863  16200.1976  558.27407
    1575.8019   14775.32773 3850.31311  11088.14056 5.66107
    1572.2407   15713.77447 4028.6787   7047.59672  518.82266
    1568.679    16703.20587 3373.08483  3632.02943  243.73827
    1565.1206   20757.2483  4812.09836  1590.1334   266.91618
    1561.5574   22683.23032 4297.09756  42.80407    344.5761
    1557.9935   19295.45794 4853.03929  -630.14836  552.99109
    1554.4332   13649.46669 4133.75514  -870.28908  531.54635
    1550.8679   9708.20345  4771.30336  -634.39505  537.05443
    1547.302    6744.26649  4056.40407  -223.51008  606.63128
    1543.7354   3925.13863  1696.07448  190.43011   275.37285
    1540.1681   1728.80524  1632.59078  0   0
    1536.6001   1883.14513  477.62546   0   0
    1533.0314   1208.56018  518.99081   304.57863   112.11687
    1529.4663   364.49458   486.78376   782.9811    105.54812
    1525.8921   -830.27427  33.31655    715.157 1.45141
    1522.3256   -369.52025  35.09889    526.4361    167.69449
    1518.75 -1306.96214 52.44469    19.73639    453.8173
    1515.1779   -223.65441  559.23495   -225.47231  150.93917
    1511.6051   -232.02024  538.36008   -114.74659  159.44486
    1508.0316   617.4249    989.93618   0   0
    1504.4575   3840.99532  352.5673    0   0
    1500.8827   8334.40679  1566.39629  292.4799    124.05464
    1497.3073   15152.5194  1466.82853  1948.5312   201.8396
    1493.7268   21261.69491 604.40944   3205.73418  983.00276
    1490.1499   25432.89417 1966.85912  3420.88132  576.93501
    1486.5724   23428.05091 1181.46604  2640.98065  96.49173
    1482.9941   18298.41337 453.42954   873.80663   471.1124
    1479.4109   12104.79892 1474.56398  -490.60048  409.25714
    1475.8313   7143.90347  553.85617   -839.37715  260.31857
    1472.251    5448.02528  383.74223   -1574.40291 612.82636
    1468.6658   4904.29928  2340.46225  -2794.68625 2133.31957
    1465.0841   3083.73166  1328.59469  -3897.77113 3542.92103
    1461.4974   2507.64932  113.31538   -2870.27836 4538.03544
    1457.9144   1924.6963   103.19243   -742.96868  3093.95777
    1454.3264   1046.25208  61.62433    2423.26316  2078.27191
    1450.7421   -200.03885  28.68756    5410.28565  3397.92619
    1447.1527   434.10301   289.64289   7416.69602  3572.39837
    1443.5669   -739.22654  29.66307    7214.45357  2701.02629
    1439.9761   273.28579   183.98044   5110.65012  2596.83975
    1436.3846   1986.24752  78.27012    5066.40912  3127.49298
    1432.7969   4883.29261  96.15606    9228.5564   2408.82528
    1429.204    10734.5344  809.13883   14221.14436 378.93326
    1425.6105   15000   0   15000   0
    1422.0206   14159.40716 268.60537   11156.17223 467.59962
    1418.4257   9423.14782  517.41428   5621.6493   163.19462
    1414.8301   4876.43767  114.57053   727.31314   689.16731
    1411.2339   4243.7837   63.62025    -1795.03777 837.389
    1407.637    4830.34164  329.76782   -3367.85811 388.23625
    1404.0393   6619.59576  1549.16449  -4672.97235 344.41188
    1400.4452   9508.79891  2690.19106  -6245.55209 731.23698
    1396.8462   14552.58054 1237.88968  -5847.74044 980.26109
    1393.2465   20827.45884 3158.86603  -3496.37594 183.47952
    1389.646    26602.41099 359.76796   -13.95387   387.51491
    1386.0449   28908.84526 397.40987   3097.99486  778.58628
    1382.4431   31709.79995 470.96612   6356.85825  116.66565
    1378.8407   29752.53115 2992.49737  10893.71804 920.03495
    1375.2374   27742.08763 6100.078    19411.10092 3619.85386
    1371.6293   24683.87391 3490.62909  33041.38462 5431.17979
    1368.0248   19981.5581  1002.9945   41637.82752 1940.66405
    1364.4194   11919.82645 368.29042   37738.29176 893.42675
    1360.8135   7087.49865  204.2053    23242.99092 1572.58367
    1357.2069   4214.82745  267.93847   9573.21266  314.93336
    1353.5952   4113.95513  6.05779 2481.81235  855.29846
    1349.9872   4376.10854  1053.40719  -1012.23545 487.86664
    1346.3784   6114.46415  959.15114   -2265.24165 124.72093
    1342.769    4933.17618  493.87231   -2410.9676  742.30486
    1339.1547   3819.0424   382.84138   -1443.95195 1125.46094
    1335.5438   3126.35908  503.03036   -207.54973  1550.30297
    1331.928    3290.10945  272.62247   928.11192   843.53531
    1328.3158   3386.14072  1786.77599  681.23548   80.23111
    1324.7029   2989.29567  568.2526    -2013.79476 1654.4116
    1321.085    1570.33944  471.03572   -4776.87339 1339.37076
    1317.4707   134.26811   100.06964   -8517.08024 281.30395
    1313.8514   -242.15598  276.63834   -12594.5119 3009.37581
    1310.2357   -528.97759  317.60973   -12809.74798    5526.61212
    1306.615    -787.53023  31.60136    -9242.59828 3730.9549
    1302.9937   -804.70611  247.7911    -9029.10803 253.11771
    1299.3759   -1931.17585 28.71261    -11754.15516    1635.12889
    1295.7531   -342.97436  1461.49515  -11133.11172    670.6443
    1292.1296   1773.79967  8.03523 -7111.41309 239.39615
    1288.5098   5826.23807  1391.15906  -4465.27268 546.18976
    1284.8849   10196.17348 404.95672   -1897.21499 269.99392
    1281.2593   12019.77419 713.33927   139.66025   197.76992
    1277.6331   10886.16394 913.15666   1314.94656  292.08234
    1274.006    7330.35358  682.61827   1003.65886  72.34462
    1270.3827   4640.96414  144.64909   354.54328   181.70232
    1266.7543   4357.72126  695.11371   516.28905   331.6909
    1263.1252   3770.63249  242.36049   393.21254   70.19972
    1259.4955   2678.83799  192.29817   762.43141   265.25595
    1255.865    1900.03877  302.50987   2461.26253  682.14067
    1252.2338   2492.58377  557.67403   4331.29651  1103.18487
    1248.6019   3631.14013  1608.61257  4694.29225  567.09107
    1244.9694   3476.47631  1905.81419  3791.62252  514.69396
    1241.3361   1814.88027  70.17796    2362.67614  152.87874
    1237.702    1222.20293  1683.4062   1611.66777  540.73006
    1234.0674   720.1254    720.67952   1931.90424  160.17191
    1230.4276   828.58798   191.94851   1478.87624  446.23699
    1226.7915   213.85171   992.32168   -1084.93453 613.88291
    1223.1548   3717.64053  345.18059   -4079.67705 1754.73677
    1219.5172   4986.65178  543.0797    -5162.225   1223.31031
    1215.879    5738.15714  423.45918   -5476.86542 87.89517
    1212.2358   3383.23933  992.74841   -5583.03796 141.88782
    1208.5962   1906.00327  48.91931    -3879.51356 55.57572
    1204.9559   -159.84881  203.95267   -793.02928  644.72282
    1201.3105   -389.52782  175.70855   439.75481   141.61519
    1197.6688   -382.69033  939.20488   809.27052   582.70092
    1194.0264   326.21  1179.17987  242.93351   106.3117
    1190.3789   -262.28987  1182.90392  264.63062   626.36707
    1186.7351   279.28801   116.32818   -275.5403   333.38138
    1183.0863   2867.41919  1014.12927  46.26977    195.65058
    1179.441    9574.04617  1940.25064  1306.19294  170.67179
    1175.7908   15830.25954 1539.99199  2836.40134  127.63131
    1172.1398   17526.26219 1599.08472  3866.50452  1207.00835
    1168.4923   13204.71078 18.45895    3030.14934  726.39365
    1164.8442   7933.80954  524.41527   1188.43678  132.06236
    1161.1912   3290.61819  743.46113   151.87244   436.84001
    1157.5374   1018.0179   80.99595    -675.56651  77.87722
    1153.8828   -132.85811  480.96943   -1195.08271 137.76543
    1150.2319   293.14199   407.48701   -1045.23744 1.65628
    1146.5759   716.54089   354.07074   -1330.10049 481.06977
    1142.9237   1451.22391  719.83604   -1626.39953 97.81202
    1139.2664   1390.32137  874.67633   -2109.11123 198.78157
    1135.6083   1606.15648  233.80701   -3870.21135 566.67244
    1131.9495   570.39266   884.55452   -6141.19689 1982.60368
    1128.2899   1089.15587  205.83905   -7508.21968 758.41828
    1124.6298   2609.81481  497.4811    -7438.65778 184.65687
    1120.9689   4283.54175  95.5083 -6621.46031 173.28413
    1117.3073   5650.58696  233.69327   -5693.73641 713.57065
    1113.6449   9196.31258  1776.9756   -6093.65412 336.15471
    1109.9818   9233.72367  1137.71298  -7439.4857  559.36363
    1106.3181   10308.32291 1247.00913  -7836.47749 49.89815
    1102.6537   12446.17065 720.39761   -6615.77159 62.03557
    1098.9884   16322.51853 117.83288   -4297.13859 561.55112
    1095.3225   20087.47566 737.44223   -907.98949  80.76084
    1091.656    23102.305   833.48066   3936.9039   1610.38971
    1087.9886   20047.21194 158.37251   13167.04244 4468.15837
    1084.3207   12967.61848 687.66394   26332.06479 5311.68554
    1080.6519   7781.58488  43.96993    38537.82924 1598.98098
    1076.9824   4395.17528  1020.45186  41496.55844 2030.66058
    1073.3079   2522.11436  953.91574   31093.90656 1658.43405
    1069.6371   1066.15963  534.30587   16374.20842 57.67218
    1065.9611   876.99651   1056.54982  7784.20278  916.9199
    1062.2888   440.19658   151.91431   3848.41381  890.71867
    1058.6157   -209.0842   427.02372   1063.17769  43.13983
    1054.942    -161.95319  789.53431   -502.28364  813.34161
    1051.2632   79.66891    2149.87237  -987.30926  611.39808
    1047.5881   -482.61938  284.42118   -1309.21286 78.90923
    1043.9078   -135.70322  8.34872 -1593.74662 61.76356
    1040.2312   74.23992    110.06811   -1527.98463 133.90726
    1036.554    227.77937   286.49194   -1205.93799 774.68541
    1032.8716   228.69232   437.12421   -1899.55928 2032.71061
    1029.1885   102.80888   407.74406   -3506.5186  1326.31978
    1025.509    613.74321   197.44265   -6064.11727 2614.83304
    1021.8245   1435.47453  17.15441    -6401.61831 5011.7163
    1018.1392   1390.11212  98.24909    -3486.04096 3119.81697
    1014.4576   863.20033   568.58806   -3301.17686 352.61457
    1010.7709   1185.6098   181.19108   -5810.94222 460.71769
    1007.0835   276.90759   647.94764   -6258.81962 233.83348
    1003.3998   -26.66717   1347.37267  -4403.08281 229.32629
    999.71094   -128.99904  1187.34679  -2625.0489  38.23089
    996.02136   -891.80675  1077.79829  -2094.6836  36.81013
    992.33545   -586.82852  624.34372   -2273.78219 760.68148
    988.64447   33.57161    264.39998   -1857.99901 465.26411
    984.95276   -225.98294  1172.78481  -1388.46702 93.82802
    981.26031   -869.35866  185.16974   -1162.21753 469.58317
    977.56714   -208.40674  31.28653    -774.52257  98.02012
    973.87323   -1163.76517 13.85567    -152.75026  207.42374
    970.17865   -365.55693  114.76047   445.97928   248.9721
    966.48334   78.54008    96.2782 992.88975   432.25628
    962.78729   42.26272    537.97036   932.68742   566.83883
    959.09052   722.46421   765.98457   763.78594   78.39061
    955.39307   695.53559   256.73706   493.37087   106.43895
    951.69482   195.52276   411.29681   -33.31821   3.84082
\end{filecontents}

\begin{document}
    
    \def\height{16cm}
    \def\widtha{9cm}
    \def\sc{0.8}
    
    \def\enlarge{0.05}
    
    \begin{tikzpicture}
        \begin{axis}[
            plot,
            width=\widtha/2,
            height=\height/2,
            enlarge x limits=0,
            enlarge y limits=\enlarge,
            xtick pos=right,
            xmin=1000,
            xmax=1675,
            x dir=reverse,
            xlabel=Wavenumber\,/\,\si{\wn},
            ytick pos=left,
            ytick=\empty,
            ylabel=Raman Intensity,
            ]
            
            \addplot[
            color=black,
            smooth
            ] 
            table[
            x index=0, 
            y index=1,
            ]{test.txt};
            
            \addplot[
            name path=upper,
            draw=none,
            ] 
            table[
            x index=0, 
            y expr=\thisrowno{1}+\thisrowno{2},
            ] 
            {test.txt};
            
            \addplot[
            name path=lower,
            draw=none,
            ] 
            table[
            x index=0, 
            y expr=\thisrowno{1}-\thisrowno{2},
            ] 
            {test.txt};
            
            \addplot[
            fill=gray,
            fill opacity=0.5,
            ] 
            fill between[of=upper and lower];
        \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

当我发表评论x dir=reverse

\addplot[
fill=gray,
fill opacity=0.5,
] 
fill between[of=upper and lower];

在此处输入图片描述 在此处输入图片描述

图表居中。 对此现象有解释和解决方案吗?

相关内容