为散点图/类中的每个元素绘制一条线

为散点图/类中的每个元素绘制一条线

我试图在散点图/类中为每个元素绘制一条线。理想情况下,它们应该有不同的颜色。

在这个例子中,有十个类,我想要九条彩色曲线,如标题所示。

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{plotmarks}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{filecontents*}{filecontents.csv}
mean,stddev,median,user,system,min,max,n,t,r
2.008092247565,0.001087585216913954,2.008002622285,0.021047700000000003,0.0051199606,2.006615163285,2.012364370285,2,1,5
3.0092475998800006,0.0011119293738394002,3.0087962747,0.029635970000000008,0.007455080000000002,3.0079635402,3.0120335862,3,1,5
3.009657125220001,0.0014051182788529148,3.0091736014199997,0.029385879999999996,0.008148095000000001,3.00789867092,3.0131954559199996,3,2,5
4.010933870295,0.0014804202526725325,4.010527780015,0.03897642,0.009461579999999999,4.009004758515,4.015295604515,4,1,5
4.01095771945,0.0015411458179162858,4.01051793343,0.038820314999999994,0.010681065,4.00907385293,4.01468278693,4,2,5
4.010423219970001,0.0011914175555101467,4.01002213093,0.036505985,0.010067645,4.00848401143,4.01468200943,4,3,5
5.01189980022,0.00130892180457241,5.01149291194,0.04706429,0.011598624199999994,5.0102514209399995,5.0156495009399995,5,1,5
5.012793391085,0.0017630092289779983,5.012443131185,0.04824636,0.014132129999999996,5.010009091685,5.016379435685,5,2,5
5.01346880715,0.0016961782636583428,5.0135436990499995,0.051351344999999986,0.013781419999999999,5.01001740255,5.01666681255,5,3,5
5.0125773417,0.0017173680217098114,5.0120461432,0.050153514999999996,0.011895550000000003,5.0100804527000005,5.0167439507000005,5,4,5
6.013640137535,0.0017640378311829458,6.013287469494999,0.05536934999999999,0.016442540000000002,6.011432350495,6.019071272495,6,1,5
6.013137843930001,0.0014049666022598961,6.012586741770001,0.05605525499999998,0.014017554999999998,6.01157240327,6.01691386127,6,2,5
6.013372380889999,0.0014916799584052546,6.01300357289,0.05362076000000001,0.016098724999999994,6.01118277189,6.01786910389,6,3,5
6.01356207849,0.0014270627869483376,6.013096740709999,0.05555249999999999,0.015190229999999997,6.01129317121,6.01762949621,6,4,5
6.013180781829999,0.0012654663948215355,6.0130248994699995,0.0544803,0.015670395000000004,6.01124026597,6.0163047359699995,6,5,5
7.0149673690600025,0.001641566212137983,7.014565445460001,0.064408525,0.01737631,7.01266992896,7.01925683396,7,1,5
7.014343266240001,0.0013608570730209945,7.01403616962,0.061554205,0.01746008,7.01260768862,7.02008403662,7,2,5
7.014957824979998,0.0016859511064958356,7.01461191506,0.064209685,0.019271975,7.01211387906,7.01957184206,7,3,5
7.014603061509999,0.0013785078078528776,7.01425674397,0.064576635,0.016701135,7.01226260347,7.01757403247,7,4,5
7.015185146634996,0.0016160238550951204,7.015159473635,0.06665530500000001,0.017239904999999996,7.012504467135,7.019346203135,7,5,5
7.016321671679998,0.0018257294905606402,7.0164876849199995,0.069555245,0.019561255000000003,7.01266289142,7.02002902142,7,6,5
8.01722143777,0.0015808878786387716,8.01687450607,0.07687362499999997,0.02115376,8.014599713070002,8.02160258207,8,1,5
8.017338989005001,0.0019667505145061948,8.017170430965,0.07660683999999998,0.022300240000000002,8.014046813465,8.022698922465,8,2,5
8.017430533575,0.0017863157834973132,8.017405223055,0.07785173000000001,0.022732635,8.013845867055,8.021215049055,8,3,5
8.017248874495,0.0016172120409783687,8.017181047495,0.07551743000000002,0.023571455,8.014349677495,8.020100200495,8,4,5
8.017125246844998,0.0016989561778296377,8.016791746524998,0.07709600500000001,0.020179879999999994,8.014066074025,8.022991737024999,8,5,5
8.016930801585,0.0016642105818595,8.016852367224999,0.07540103499999999,0.023147999999999995,8.013887378724998,8.020411152725,8,6,5
8.016520918315,0.001654337096663089,8.016328431995,0.07529221999999999,0.02118175999999999,8.013148344494999,8.019839532495,8,7,5
9.016799249670001,0.0015718462211550999,9.01659279673,0.081049745,0.019341719999999996,9.01438055473,9.020618206730001,9,1,5
9.017018194054998,0.0014350300009393824,9.016908835395,0.078868215,0.022682285000000003,9.014823156395,9.021151249395,9,2,5
9.01726332741,0.002115676906681981,9.01658689167,0.080441425,0.021180010000000006,9.01496449417,9.02648660917,9,3,5
9.016763639119999,0.001512952945413639,9.01633446806,0.07937265,0.021857389999999994,9.01460193756,9.020248113560001,9,4,5
9.017349750035002,0.0017003842661876519,9.017002786995,0.08172369499999999,0.022520850000000002,9.014962139995001,9.022972700995,9,5,5
9.017306100565,0.0017584685970845099,9.017007012425,0.07975570499999997,0.02273486999999999,9.014567779924999,9.024597107924999,9,6,5
9.017007630905,0.0015125437139633618,9.016584779425,0.07929927499999999,0.021604699999999998,9.015123699924999,9.023345937924999,9,7,5
9.0188481787,0.002038130740157264,9.018710005199999,0.08872810999999999,0.02333252,9.015418677200001,9.0229693742,9,8,5
10.020097456779999,0.0020732834110187407,10.020212923159999,0.10054147499999999,0.027472845000000006,10.01639936466,10.024513922659999,10,1,5
10.020701272595,0.0022119896198483815,10.021010574275,0.09928061999999999,0.026462539999999993,10.016149150775,10.024349466775,10,2,5
10.020294442275002,0.0018471010390020766,10.019912748375,0.09662063499999998,0.029709829999999996,10.016893148375,10.025330058375001,10,3,5
10.020971053870001,0.002209195030397343,10.02079165515,0.09821629999999999,0.028191004999999998,10.01684321365,10.024464921649999,10,4,5
10.02147153793,0.0020951036709112854,10.021724447249998,0.09956617999999995,0.030633655000000003,10.017308507749998,10.025903988749999,10,5,5
10.020853486755001,0.002387481522172249,10.020695327635,0.10029417,0.027966095000000007,10.016340242635001,10.029198219635001,10,6,5
10.018751216420002,0.0019698224247626578,10.018146075059999,0.08825113500000002,0.025826920000000003,10.016164508060001,10.02565086006,10,7,5
10.018302961014996,0.0015231888831009253,10.018166453534999,0.089845875,0.022562924999999998,10.015884921535,10.022615320535,10,8,5
10.618139131275001,0.0012810901522741483,10.018190750015,0.08894370999999998,0.02330762499999999,10.015776271015,10.021069502015001,10,9,5

