ytick 等间距

ytick 等间距

我有一段代码,显示写入外部文件中的数据。但是,读取图表并不简单。因此,我希望得到一个 y 刻度上的距离不相同的图表(例如,0.6-0.7 为 1cm,0.7-0.8 为 0.2cm)。我怎样才能获得这个结果?提前致谢。

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    xlabel={Iterations},
    ylabel={$y$},
    ymin = 0.55,
    ymax = 0.85,
    ]

\addplot[color=red,mark=none] 
    table [x expr=\thisrowno{0}, y expr=\thisrowno{1}, col sep=space] {dataTeX.txt};
    
\addplot[color=blue,mark=none] 
    table [x expr=\thisrowno{0}, y expr=\thisrowno{2}, col sep=space] {dataTeX.txt};
    
\addplot[color=orange,mark=none] 
    table [x expr=\thisrowno{0}, y expr=\thisrowno{3}, col sep=space] {dataTeX.txt};
    
\addplot[color=black,mark=none] 
    table [x expr=\thisrowno{0}, y expr=\thisrowno{4}, col sep=space] {dataTeX.txt};
    
\addplot[color=yellow,mark=none] 
    table [x expr=\thisrowno{0}, y expr=\thisrowno{5}, col sep=space] {dataTeX.txt};

\addplot[color=green,mark=none] 
    table [x expr=\thisrowno{0}, y expr=\thisrowno{6}, col sep=space] {dataTeX.txt};

\addplot[color=cyan,mark=none] 
    table [x expr=\thisrowno{0}, y expr=\thisrowno{7}, col sep=space] {dataTeX.txt};

\end{axis}
\end{tikzpicture}

\end{document}

从我的代码中绘制

答案1

因此,我在手册中找不到适合您的方法的命令,因此我尝试从评论中“采用我的方法”。

\documentclass[border=10pt]{standalone}

\usepackage{pgfplots}
\usepackage{filecontents}

\usetikzlibrary{calc}

\pgfplotsset{compat=newest}

\begin{filecontents}[overwrite]{test1.dat}
    x   y
    1.7875787578757922   0.5934645808080006
    2.8136813681368196   0.6023671693011997
    4.231568611406601    0.6058869656117807
    5.276327632763277    0.6196892161126224
    5.481548154815485    0.6406480985177169
    5.686768676867693    0.6530676550801147
    5.8919891989198945   0.6657459790922912
    7.12331233123313     0.6803704159997205
    9.175517551755178    0.681567800974854
    10.201620162016205   0.6871967758573609
    10.406840684068413   0.6939234485246277
    10.612061206120615   0.7009088886416731
    10.817281728172823   0.7078943287587185
    11.330333033303333   0.7168832950710801
    12.151215121512159   0.7228298223080735
    13.690369036903697   0.7301539193755943
    15.537353735373543   0.7309691017255818
    16.46084608460847    0.7398168805644609
    16.87128712871288    0.7487417955278673
    17.48694869486949    0.7557893654533993
    19.026102610261034   0.7600435395940002
    21.28352835283529    0.7606175561376362
    23.540954095409546   0.760603464840866
    25.798379837983802   0.760589373544096
    28.055805580558058   0.7605752822473258
    30.313231323132328   0.7605611909505556
    32.570657065706584   0.7605470996537855
    34.82808280828084    0.7628383910914074
    36.26462646264628    0.7668207157794431
    36.982898289828995   0.7742989242744499
    38.009000900090015   0.7796619437224621
    39.75337533753377    0.7856262306516657
    42.010801080108024   0.785847382491058
    44.26822682268228    0.7858332911942879
    46.525652565256536   0.7858191998975178
    48.78307830783079    0.7872636160449549
    51.04050405040505    0.7899548208140528
    52.579657965796585   0.7936738168198842
    53.2979297929793     0.7990603217625133
    53.81098109810982    0.8042755960989357
    57.81278127812783    0.8069676742955194
    60.070207020702085   0.8069535829987493
    62.32763276327634    0.8069394917019791
    64.5850585058506     0.806925400405209
    66.84248424842485    0.8069113091084389
    69.09990999099911    0.8068972178116688
    71.35733573357338    0.8068831265148987
    73.61476147614763    0.8068690352181285
    75.87218721872189    0.8068549439213584
    78.12961296129615    0.8068408526245883
    80.3870387038704     0.8068267613278182
    82.64446444644466    0.806812670031048
    84.90189018901893    0.8067985787342778
    87.15931593159317    0.8067844874375077
    89.41674167416744    0.8067703961407376
    91.67416741674168    0.8067563048439674
    93.93159315931595    0.8067422135471973
    96.18901890189022    0.8067281222504272
    98.44644464446446    0.8067140309536571
    100.70387038703873   0.806699939656887
    102.96129612961298   0.8066858483601168
    105.21872187218725   0.8066717570633467
    107.47614761476149   0.8066576657665766
    109.73357335733576   0.8066435744698065
    111.99099909991  0.8066294831730363
    114.24842484248427   0.8066153918762662
    116.50585058505854   0.8066013005794961
    118.76327632763278   0.806587209282726
