[Tex/LaTex] pgfplots: How to place the legend box in the middle of an axis


I would like to have something like

legend pos= west, %insted of north west, south east...

because I don't wanna place it in the corner but vertically in the middle.

How could I do this?

Best Answer

legend pos=south west is equivalent to

legend style={at={(0.03,0.03)},anchor=south west}

So by analogy we can make a version anchored west by using

legend style={at={(0.03,0.5)},anchor=west}

Sample output




  \begin{axis}[legend style={at={(0.03,0.5)},anchor=west}]
    \addplot[smooth,mark=*,blue] coordinates {
    (0,2) (2,3) (3,1)
    \addlegendentry{Case 1}
    \addplot[smooth,color=red,mark=x] coordinates {
    (0,0) (1,1) (2,1) (3,2)
    \addlegendentry{Case 2}