\end{filecontents*}
\begin{tikzpicture}
\begin{axis}[xlabel=t,ylabel=mean,,legend pos=outer north east, xtick={1,...,10}]
   \addplot[
        % clickable coords={\thisrow{n}}, 
        scatter/classes={
            2={mark=square*,blue},%
            3={mark=triangle*,red},%
            4={mark=o,draw=black,fill=black},%
            5={mark=asterisk,red},%
            6={mark=pentagon*,green},%
            7={mark=x,draw=black,fill=cyan},%
          8={mark=oplus,blue},%
            9={mark=otimes*,yellow},%
            10={mark=diamond*,draw=black,fill=violet}%
        },
        scatter,
        scatter src=explicit symbolic]
    table[x=t,y=mean,meta=n, col sep=comma]
            {filecontents.csv};
\legend{$n=2$,$n=3$,$n=4$,$n=5$,$n=6$,$n=7$,$n=8$,$n=9$,$n=10$} 
\end{axis}
\end{tikzpicture}
\end{document}

所有散点图类别均有一条黑线

答案1

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{plotmarks}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{filecontents*}{filecontents.csv}
mean,stddev,median,user,system,min,max,n,t,r
2.008092247565,0.001087585216913954,2.008002622285,0.021047700000000003,0.0051199606,2.006615163285,2.012364370285,2,1,5
3.0092475998800006,0.0011119293738394002,3.0087962747,0.029635970000000008,0.007455080000000002,3.0079635402,3.0120335862,3,1,5
3.009657125220001,0.0014051182788529148,3.0091736014199997,0.029385879999999996,0.008148095000000001,3.00789867092,3.0131954559199996,3,2,5
4.010933870295,0.0014804202526725325,4.010527780015,0.03897642,0.009461579999999999,4.009004758515,4.015295604515,4,1,5
4.01095771945,0.0015411458179162858,4.01051793343,0.038820314999999994,0.010681065,4.00907385293,4.01468278693,4,2,5
4.010423219970001,0.0011914175555101467,4.01002213093,0.036505985,0.010067645,4.00848401143,4.01468200943,4,3,5
5.01189980022,0.00130892180457241,5.01149291194,0.04706429,0.011598624199999994,5.0102514209399995,5.0156495009399995,5,1,5
5.012793391085,0.0017630092289779983,5.012443131185,0.04824636,0.014132129999999996,5.010009091685,5.016379435685,5,2,5
5.01346880715,0.0016961782636583428,5.0135436990499995,0.051351344999999986,0.013781419999999999,5.01001740255,5.01666681255,5,3,5
5.0125773417,0.0017173680217098114,5.0120461432,0.050153514999999996,0.011895550000000003,5.0100804527000005,5.0167439507000005,5,4,5
6.013640137535,0.0017640378311829458,6.013287469494999,0.05536934999999999,0.016442540000000002,6.011432350495,6.019071272495,6,1,5
6.013137843930001,0.0014049666022598961,6.012586741770001,0.05605525499999998,0.014017554999999998,6.01157240327,6.01691386127,6,2,5
6.013372380889999,0.0014916799584052546,6.01300357289,0.05362076000000001,0.016098724999999994,6.01118277189,6.01786910389,6,3,5
6.01356207849,0.0014270627869483376,6.013096740709999,0.05555249999999999,0.015190229999999997,6.01129317121,6.01762949621,6,4,5
6.013180781829999,0.0012654663948215355,6.0130248994699995,0.0544803,0.015670395000000004,6.01124026597,6.0163047359699995,6,5,5
7.0149673690600025,0.001641566212137983,7.014565445460001,0.064408525,0.01737631,7.01266992896,7.01925683396,7,1,5
7.014343266240001,0.0013608570730209945,7.01403616962,0.061554205,0.01746008,7.01260768862,7.02008403662,7,2,5
7.014957824979998,0.0016859511064958356,7.01461191506,0.064209685,0.019271975,7.01211387906,7.01957184206,7,3,5
7.014603061509999,0.0013785078078528776,7.01425674397,0.064576635,0.016701135,7.01226260347,7.01757403247,7,4,5
7.015185146634996,0.0016160238550951204,7.015159473635,0.06665530500000001,0.017239904999999996,7.012504467135,7.019346203135,7,5,5
7.016321671679998,0.0018257294905606402,7.0164876849199995,0.069555245,0.019561255000000003,7.01266289142,7.02002902142,7,6,5
8.01722143777,0.0015808878786387716,8.01687450607,0.07687362499999997,0.02115376,8.014599713070002,8.02160258207,8,1,5
8.017338989005001,0.0019667505145061948,8.017170430965,0.07660683999999998,0.022300240000000002,8.014046813465,8.022698922465,8,2,5
8.017430533575,0.0017863157834973132,8.017405223055,0.07785173000000001,0.022732635,8.013845867055,8.021215049055,8,3,5
8.017248874495,0.0016172120409783687,8.017181047495,0.07551743000000002,0.023571455,8.014349677495,8.020100200495,8,4,5
8.017125246844998,0.0016989561778296377,8.016791746524998,0.07709600500000001,0.020179879999999994,8.014066074025,8.022991737024999,8,5,5
8.016930801585,0.0016642105818595,8.016852367224999,0.07540103499999999,0.023147999999999995,8.013887378724998,8.020411152725,8,6,5
8.016520918315,0.001654337096663089,8.016328431995,0.07529221999999999,0.02118175999999999,8.013148344494999,8.019839532495,8,7,5
9.016799249670001,0.0015718462211550999,9.01659279673,0.081049745,0.019341719999999996,9.01438055473,9.020618206730001,9,1,5
9.017018194054998,0.0014350300009393824,9.016908835395,0.078868215,0.022682285000000003,9.014823156395,9.021151249395,9,2,5
9.01726332741,0.002115676906681981,9.01658689167,0.080441425,0.021180010000000006,9.01496449417,9.02648660917,9,3,5
9.016763639119999,0.001512952945413639,9.01633446806,0.07937265,0.021857389999999994,9.01460193756,9.020248113560001,9,4,5
9.017349750035002,0.0017003842661876519,9.017002786995,0.08172369499999999,0.022520850000000002,9.014962139995001,9.022972700995,9,5,5
9.017306100565,0.0017584685970845099,9.017007012425,0.07975570499999997,0.02273486999999999,9.014567779924999,9.024597107924999,9,6,5
9.017007630905,0.0015125437139633618,9.016584779425,0.07929927499999999,0.021604699999999998,9.015123699924999,9.023345937924999,9,7,5
9.0188481787,0.002038130740157264,9.018710005199999,0.08872810999999999,0.02333252,9.015418677200001,9.0229693742,9,8,5
10.020097456779999,0.0020732834110187407,10.020212923159999,0.10054147499999999,0.027472845000000006,10.01639936466,10.024513922659999,10,1,5
10.020701272595,0.0022119896198483815,10.021010574275,0.09928061999999999,0.026462539999999993,10.016149150775,10.024349466775,10,2,5
10.020294442275002,0.0018471010390020766,10.019912748375,0.09662063499999998,0.029709829999999996,10.016893148375,10.025330058375001,10,3,5
10.020971053870001,0.002209195030397343,10.02079165515,0.09821629999999999,0.028191004999999998,10.01684321365,10.024464921649999,10,4,5
10.02147153793,0.0020951036709112854,10.021724447249998,0.09956617999999995,0.030633655000000003,10.017308507749998,10.025903988749999,10,5,5
10.020853486755001,0.002387481522172249,10.020695327635,0.10029417,0.027966095000000007,10.016340242635001,10.029198219635001,10,6,5
10.018751216420002,0.0019698224247626578,10.018146075059999,0.08825113500000002,0.025826920000000003,10.016164508060001,10.02565086006,10,7,5
10.018302961014996,0.0015231888831009253,10.018166453534999,0.089845875,0.022562924999999998,10.015884921535,10.022615320535,10,8,5
10.018139131275001,0.0012810901522741483,10.018190750015,0.08894370999999998,0.02330762499999999,10.015776271015,10.021069502015001,10,9,5