\end{filecontents}

\begin{filecontents}[overwrite]{test2.dat}
    x   y
    2.095409541 0.726062494
    3.531953195 0.738862515
    4.352835284 0.749898136
    5.071107111 0.752179431
    5.276327633 0.757871034
    5.481548155 0.764080172
    5.686768677 0.77028931
    7.03210321  0.781005385
    8.765076508 0.782432165
    9.585958596 0.790190064
    10.86288629 0.797772605
    13.27992799 0.797930029
    15.61431143 0.798788797
    17.79477948 0.805923637
    20.05220522 0.806168313
    22.30963096 0.806154222
    24.56705671 0.806140131
    26.82448245 0.80612604
    29.08190819 0.806111948
    31.33933393 0.806097857
    33.59675968 0.806083766
    35.85418542 0.806069674
    38.11161116 0.806055583
    40.3690369  0.806041492
    42.62646265 0.8060274
    44.88388839 0.806013309
    47.14131413 0.805999218
    49.39873987 0.805985127
    51.65616562 0.805971035
    53.91359136 0.805956944
    56.1710171  0.805942853
    58.42844284 0.805928761
    60.68586859 0.80591467
    62.94329433 0.805900579
    65.20072007 0.805886488
    67.45814581 0.805872396
    69.71557156 0.805858305
    71.9729973  0.805844214
    74.23042304 0.805830122
    76.48784878 0.805816031
    78.74527453 0.80580194
    81.00270027 0.805787848
    83.26012601 0.805773757
    85.51755176 0.805759666
    87.7749775  0.805745575
    90.03240324 0.805731483
    92.28982898 0.805717392
    94.54725473 0.805703301
    96.80468047 0.805689209
    99.06210621 0.805675118
    101.319532  0.805661027
    103.5769577 0.805646935
    105.8343834 0.805632844
    108.0918092 0.805618753
    110.3492349 0.805604662
    112.6066607 0.80559057
    114.8640864 0.805576479
    117.1215122 0.805562388
    119.0711071 0.805550218
\end{filecontents}

