2

I want to make a plot where val1 is the X axis and val2 the Y axis. I want the plot to have both the X, Y values for model type a and b, that is, a line plot with two lines, one for each model type.

I tried this:

import pandas as pd
# df contains the dataframe above
df = df.pivot(index="alpha", columns='model', values=['val1', "val2"])

df.plot(
    figsize=(15, 13),
    xlabel = "val1",
    ylabel = "val2"
)

But that gives me a line plot for every model type for val1 and val2. That is, instead of having 2 curves that have one (val1, val2) pair for every alpha, I have 4 curves, with pairs (alpha, val_n), where n = 1:2.

How can I plot val1 against val2 by model on the same plot? No loops, please.

Extra: I've seen this question, which is similar. However, it only plots multiple lines against a common X axis. In my case, there are multiple X axis. Also note that while the X axis vary, they're all within the same range.

EDIT: Following @Trenton Mckinney's comments, I edited the table to also include cases where, for some entries of alpha, there are duplicate pairs of (val1, val2).

sample data

model,alpha,val1,val2
a,0.0,0.0209351377553025,1.0
a,0.0101010101010101,0.0384738461538461,0.9780976220275344
a,0.0202020202020202,0.0495397764628533,0.9430538172715894
a,0.0303030303030303,0.0579088471849865,0.8785982478097623
a,0.0404040404040404,0.0679002982961727,0.8404255319148937
a,0.0505050505050505,0.076747811488188,0.8010012515644556
a,0.0606060606060606,0.0827263982410334,0.753441802252816
a,0.0707070707070707,0.0863143318716824,0.7021276595744681
a,0.0808080808080808,0.0898876404494382,0.6608260325406758
a,0.0909090909090909,0.0911214953271028,0.6101376720901126
a,0.101010101010101,0.0931797328983586,0.571964956195244
a,0.1111111111111111,0.095023122660207,0.5400500625782227
a,0.1212121212121212,0.0966555977229601,0.5100125156445557
a,0.1313131313131313,0.0991264717052791,0.4899874843554443
a,0.1414141414141414,0.0999729437229437,0.4624530663329161
a,0.1515151515151515,0.0998256320836966,0.4299123904881101
a,0.1616161616161616,0.0981823830977163,0.3954943679599499
a,0.1717171717171717,0.0976876675603217,0.3648310387984981
a,0.1818181818181818,0.0946969696969697,0.3285356695869837
a,0.1919191919191919,0.0922956589753617,0.295369211514393
a,0.202020202020202,0.0890878090366581,0.2615769712140175
a,0.2121212121212121,0.0858516483516483,0.2346683354192741
a,0.2222222222222222,0.0851274437020539,0.2152690863579474
a,0.2323232323232323,0.0827027027027027,0.1914893617021276
a,0.2424242424242424,0.0814991076740035,0.1714643304130162
a,0.2525252525252525,0.081406707912732,0.1564455569461827
a,0.2626262626262626,0.0831261101243339,0.146433041301627
a,0.2727272727272727,0.0826287471176018,0.1345431789737171
a,0.2828282828282829,0.0833677259595542,0.1264080100125156
a,0.2929292929292929,0.082210242587601,0.1145181476846057
a,0.303030303030303,0.0843315764254911,0.1101376720901126
a,0.3131313131313131,0.0822981366459627,0.0994993742177722
a,0.3232323232323232,0.0795140806184428,0.0901126408010012
a,0.3333333333333333,0.0814991076740035,0.0857321652065081
a,0.3434343434343435,0.0807493540051679,0.0782227784730913
a,0.3535353535353536,0.0800850460666194,0.0707133917396746
a,0.3636363636363636,0.0773395204949729,0.0625782227784731
a,0.3737373737373737,0.0753246753246753,0.0544430538172715
a,0.3838383838383838,0.065155807365439,0.0431789737171464
a,0.393939393939394,0.0640756302521008,0.0381727158948685
a,0.4040404040404041,0.0667447306791569,0.0356695869837296
a,0.4141414141414142,0.0600801068090787,0.0281602002503128
a,0.4242424242424242,0.061633281972265,0.0250312891113892
a,0.4343434343434343,0.0586145648312611,0.0206508135168961
a,0.4444444444444445,0.0542797494780793,0.016270337922403
a,0.4545454545454546,0.0505050505050505,0.0125156445556946
a,0.4646464646464647,0.0470219435736677,0.0093867334167709
a,0.4747474747474748,0.0595238095238095,0.0093867334167709
a,0.4848484848484848,0.0666666666666666,0.0081351689612015
a,0.494949494949495,0.064516129032258,0.0062578222778473
a,0.5050505050505051,0.064516129032258,0.0050062578222778
a,0.5151515151515152,0.0697674418604651,0.0037546933667083
a,0.5252525252525253,0.0689655172413793,0.0025031289111389
a,0.5353535353535354,0.0714285714285714,0.0018773466833541
a,0.5454545454545455,0.1153846153846153,0.0018773466833541
a,0.5555555555555556,0.1176470588235294,0.0012515644555694
a,0.5656565656565657,0.1,0.0006257822277847
a,0.5757575757575758,0.1428571428571428,0.0006257822277847
a,0.5858585858585859,0.0,0.0
a,0.595959595959596,0.0,0.0
a,0.6060606060606061,0.0,0.0
a,0.6161616161616162,0.0,0.0
a,0.6262626262626263,0.0,0.0
a,0.6363636363636365,0.0,0.0
a,0.6464646464646465,0.0,0.0
a,0.6565656565656566,0.0,0.0
a,0.6666666666666667,0.0,0.0
a,0.6767676767676768,0.0,0.0
a,0.686868686868687,0.0,0.0
a,0.696969696969697,0.0,0.0
a,0.7070707070707072,0.0,0.0
a,0.7171717171717172,0.0,0.0
a,0.7272727272727273,0.0,0.0
a,0.7373737373737375,0.0,0.0
a,0.7474747474747475,0.0,0.0
a,0.7575757575757577,0.0,0.0
a,0.7676767676767677,0.0,0.0
a,0.7777777777777778,0.0,0.0
a,0.787878787878788,0.0,0.0
a,0.797979797979798,0.0,0.0
a,0.8080808080808082,0.0,0.0
a,0.8181818181818182,0.0,0.0
a,0.8282828282828284,0.0,0.0
a,0.8383838383838385,0.0,0.0
a,0.8484848484848485,0.0,0.0
a,0.8585858585858587,0.0,0.0
a,0.8686868686868687,0.0,0.0
a,0.8787878787878789,0.0,0.0
a,0.888888888888889,0.0,0.0
a,0.8989898989898991,0.0,0.0
a,0.9090909090909092,0.0,0.0
a,0.9191919191919192,0.0,0.0
a,0.9292929292929294,0.0,0.0
a,0.9393939393939394,0.0,0.0
a,0.9494949494949496,0.0,0.0
a,0.9595959595959596,0.0,0.0
a,0.9696969696969696,0.0,0.0
a,0.97979797979798,0.0,0.0
a,0.98989898989899,0.0,0.0
a,1.0,0.0,0.0
b,0.0,0.0209351377553025,1.0
b,0.0101010101010101,0.0311796532522412,0.98811013767209
b,0.0202020202020202,0.038218896713615,0.9780976220275344
b,0.0303030303030303,0.0443462796167747,0.967459324155194
b,0.0404040404040404,0.0494074390203867,0.94180225281602
b,0.0505050505050505,0.0536487837387537,0.9067584480600752
b,0.0606060606060606,0.0579099545642296,0.8773466833541927
b,0.0707070707070707,0.0624309392265193,0.8485607008760951
b,0.0808080808080808,0.0682604272634791,0.8397997496871089
b,0.0909090909090909,0.0730481402881715,0.818523153942428
b,0.101010101010101,0.0772134940932895,0.7934918648310388
b,0.1111111111111111,0.0808107396683337,0.7684605757196495
b,0.1212121212121212,0.082314072824406,0.7327909887359199
b,0.1313131313131313,0.0842868895370578,0.7052565707133918
b,0.1414141414141414,0.0872056015276893,0.685857321652065
b,0.1515151515151515,0.0890210200150741,0.6652065081351689
b,0.1616161616161616,0.0897685103375154,0.6357947434292867
b,0.1717171717171717,0.090951405697263,0.6113892365456821
b,0.1818181818181818,0.0919013741350745,0.5901126408010012
b,0.1919191919191919,0.0931881228809205,0.567584480600751
b,0.202020202020202,0.0941756945189316,0.5494367959949937
b,0.2121212121212121,0.095206017738857,0.5306633291614519
b,0.2222222222222222,0.0958118858212447,0.5125156445556946
b,0.2323232323232323,0.0973819427452899,0.4981226533166458
b,0.2424242424242424,0.0987325728770595,0.4874843554443054
b,0.2525252525252525,0.1006364359586316,0.4749687108886107
b,0.2626262626262626,0.100246845858475,0.4574468085106383
b,0.2727272727272727,0.1002437975046608,0.4374217772215269
b,0.2828282828282829,0.0990276738967838,0.4142678347934919
b,0.2929292929292929,0.0981863664790494,0.392991239048811
b,0.303030303030303,0.0979558462796402,0.3748435544430538
b,0.3131313131313131,0.0970492921712433,0.3560700876095118
b,0.3232323232323232,0.0944952483414021,0.3297872340425531
b,0.3333333333333333,0.0920953101361573,0.304755944931164
b,0.3434343434343435,0.092139303482587,0.2897371714643304
b,0.3535353535353536,0.0887949260042283,0.2628285356695869
b,0.3636363636363636,0.0878679750223015,0.246558197747184
b,0.3737373737373737,0.0863935969868173,0.2296620775969962
b,0.3838383838383838,0.084931506849315,0.2133917396745932
b,0.393939393939394,0.0827823327162126,0.1958698372966207
b,0.4040404040404041,0.0818565400843881,0.1821026282853567
b,0.4141414141414142,0.0815282791817087,0.169586983729662
b,0.4242424242424242,0.0801810539928871,0.1551939924906132
b,0.4343434343434343,0.0814153211954654,0.1483103879849812
b,0.4444444444444445,0.0844346549192364,0.1439299123904881
b,0.4545454545454546,0.0827478532396565,0.1326658322903629
b,0.4646464646464647,0.0828843762950683,0.1251564455569462
b,0.4747474747474748,0.0826666666666666,0.1163954943679599
b,0.4848484848484848,0.0832171083217108,0.1120150187734668
b,0.494949494949495,0.0818452380952381,0.1032540675844806
b,0.5050505050505051,0.080824088748019,0.0957446808510638
b,0.5151515151515152,0.0801781737193764,0.0901126408010012
b,0.5252525252525253,0.079667063020214,0.0838548185231539
b,0.5353535353535354,0.0793147208121827,0.0782227784730913
b,0.5454545454545455,0.0790378006872852,0.071964956195244
b,0.5555555555555556,0.078927773641102,0.0663329161451814
b,0.5656565656565657,0.0752864157119476,0.0575719649561952
b,0.5757575757575758,0.0709219858156028,0.0500625782227784
b,0.5858585858585859,0.06511175898931,0.0419274092615769
b,0.595959595959596,0.0643776824034334,0.0375469336670838
b,0.6060606060606061,0.0676328502415458,0.0350438047559449
b,0.6161616161616162,0.0613079019073569,0.0281602002503128
b,0.6262626262626263,0.0682539682539682,0.0269086357947434
b,0.6363636363636365,0.0588235294117647,0.0200250312891113
b,0.6464646464646465,0.0592105263157894,0.0168961201501877
b,0.6565656565656566,0.0506666666666666,0.0118898623279098
b,0.6666666666666667,0.0549828178694158,0.0100125156445556
b,0.6767676767676768,0.0614035087719298,0.0087609511889862
b,0.686868686868687,0.0578034682080924,0.0062578222778473
b,0.696969696969697,0.0666666666666666,0.0056320400500625
b,0.7070707070707072,0.0618556701030927,0.0037546933667083
b,0.7171717171717172,0.0806451612903225,0.0031289111389236
b,0.7272727272727273,0.1,0.0025031289111389
b,0.7373737373737375,0.1304347826086956,0.0018773466833541
b,0.7474747474747475,0.1538461538461538,0.0012515644555694
b,0.7575757575757577,0.0,0.0
b,0.7676767676767677,0.0,0.0
b,0.7777777777777778,0.0,0.0
b,0.787878787878788,0.0,0.0
b,0.797979797979798,0.0,0.0
b,0.8080808080808082,0.0,0.0
b,0.8181818181818182,0.0,0.0
b,0.8282828282828284,0.0,0.0
b,0.8383838383838385,0.0,0.0
b,0.8484848484848485,0.0,0.0
b,0.8585858585858587,0.0,0.0
b,0.8686868686868687,0.0,0.0
b,0.8787878787878789,0.0,0.0
b,0.888888888888889,0.0,0.0
b,0.8989898989898991,0.0,0.0
b,0.9090909090909092,0.0,0.0
b,0.9191919191919192,0.0,0.0
b,0.9292929292929294,0.0,0.0
b,0.9393939393939394,0.0,0.0
b,0.9494949494949496,0.0,0.0
b,0.9595959595959596,0.0,0.0
b,0.9696969696969696,0.0,0.0
b,0.97979797979798,0.0,0.0
b,0.98989898989899,0.0,0.0
b,1.0,0.0,0.0
c,0.0,0.0209351377553025,1.0
c,0.0101010101010101,0.0260009203865623,0.9899874843554444
c,0.0202020202020202,0.0291272929405225,0.983729662077597
c,0.0303030303030303,0.0316901408450704,0.9799749687108886
c,0.0404040404040404,0.0335694822888283,0.9637046307884856
c,0.0505050505050505,0.0353562373520039,0.951188986232791
c,0.0606060606060606,0.0366177773402894,0.9311639549436797
c,0.0707070707070707,0.0379792840268944,0.9155193992490612
c,0.0808080808080808,0.0391739640450664,0.8986232790988736
c,0.0909090909090909,0.0405548405548405,0.8873591989987485
c,0.101010101010101,0.041501090561415,0.8692115143929913
c,0.1111111111111111,0.042478371818012,0.8541927409261577
c,0.1212121212121212,0.0435219066740066,0.8410513141426783
c,0.1313131313131313,0.0446280991735537,0.827909887359199
c,0.1414141414141414,0.0456870576693994,0.8160200250312891
c,0.1515151515151515,0.0466965816642953,0.8010012515644556
c,0.1616161616161616,0.0476515151515151,0.7872340425531915
c,0.1717171717171717,0.0482444068729603,0.7678347934918648
c,0.1818181818181818,0.0492057026476578,0.7559449311639549
c,0.1919191919191919,0.0506820965493939,0.7509386733416771
c,0.202020202020202,0.0518977877468443,0.7384230287859824
c,0.2121212121212121,0.0529285941837709,0.727784730913642
c,0.2222222222222222,0.0539495402027823,0.7158948685857321
c,0.2323232323232323,0.055045871559633,0.7058823529411765
c,0.2424242424242424,0.0562687097265208,0.6939924906132666
c,0.2525252525252525,0.0571608369605118,0.6821026282853567
c,0.2626262626262626,0.0585387084489418,0.6733416770963705
c,0.2727272727272727,0.0593187047533531,0.6614518147684606
c,0.2828282828282829,0.0605287569573283,0.6533166458072591
c,0.2929292929292929,0.0615191837221791,0.6451814768460575
c,0.303030303030303,0.0624768946395563,0.6345431789737171
c,0.3131313131313131,0.0634081060412949,0.6226533166458073
c,0.3232323232323232,0.0645521407932755,0.6151439299123905
c,0.3333333333333333,0.0652394824198902,0.6026282853566959
c,0.3434343434343435,0.0662098860378941,0.5926157697121401
c,0.3535353535353536,0.067065695536165,0.5819774718397998
c,0.3636363636363636,0.0688039274025587,0.5788485607008761
c,0.3737373737373737,0.0697781178270849,0.5707133917396746
c,0.3838383838383838,0.0709895997478726,0.5638297872340425
c,0.393939393939394,0.0718514313518773,0.5544430538172715
c,0.4040404040404041,0.0726042275879355,0.5438047559449312
c,0.4141414141414142,0.0727350794332331,0.5300375469336671
c,0.4242424242424242,0.0735502121640735,0.5206508135168961
c,0.4343434343434343,0.0736765508459159,0.5068836045056321
c,0.4444444444444445,0.0749274140676219,0.5006257822277848
c,0.4545454545454546,0.0757341576506955,0.490613266583229
c,0.4646464646464647,0.076371602110923,0.4799749687108886
c,0.4747474747474748,0.076639344262295,0.4680851063829787
c,0.4848484848484848,0.0778247096092925,0.4612015018773467
c,0.494949494949495,0.0787418655097614,0.4543178973717146
c,0.5050505050505051,0.0794739208633093,0.4424280350438047
c,0.5151515151515152,0.0805423571676903,0.434918648310388
c,0.5252525252525253,0.0804776119402985,0.4217772215269086
c,0.5353535353535354,0.0812546307730303,0.4117647058823529
c,0.5454545454545455,0.0811571940604198,0.3967459324155194
c,0.5555555555555556,0.0826709062003179,0.3904881101376721
c,0.5656565656565657,0.0829772570640937,0.376720901126408
c,0.5757575757575758,0.0842511800886854,0.3685857321652065
c,0.5858585858585859,0.0856255545696539,0.3623279098873592
c,0.595959595959596,0.0862148455509451,0.351063829787234
c,0.6060606060606061,0.0874482319209939,0.3435544430538172
c,0.6161616161616162,0.0871513944223107,0.3285356695869837
c,0.6262626262626263,0.0869339785689595,0.3147684605757196
c,0.6363636363636365,0.0870655678968111,0.3041301627033792
c,0.6464646464646465,0.0871361502347417,0.2903629536921151
c,0.6565656565656566,0.0877399138268703,0.2803504380475594
c,0.6666666666666667,0.0876723605680181,0.2665832290362954
c,0.6767676767676768,0.0885585003232062,0.2571964956195244
c,0.686868686868687,0.0877431026684758,0.2428035043804756
c,0.696969696969697,0.0882844189930804,0.2315394242803504
c,0.7070707070707072,0.0908171009359979,0.2246558197747184
c,0.7171717171717172,0.0899057873485868,0.2090112640801001
c,0.7272727272727273,0.0891628440366972,0.1946182728410513
c,0.7373737373737375,0.0884603611876339,0.1808510638297872
c,0.7474747474747475,0.0867430441898527,0.1658322903629537
c,0.7575757575757577,0.0855935188446636,0.1520650813516896
c,0.7676767676767677,0.0863228699551569,0.1445556946182728
c,0.7777777777777778,0.0879032258064516,0.1364205256570713
c,0.787878787878788,0.0894924309884238,0.1257822277847309
c,0.797979797979798,0.0907774022211492,0.1176470588235294
c,0.8080808080808082,0.093717277486911,0.1120150187734668
c,0.8181818181818182,0.0949589683470105,0.1013767209011264
c,0.8282828282828284,0.0908492429229756,0.0863579474342928
c,0.8383838383838385,0.0925373134328358,0.0775969962453066
c,0.8484848484848485,0.0939130434782608,0.0675844806007509
c,0.8585858585858587,0.0916334661354581,0.0575719649561952
c,0.8686868686868687,0.0877817319098457,0.04630788485607
c,0.8787878787878789,0.0844062947067239,0.0369211514392991
c,0.888888888888889,0.0816326530612244,0.0275344180225281
c,0.8989898989898991,0.073170731707317,0.0187734668335419
c,0.9090909090909092,0.0833333333333333,0.016270337922403
c,0.9191919191919192,0.0938967136150234,0.0125156445556946
c,0.9292929292929294,0.1065573770491803,0.0081351689612015
c,0.9393939393939394,0.0483870967741935,0.0018773466833541
c,0.9494949494949496,0.0,0.0
c,0.9595959595959596,0.0,0.0
c,0.9696969696969696,0.0,0.0
c,0.97979797979798,0.0,0.0
c,0.98989898989899,0.0,0.0
c,1.0,0.0,0.0
d,0.0,0.0209351377553025,1.0
d,0.0101010101010101,0.0251245945732141,0.9937421777221528
d,0.0202020202020202,0.0281562054208273,0.98811013767209
d,0.0303030303030303,0.030655907465661,0.9818523153942428
d,0.0404040404040404,0.0328760792387034,0.979349186483104
d,0.0505050505050505,0.0346682204244447,0.9680851063829788
d,0.0606060606060606,0.0363865386443578,0.958072590738423
d,0.0707070707070707,0.0377041787754284,0.94180225281602
d,0.0808080808080808,0.0390011075365223,0.925531914893617
d,0.0909090909090909,0.0403049808005746,0.9130162703379224
d,0.101010101010101,0.041452126120914,0.8967459324155194
d,0.1111111111111111,0.0425454765214238,0.8811013767209012
d,0.1212121212121212,0.0437815656565656,0.8679599499374218
d,0.1313131313131313,0.0451219112000787,0.860450563204005
d,0.1414141414141414,0.0463402149803787,0.8498122653316645
d,0.1515151515151515,0.047537959415354,0.8385481852315394
d,0.1616161616161616,0.0485289769367238,0.8216520650813517
d,0.1717171717171717,0.0494610503784114,0.8097622027534418
d,0.1818181818181818,0.0504505219703886,0.795369211514393
d,0.1919191919191919,0.0515671979900325,0.7834793491864831
d,0.202020202020202,0.0523551266174147,0.7672090112640801
d,0.2121212121212121,0.0534628865521984,0.7540675844806007
d,0.2222222222222222,0.0547603656847354,0.7421777221526908
d,0.2323232323232323,0.0559169616378073,0.7315394242803505
d,0.2424242424242424,0.0575339748040868,0.7259073842302879
d,0.2525252525252525,0.0586426081607545,0.7158948685857321
d,0.2626262626262626,0.0600956429330499,0.7077596996245307
d,0.2727272727272727,0.0607026997305767,0.690863579474343
d,0.2828282828282829,0.0617571794142735,0.6795994993742178
d,0.2929292929292929,0.0628723090533765,0.6670838548185232
d,0.303030303030303,0.0637793840733766,0.6570713391739674
d,0.3131313131313131,0.0650753768844221,0.6483103879849812
d,0.3232323232323232,0.0661826667530952,0.6389236545682102
d,0.3333333333333333,0.0669249265295217,0.6270337922403004
d,0.3434343434343435,0.0682694957288509,0.6201501877346683
d,0.3535353535353536,0.0689581401982457,0.6051314142678348
d,0.3636363636363636,0.0700088339222614,0.595118898623279
d,0.3737373737373737,0.0714177407126611,0.5894868585732165
d,0.3838383838383838,0.0725291828793774,0.5832290362953693
d,0.393939393939394,0.0735505510301868,0.5763454317897372
d,0.4040404040404041,0.0746819860484201,0.5694618272841051
d,0.4141414141414142,0.075576971848846,0.5594493116395495
d,0.4242424242424242,0.0762866846642863,0.5481852315394243
d,0.4343434343434343,0.0773564657485244,0.5413016270337923
d,0.4444444444444445,0.0787677550267478,0.5344180225281602
d,0.4545454545454546,0.0791476407914764,0.5206508135168961
d,0.4646464646464647,0.0786209590780349,0.5037546933667084
d,0.4747474747474748,0.0798065296251511,0.4956195244055069
d,0.4848484848484848,0.0810081941707291,0.4887359198998748
d,0.494949494949495,0.0822561692126909,0.4818523153942428
d,0.5050505050505051,0.0830026455026455,0.4712140175219024
d,0.5151515151515152,0.0836748633879781,0.4599499374217772
d,0.5252525252525253,0.0840355805243445,0.4493116395494368
d,0.5353535353535354,0.0846862127453356,0.4374217772215269
d,0.5454545454545455,0.0857928964482241,0.4292866082603254
d,0.5555555555555556,0.0865896403998442,0.4173967459324155
d,0.5656565656565657,0.0867985466289866,0.4036295369211514
d,0.5757575757575758,0.0871873690093614,0.3904881101376721
d,0.5858585858585859,0.0877801879971077,0.3798498122653316
d,0.595959595959596,0.0882706766917293,0.367334167709637
d,0.6060606060606061,0.088829703900987,0.3548185231539424
d,0.6161616161616162,0.089370014650822,0.3435544430538172
d,0.6262626262626263,0.0898477157360406,0.3322903629536921
d,0.6363636363636365,0.0905713780293649,0.3204005006257822
d,0.6464646464646465,0.0899373387394028,0.3053817271589487
d,0.6565656565656566,0.0908043770397389,0.2959949937421777
d,0.6666666666666667,0.0890507994333131,0.2753441802252816
d,0.6767676767676768,0.0873744926297799,0.2559449311639549
d,0.686868686868687,0.0882882882882882,0.2453066332916145
d,0.696969696969697,0.0901072705601907,0.2365456821026282
d,0.7070707070707072,0.0909090909090909,0.2246558197747184
d,0.7171717171717172,0.091277342695112,0.211514392991239
d,0.7272727272727273,0.0910138248847926,0.1977471839799749
d,0.7373737373737375,0.0904109589041095,0.1858573216520651
d,0.7474747474747475,0.0915654742369543,0.1745932415519399
d,0.7575757575757577,0.090014064697609,0.1602002503128911
d,0.7676767676767677,0.0896084337349397,0.1489361702127659
d,0.7777777777777778,0.0903515944399018,0.1382978723404255
d,0.787878787878788,0.0898976412995104,0.1264080100125156
d,0.797979797979798,0.0889662027833002,0.1120150187734668
d,0.8080808080808082,0.0907608695652174,0.10450563204005
d,0.8181818181818182,0.0908543922984356,0.0944931163954943
d,0.8282828282828284,0.0892857142857142,0.081351689612015
d,0.8383838383838385,0.0888364779874213,0.0707133917396746
d,0.8484848484848485,0.0899182561307901,0.0619524405506883
d,0.8585858585858587,0.0905263157894736,0.0538172715894868
d,0.8686868686868687,0.0879689521345407,0.0425531914893617
d,0.8787878787878789,0.0856164383561643,0.0312891113892365
d,0.888888888888889,0.0775862068965517,0.0225281602002503
d,0.8989898989898991,0.0813253012048192,0.0168961201501877
d,0.9090909090909092,0.0818965517241379,0.0118898623279098
d,0.9191919191919192,0.0895522388059701,0.0075093867334167
d,0.9292929292929294,0.0172413793103448,0.0006257822277847
d,0.9393939393939394,0.0,0.0
d,0.9494949494949496,0.0,0.0
d,0.9595959595959596,0.0,0.0
d,0.9696969696969696,0.0,0.0
d,0.97979797979798,0.0,0.0
d,0.98989898989899,0.0,0.0
d,1.0,0.0,0.0
e,0.0,0.0209351377553025,1.0
e,0.0101010101010101,0.0231925388118552,0.9974968710888612
e,0.0202020202020202,0.0259959652949763,0.9918648310387984
e,0.0303030303030303,0.0285874642430387,0.98811013767209
e,0.0404040404040404,0.031019173345906,0.98811013767209
e,0.0505050505050505,0.0332503481159542,0.986232790988736
e,0.0606060606060606,0.0352864495538624,0.9824780976220276
e,0.0707070707070707,0.0373713795731707,0.9818523153942428
e,0.0808080808080808,0.0394302281608471,0.9787234042553192
e,0.0909090909090909,0.0413554817275747,0.9737171464330412
e,0.101010101010101,0.0431863951667039,0.9662077596996246
e,0.1111111111111111,0.0450381679389313,0.9599499374217773
e,0.1212121212121212,0.0467692307692307,0.951188986232791
e,0.1313131313131313,0.0481455293437038,0.9374217772215268
e,0.1414141414141414,0.0495889951350444,0.9249061326658324
e,0.1515151515151515,0.0511773940345368,0.9180225281602002
e,0.1616161616161616,0.052410141090276,0.9042553191489362
e,0.1717171717171717,0.0539613107583242,0.89549436795995
e,0.1818181818181818,0.055350553505535,0.8823529411764706
e,0.1919191919191919,0.0571533472035246,0.876720901126408
e,0.202020202020202,0.0587710730816595,0.8660826032540676
e,0.2121212121212121,0.0605230606114154,0.8573216520650814
e,0.2222222222222222,0.0627839735646427,0.8560700876095119
e,0.2323232323232323,0.0648055356716774,0.8498122653316645
e,0.2424242424242424,0.0664880420760146,0.8385481852315394
e,0.2525252525252525,0.0678446321862765,0.8241551939924906
e,0.2626262626262626,0.0699075069907507,0.8135168961201502
e,0.2727272727272727,0.0716877896264865,0.8035043804755945
e,0.2828282828282829,0.0732978230662343,0.7922403003754693
e,0.2929292929292929,0.0749489121288616,0.7803504380475594
e,0.303030303030303,0.0763780995587595,0.7690863579474343
e,0.3131313131313131,0.07753683804131,0.7540675844806007
e,0.3232323232323232,0.079101302844988,0.7446808510638298
e,0.3333333333333333,0.0802439525800041,0.7327909887359199
e,0.3434343434343435,0.0811553363860514,0.72090112640801
e,0.3535353535353536,0.0823060188542422,0.7102628285356696
e,0.3636363636363636,0.0837809609071918,0.7027534418022529
e,0.3737373737373737,0.0846094946401225,0.6914893617021277
e,0.3838383838383838,0.0848217798410575,0.6745932415519399
e,0.393939393939394,0.0860649119974164,0.6670838548185232
e,0.4040404040404041,0.0863961416929985,0.6501877346683355
e,0.4141414141414142,0.0878707581844602,0.6433041301627034
e,0.4242424242424242,0.0886686546219961,0.632665832290363
e,0.4343434343434343,0.0899361453368108,0.6257822277847309
e,0.4444444444444445,0.0898845265588914,0.6088861076345432
e,0.4545454545454546,0.090398705871158,0.5944931163954944
e,0.4646464646464647,0.0913884007029877,0.5857321652065082
e,0.4747474747474748,0.0922490724957385,0.5757196495619524
e,0.4848484848484848,0.0932712215320911,0.5638297872340425
e,0.494949494949495,0.0934599381201323,0.5481852315394243
e,0.5050505050505051,0.0947716015410016,0.5387984981226533
e,0.5151515151515152,0.0953619909502262,0.5275344180225282
e,0.5252525252525253,0.0963212254845073,0.5193992490613266
e,0.5353535353535354,0.0971012763926995,0.509386733416771
e,0.5454545454545455,0.097106424717999,0.4956195244055069
e,0.5555555555555556,0.0981873111782477,0.4881101376720901
e,0.5656565656565657,0.0987765614938828,0.4799749687108886
e,0.5757575757575758,0.0996686547382372,0.4705882352941176
e,0.5858585858585859,0.0997550353837779,0.4586983729662077
e,0.595959595959596,0.0999161542761319,0.4474342928660826
e,0.6060606060606061,0.1008029825064525,0.4399249061326658
e,0.6161616161616162,0.1004134672179562,0.425531914893617
e,0.6262626262626263,0.0990415335463258,0.4073842302878598
e,0.6363636363636365,0.0991244527829893,0.3967459324155194
e,0.6464646464646465,0.0976121329461116,0.3785982478097622
e,0.6565656565656566,0.0965899546447169,0.3598247809762203
e,0.6666666666666667,0.0956140350877193,0.3410513141426783
e,0.6767676767676768,0.094518302677108,0.3247809762202753
e,0.686868686868687,0.0928448110492998,0.3028785982478097
e,0.696969696969697,0.0907801418439716,0.2803504380475594
e,0.7070707070707072,0.0910656620021528,0.2647058823529412
e,0.7171717171717172,0.0898927675108373,0.246558197747184
e,0.7272727272727273,0.089101620029455,0.2271589486858573
e,0.7373737373737375,0.0873581419899709,0.2071339173967459
e,0.7474747474747475,0.0864479315263908,0.1896120150187734
e,0.7575757575757577,0.0855911330049261,0.1739674593241552
e,0.7676767676767677,0.0850847457627118,0.1570713391739674
e,0.7777777777777778,0.0846521899153478,0.1439299123904881
e,0.787878787878788,0.0821256038647343,0.1276595744680851
e,0.797979797979798,0.0801424755120213,0.1126408010012515
e,0.8080808080808082,0.081513828238719,0.1051314142678347
e,0.8181818181818182,0.0824146981627296,0.0982478097622027
e,0.8282828282828284,0.0788091068301225,0.0844806007509386
e,0.8383838383838385,0.079790712884238,0.0763454317897371
e,0.8484848484848485,0.0765151515151515,0.0632040050062578
e,0.8585858585858587,0.0758377425044091,0.0538172715894868
e,0.8686868686868687,0.079685746352413,0.0444305381727158
e,0.8787878787878789,0.072289156626506,0.030037546933667
e,0.888888888888889,0.0842105263157894,0.0250312891113892
e,0.8989898989898991,0.0748299319727891,0.013767209011264
e,0.9090909090909092,0.0558659217877094,0.0062578222778473
e,0.9191919191919192,0.073170731707317,0.0037546933667083
e,0.9292929292929294,0.0588235294117647,0.0012515644555694
e,0.9393939393939394,0.0,0.0
e,0.9494949494949496,0.0,0.0
e,0.9595959595959596,0.0,0.0
e,0.9696969696969696,0.0,0.0
e,0.97979797979798,0.0,0.0
e,0.98989898989899,0.0,0.0
e,1.0,0.0,0.0
f,0.0,0.0209351377553025,1.0
f,0.0101010101010101,0.0234153507161219,0.9974968710888612
f,0.0202020202020202,0.0262395017145128,0.9912390488110138
f,0.0303030303030303,0.0288987719394571,0.98811013767209
f,0.0404040404040404,0.0313480869323374,0.9874843554443054
f,0.0505050505050505,0.0335380154364419,0.9843554443053816
f,0.0606060606060606,0.03554679535105,0.9818523153942428
f,0.0707070707070707,0.0376540832049306,0.9787234042553192
f,0.0808080808080808,0.0396716128703278,0.9737171464330412
f,0.0909090909090909,0.0417294446835987,0.9705882352941176
f,0.101010101010101,0.0435324087178035,0.9624530663329162
f,0.1111111111111111,0.0452358322442675,0.9530663329161452
f,0.1212121212121212,0.0467031259710397,0.9405506883604504
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
eduardokapp
  • 1,612
  • 1
  • 6
  • 28