\end{filecontents*}
\pgfplotscreateplotcyclelist{mycyclelist}{
mark=square*,blue\\
mark=triangle*,red\\
mark=o,draw=black,fill=black\\
mark=asterisk,red\\
mark=pentagon*,green\\
mark=x,draw=black,fill=cyan\\
mark=oplus,blue\\
mark=otimes*,yellow\\
mark=diamond*,draw=black,fill=violet\\
}

\begin{tikzpicture}
\begin{axis}[,legend pos=outer north east, xtick={1,...,10},  cycle list name=mycyclelist]
   \addplot+[y filter/.expression={round(y)==2? y : nan}] table[x=t,y=mean, col sep=comma] {filecontents.csv};
   \addplot+[y filter/.expression={round(y)==3? y : nan}] table[x=t,y=mean, col sep=comma] {filecontents.csv};
   \addplot+[y filter/.expression={round(y)==4? y : nan}] table[x=t,y=mean, col sep=comma] {filecontents.csv};
   \addplot+[y filter/.expression={round(y)==5? y : nan}] table[x=t,y=mean, col sep=comma] {filecontents.csv};
   \addplot+[y filter/.expression={round(y)==6? y : nan}] table[x=t,y=mean, col sep=comma] {filecontents.csv};
   \addplot+[y filter/.expression={round(y)==7? y : nan}] table[x=t,y=mean, col sep=comma] {filecontents.csv};
   \addplot+[y filter/.expression={round(y)==8? y : nan}] table[x=t,y=mean, col sep=comma] {filecontents.csv};
   \addplot+[y filter/.expression={round(y)==9? y : nan}] table[x=t,y=mean, col sep=comma] {filecontents.csv};
   \addplot+[y filter/.expression={round(y)==10? y : nan}] table[x=t,y=mean, col sep=comma] {filecontents.csv};
 
\legend{$n=2$,$n=3$,$n=4$,$n=5$,$n=6$,$n=7$,$n=8$,$n=9$,$n=10$} 
\end{axis}
\end{tikzpicture}
\end{document}

九种不同风格的水平图

相关内容