3

Hello fellows and folks!

I need to draw the following curve. Could you please give me a hand?

enter image description here

I tried my best the other day but I had serious problems with the labels inside and outside the plot.

Here are the coordinates for train and test:

train: [1.1257, 0.9836, 0.9558, 0.9431, 0.9359, 0.931, 0.9277, 0.9252, 0.9233, 0.9219, 0.9205, 0.9197, 0.9189, 0.9182, 0.9177, 0.9172, 0.9168, 0.9165, 0.9162, 0.9159, 0.9157, 0.9155, 0.9153, 0.9152, 0.915, 0.9149, 0.9147, 0.9146, 0.9145, 0.9143, 0.9143, 0.9142, 0.9141, 0.914, 0.914, 0.914, 0.9139, 0.9138, 0.9137, 0.9137, 0.9136, 0.9136, 0.9136, 0.9136, 0.9135, 0.9134, 0.9134, 0.9134, 0.9133, 0.9132]

test: [1.1257, 0.992, 0.9681, 0.9579, 0.9521, 0.9485, 0.9457, 0.9445, 0.9432, 0.9424, 0.9413, 0.9409, 0.9409, 0.9408, 0.9402, 0.9397, 0.94, 0.9397, 0.9397, 0.9392, 0.9397, 0.9395, 0.9393, 0.9398, 0.9389, 0.9394, 0.9393, 0.9396, 0.9394, 0.9393, 0.9392, 0.939, 0.9389, 0.9394, 0.9393, 0.9385, 0.939, 0.9393, 0.9392, 0.9395, 0.9392, 0.9396, 0.9394, 0.9391, 0.9397, 0.9393, 0.9391, 0.9397, 0.9392, 0.9393]

The actual code (an absolute mess):

      \begin{tikzpicture} 
     \begin{loglogaxis}[ xlabel={Epochs}, 
                ylabel={RMSE} ] 


   \addplot coordinates { (5,8.312e-02) (17,2.547e-02)  
                  (49,7.407e-03) (129,2.102e-03) 
                  (321,5.874e-04) (769,1.623e-04)
                   (1793,4.442e-05) 
                   (4097,1.207e-05) (9217,3.261e-06) }; 



   \addplot coordinates{  (7,8.472e-02) 
                  (31,3.044e-02)
                  (111,1.022e-02) 
                  (351,3.303e-03) 
                  (1023,1.039e-03)
                  (2815,3.196e-04)
                  (7423,9.658e-05) 
                  (18943,2.873e-05) (47103,8.437e-06) }; 



   \addplot coordinates{ (9,7.881e-02)
     (49,3.243e-02) (209,1.232e-02) 
       (769,4.454e-03) (2561,1.551e-03) 
        (7937,5.236e-04) (23297,1.723e-04) 
          (65537,5.545e-05) (178177,1.751e-05) }; 



   \addplot coordinates{ (11,6.887e-02)
                   (71,3.177e-02)
                   (351,1.341e-02) (1471,5.334e-03)
                 (5503,2.027e-03) (18943,7.415e-04)
                (61183,2.628e-04) 
               (187903,9.063e-05) (553983,3.053e-05) }; 



  \addplot coordinates{ (13,5.755e-02) 
                 (97,2.925e-02) (545,1.351e-02)
                 (2561,5.842e-03) (10625,2.397e-03)
                   (40193,9.414e-04) (141569,3.564e-04)
                 (471041,1.308e-04) (1496065,4.670e-05) }; 

  \legend{$d=2$,$d=3$,$d=4$,$d=5$,$d=6$} \end{loglogaxis} 

  \end{tikzpicture}
3
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{tikzpicture}
 \begin{axis}
  \addplot[color=red,smooth] table[x expr=\coordindex,y index=0] {
 1.1257
 0.992
 0.9681
 0.9579
 0.9521
 0.9485
 0.9457
 0.9445
 0.9432
 0.9424
 0.9413
 0.9409
 0.9409
 0.9408
 0.9402
 0.9397
 0.94
 0.9397
 0.9397
 0.9392
 0.9397
 0.9395
 0.9393
 0.9398
 0.9389
 0.9394
 0.9393
 0.9396
 0.9394
 0.9393
 0.9392
 0.939
 0.9389
 0.9394
 0.9393
 0.9385
 0.939
 0.9393
 0.9392
 0.9395
 0.9392
 0.9396
 0.9394
 0.9391
 0.9397
 0.9393
 0.9391
 0.9397
 0.9392
 0.9393
 };
 \addlegendentry{Validation error} 
  \addplot[color=blue,smooth] table[x expr=\coordindex,y index=0] {
  1.1257
 0.9836
 0.9558
 0.9431
 0.9359
 0.931
 0.9277
 0.9252
 0.9233
 0.9219
 0.9205
 0.9197
 0.9189
 0.9182
 0.9177
 0.9172
 0.9168
 0.9165
 0.9162
 0.9159
 0.9157
 0.9155
 0.9153
 0.9152
 0.915
 0.9149
 0.9147
 0.9146
 0.9145
 0.9143
 0.9143
 0.9142
 0.9141
 0.914
 0.914
 0.914
 0.9139
 0.9138
 0.9137
 0.9137
 0.9136
 0.9136
 0.9136
 0.9136
 0.9135
 0.9134
 0.9134
 0.9134
 0.9133
 0.9132
 };
 \addlegendentry{Train error} 
 \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • The absolute One! One last question: how do you draw the box inside with text “Validation Error” and “Train Error”? – NaveganTeX May 17 at 4:04
  • @naveganteX The legend? Sure. – user121799 May 17 at 4:07
  • The legend, yes! Thank you very much! – NaveganTeX May 17 at 4:08
  • When I compile the whole tex document, it prints the y values with commas instead of a point. Do you know why this is happening? – NaveganTeX May 17 at 5:07
  • 1
    @naveganteX Most likely you have set thousands separator={,} somewhere. – user121799 May 17 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.