\begin{filecontents}[overwrite]{test3.dat}
    x   y
    1.6849684968496845   0.7640715251300411
    2.91629162916292     0.7730236619167534
    4.681188118811882    0.775988470757188
    5.3546354635463445   0.7799611140889371
    5.626012601260122    0.7853106855629384
    6.558955895589563    0.7913611390031459
    7.283168316831755    0.7941377036580062
    7.671467146714782    0.797079781011809
    8.32043204320432     0.8004138553680586
    9.175517551755178    0.8005433239953208
    11.43294329432944    0.8005292326985507
    13.804380438043808   0.8009169568642257
    14.716471647164724   0.802084688404635
    16.39333933393339    0.8029343973212438
    18.205220522052215   0.8028975818930207
    20.46264626462647    0.8028834905962506
    22.720072007200727   0.8024948674642745
    24.977497749774983   0.8024807761675044
    27.23492349234924    0.8024666848707342
    29.492349234923495   0.8024525935739641
    31.749774977497765   0.8024385022771939
    34.00720072007202    0.8024244109804238
    36.26462646264628    0.8024103196836537
    38.52205220522053    0.802623630085174
    40.77947794779479    0.8038369301690128
    43.036903690369044   0.8067211581219409
    45.2943294329433     0.8070458169412447
    47.551755175517556   0.8070317256444746
    49.809180918091826   0.8070176343477043
    52.06660666066608    0.8070035430509342
    54.32403240324034    0.8069894517541641
    56.581458145814594   0.8074928953569513
    58.83888388838885    0.8079963389597387
    61.096309630963106   0.8080410584470091
    63.446084608460865   0.8138397851021056
    65.61116111611163    0.8139057164143381
    67.86858685868589    0.8138916251175679
    70.12601260126014    0.8138775338207977
    72.3834383438344     0.8138634425240276
    74.64086408640865    0.8138493512272575
    76.89828982898291    0.8138352599304874
    79.15571557155717    0.8138211686337172
    81.41314131413144    0.8138070773369471
    83.67056705670569    0.813792986040177
    85.92799279927993    0.8137788947434069
    88.1854185418542     0.8137648034466367
    90.44284428442847    0.8137507121498666
    92.70027002700272    0.8135876335335269
    94.8721872187219     0.8141891473791574
    97.21512151215123    0.8139651834437784
    99.4725472547255     0.8140670216153382
    101.72997299729974   0.813680255666016
    103.98739873987401   0.8136661643692459
    106.24482448244828   0.8136520730724758
    108.50225022502252   0.8136379817757056
    110.75967596759679   0.8136238904789355
    113.01710171017103   0.8136097991821654
    115.2745274527453    0.8135957078853953
    117.53195319531955   0.813581616588625
    119.37893789378941   0.8135700873458132
\end{filecontents}

\def\ycut{0.75}
\def\height{8cm}
\def\fac{0.25}

\begin{document}
    
    \begin{tikzpicture}
        
        \begin{axis}[% only for the axis labels
                width=8cm,
                height=\height,
                scale only axis=true,
                axis line style={draw=none},
                tick style={draw=none},
                xticklabel style={text opacity=0},
                yticklabel style={text opacity=0},
                xlabel={Iterations},
                ylabel={$y$},
            ]
            addplot[
                draw=none,
            ]
        \end{axis}
        
        \begin{axis}[
                name=a,
                width=8cm,
                height=\fac*\height,
                scale only axis=true,
                xmin=0,
                xmax=120,
                ymin=0.55,
                ymax=\ycut,
                enlarge x limits=0.1,
                minor y tick num=4,
                enlarge y limits={value=0.1, lower},
                ytick distance=0.1,
                axis x line*=left
            ]
            \addplot[
                red
            ] table {test1.dat};
            
            \addplot[
                blue,
            ] table {test2.dat};
            
            \addplot[
                orange,
            ] table {test3.dat};
        \end{axis}
    
        \begin{axis}[
            at={($(a.north)$)},
            anchor=south,
            width=8cm,
            height=(1-\fac)*\height,
            scale only axis=true,
            xmin=0,
            xmax=120,
            ymin=\ycut,
            ymax=0.85,
            enlarge x limits=0.1, 
            enlarge y limits={value=0.1, upper},            
            ytick distance=0.1,
            minor y tick num=4,
            axis x line*=right,
            xticklabels={,,}, 
            ]
            \addplot[
            red
            ] table {test1.dat};
            
            \addplot[
            blue,
            ] table {test2.dat};
            
            \addplot[
            orange,
            ] table {test3.dat};
        \end{axis}
            
    \end{tikzpicture}
    
\end{document}

在此处输入图片描述

您可以尝试使用这两个图表的height因子\fac以及\ycut我定义的值(如果它适合您的需要)。

相关内容