2 Answers2

2
  • For long data, as shown by the sample data, seaborn, a high-level API for matplotlib is usually the easiest option.
  • The following answers use the raw dataframe, df, not the pivoted dataframe.
  • Tested in python 3.8.11, pandas 1.3.2, matplotlib 3.4.3, seaborn 0.11.2

Axes-Level Plot

  • seaborn.scatterplot
  • Has an estimator parameter for aggregating across multiple observations of the y variable at the same x level.
import seaborn as sns
import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(10, 5))
sns.scatterplot(data=df, x='val1', y='val2', hue='model', ax=ax)

enter image description here

Figure-Level Plot

sns.relplot(data=df, x='val1', y='val2', hue='model', kind='scatter', aspect=2)

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
1

You can convert model column to int type, and then pass as c argument in the plot function:

df.assign(model=df.model.factorize()[0]).plot.scatter(x='val1', y='val2', c='model', colormap='viridis')

enter image description here

To get a line plot, one option is to pivot model into different columns, interpolate by index and then plot:

df.pivot('val1', 'model', 'val2').interpolate(method='index').plot.line()

enter image description here

Psidom
  • 209,562
  • 33
  • 339
  • 356
  • Looking good! I don't understand the gradient colored sidebar, though. Is it possible to have a legend, considering the `model` is categorical, not continuous? Also, is there a way to have lines, instead of a scatter plot? – eduardokapp Sep 29 '21 at 16:28
  • @eduardokapp I added a line plot example. – Psidom Sep 29 '21 at 16:37