图例超出了图表的范围

图例超出了图表的范围

尝试在图表范围内绘制以下带图例的图表。请提供建议。在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{tikz,pgfplots,pgfplotstable}
\usepackage{tikz-qtree}
\usepackage{forest}
\usepackage{lettrine}
\usepackage{mathtools}
\usepackage{lscape}
\usepackage{pgf-pie}
\usepackage{caption}  
\usetikzlibrary{positioning,shapes,arrows,shadows,patterns,intersections,calc,fit}
\usepackage{dashbox}
\usepackage{mathptmx}
\usepackage{xcolor}
\usepackage{hyperref}
\pgfplotsset{compat=1.3}
\begin{document}         
\begin{tikzpicture}[scale=1.2, transform shape]
    \begin{axis}[           
        xlabel style={font=\tiny},        
        ylabel style={font=\tiny, yshift=-.3cm},
        xmin=.1, xmax=1,
        ymin=0, ymax=80,
        ytick={10,20,30,40,50,60,70,80},
        xtick={.1,.2,.3,.4,.5,.6,.7,.8,.9,1},
        xticklabel style={font=\tiny},
        yticklabel style={font=\tiny},
        width=2.5in,
        legend style={font=\tiny},
        legend pos=south east   
        ]               
        \addplot coordinates {(.2, 54.4086) (.3, 54.4086) (.4, 55.8423) (.5, 56.5591) (.6, 58.3513) (.7, 61.2186) (.8, 64.4444) (.9, 66.595)};
        \addplot coordinates {(.2, 50) (.3, 52.3214) (.4, 54.6429) (.5, 56.0714) (.6, 58.0357) (.7, 60) (.8, 62.1429) (.9, 64.1071)};
        \addplot coordinates {(.2, 54.5291) (.3, 59.0135) (.4, 60.3587) (.5, 61.0314) (.6, 61.4798) (.7, 63.9462) (.8, 63.722) (.9, 67.3094)};
        \addplot coordinates {(.2, 50.4569) (.3, 53.2487) (.4, 54.5178) (.5, 57.0558) (.6, 60.3553) (.7, 63.1472) (.8, 64.6701) (.9, 66.9543)};
        \addplot coordinates {(.2, 48.7097) (.3, 51.2903) (.4, 53.871) (.5, 55.1613) (.6, 58.0645) (.7, 59.0323) (.8, 61.6129) (.9, 64.8387)};  
        \addplot coordinates {(.2, 51.25) (.3, 55.1562) (.4, 55.1562) (.5, 55.1562) (.6, 59.0625) (.7, 61.4062) (.8, 64.5312) (.9, 66.875)};
        \addplot coordinates {(.2, 52.6039) (.3, 55.2298) (.4, 56.5427) (.5, 56.3239) (.6, 58.2932) (.7, 60.0438) (.8, 60.4814) (.9, 63.7722)};
        \addplot coordinates {(.2, 48.0992) (.3, 48.9256) (.4, 48.0992) (.5, 50.5785) (.6, 54.7107) (.7, 58.843) (.8, 60.4959) (.9, 59.6694)};
        \addplot coordinates {(.2, 50.9609) (.3, 53.0961) (.4, 54.5196) (.5, 57.3665) (.6, 59.1459) (.7, 62.3488) (.8, 62.3488) (.9, 63.7722)};             
        \addplot coordinates {(.2, 40.7792) (.3, 44.6753) (.4, 44.6453) (.5, 47.2727) (.6, 51.1688) (.7, 55.0649) (.8, 56.3636) (.9, 62.8571)};
        \addplot coordinates {(.2, 39.4093) (.3, 42.7848) (.4, 47.0042) (.5, 47.4262) (.6, 48.27) (.7, 52.4895) (.8, 53.3333) (.9, 56.7089)};
        \addplot coordinates {(.2, 45) (.3, 45) (.4, 49.5455) (.5, 51.8182) (.6, 55.2273) (.7, 56.3636) (.8, 60.9091) (.9, 64.3182)};
        \addplot coordinates {(.2, 51.8367) (.3, 54.449) (.4, 54.9388) (.5, 55.7551) (.6, 55.2653) (.7, 57.2245) (.8, 58.9388) (.9, 59.4286)};
        \addplot coordinates {(.2, 53.1325) (.3, 53.7349) (.4, 55.9036) (.5, 57.7108) (.6, 58.4337) (.7, 59.8795) (.8, 62.6506) (.9, 65.0602)}; 
        \addplot coordinates {(.2, 56.0269) (.3, 58.3838) (.4, 62.4242) (.5, 65.1178) (.6, 65.7912) (.7, 67.138) (.8, 68.8215) (.9, 70.1684)};
        \legend{X1/Y1,X1/Y2,X1/Y3,X1/Y4,X2/Y1,X3/Y1,X4/Y1,X4/Y2,X5/Y1,X5/Y2,X6/Y1,X6/Y2,X7/Y1,X8/Y1,X9/Y1}
     \end{axis}
  \end{tikzpicture}       
\end{document}

答案1

\documentclass[border=5mm]{standalone}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{tikz,pgfplots,pgfplotstable}
\usepackage{tikz-qtree}
\usepackage{forest}
\usepackage{lettrine}
\usepackage{mathtools}
\usepackage{lscape}
\usepackage{pgf-pie}
\usepackage{caption}  
\usetikzlibrary{positioning,shapes,arrows,shadows,patterns,intersections,calc,fit}
\usepackage{dashbox}
\usepackage{mathptmx}
\usepackage{xcolor}
\usepackage{hyperref}
\pgfplotsset{compat=1.3}
\begin{document}         
\begin{tikzpicture}[scale=1.2, transform shape]
    \begin{axis}[           
        xlabel style={font=\tiny},        
        ylabel style={font=\tiny, yshift=-.3cm},
        xmin=.1, xmax=1,
        ymin=0, ymax=80,
        ytick={10,20,30,40,50,60,70,80},
        xtick={.1,.2,.3,.4,.5,.6,.7,.8,.9,1},
        xticklabel style={font=\tiny},
        yticklabel style={font=\tiny},
        width=2.5in,
        legend style={font=\tiny,at={(1.1,0.5)},anchor=west}    
        ]               
        \addplot coordinates {(.2, 54.4086) (.3, 54.4086) (.4, 55.8423) (.5, 56.5591) (.6, 58.3513) (.7, 61.2186) (.8, 64.4444) (.9, 66.595)};
        \addplot coordinates {(.2, 50) (.3, 52.3214) (.4, 54.6429) (.5, 56.0714) (.6, 58.0357) (.7, 60) (.8, 62.1429) (.9, 64.1071)};
        \addplot coordinates {(.2, 54.5291) (.3, 59.0135) (.4, 60.3587) (.5, 61.0314) (.6, 61.4798) (.7, 63.9462) (.8, 63.722) (.9, 67.3094)};
        \addplot coordinates {(.2, 50.4569) (.3, 53.2487) (.4, 54.5178) (.5, 57.0558) (.6, 60.3553) (.7, 63.1472) (.8, 64.6701) (.9, 66.9543)};
        \addplot coordinates {(.2, 48.7097) (.3, 51.2903) (.4, 53.871) (.5, 55.1613) (.6, 58.0645) (.7, 59.0323) (.8, 61.6129) (.9, 64.8387)};  
        \addplot coordinates {(.2, 51.25) (.3, 55.1562) (.4, 55.1562) (.5, 55.1562) (.6, 59.0625) (.7, 61.4062) (.8, 64.5312) (.9, 66.875)};
        \addplot coordinates {(.2, 52.6039) (.3, 55.2298) (.4, 56.5427) (.5, 56.3239) (.6, 58.2932) (.7, 60.0438) (.8, 60.4814) (.9, 63.7722)};
        \addplot coordinates {(.2, 48.0992) (.3, 48.9256) (.4, 48.0992) (.5, 50.5785) (.6, 54.7107) (.7, 58.843) (.8, 60.4959) (.9, 59.6694)};
        \addplot coordinates {(.2, 50.9609) (.3, 53.0961) (.4, 54.5196) (.5, 57.3665) (.6, 59.1459) (.7, 62.3488) (.8, 62.3488) (.9, 63.7722)};             
        \addplot coordinates {(.2, 40.7792) (.3, 44.6753) (.4, 44.6453) (.5, 47.2727) (.6, 51.1688) (.7, 55.0649) (.8, 56.3636) (.9, 62.8571)};
        \addplot coordinates {(.2, 39.4093) (.3, 42.7848) (.4, 47.0042) (.5, 47.4262) (.6, 48.27) (.7, 52.4895) (.8, 53.3333) (.9, 56.7089)};
        \addplot coordinates {(.2, 45) (.3, 45) (.4, 49.5455) (.5, 51.8182) (.6, 55.2273) (.7, 56.3636) (.8, 60.9091) (.9, 64.3182)};
        \addplot coordinates {(.2, 51.8367) (.3, 54.449) (.4, 54.9388) (.5, 55.7551) (.6, 55.2653) (.7, 57.2245) (.8, 58.9388) (.9, 59.4286)};
        \addplot coordinates {(.2, 53.1325) (.3, 53.7349) (.4, 55.9036) (.5, 57.7108) (.6, 58.4337) (.7, 59.8795) (.8, 62.6506) (.9, 65.0602)}; 
        \addplot coordinates {(.2, 56.0269) (.3, 58.3838) (.4, 62.4242) (.5, 65.1178) (.6, 65.7912) (.7, 67.138) (.8, 68.8215) (.9, 70.1684)};
        \legend{X1/Y1,X1/Y2,X1/Y3,X1/Y4,X2/Y1,X3/Y1,X4/Y1,X4/Y2,X5/Y1,X5/Y2,X6/Y1,X6/Y2,X7/Y1,X8/Y1,X9/Y1}
     \end{axis}
  \end{tikzpicture}       
\end{document}

在此处输入图片描述

附录:图例与情节一样高的版本(或者更准确地说,情节与图例一样高)。

\documentclass[border=5mm]{standalone}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{tikz,pgfplots,pgfplotstable}
\usepackage{tikz-qtree}
\usepackage{forest}
\usepackage{lettrine}
\usepackage{mathtools}
\usepackage{lscape}
\usepackage{pgf-pie}
\usepackage{caption}  
\usetikzlibrary{positioning,shapes,arrows,shadows,patterns,intersections,calc,fit}
\usepackage{dashbox}
\usepackage{mathptmx}
\usepackage{xcolor}
\usepackage{hyperref}
\pgfplotsset{compat=1.3}
\begin{document}         
\begin{tikzpicture}[scale=1.2, transform shape]
    \begin{axis}[           
        xlabel style={font=\tiny},        
        ylabel style={font=\tiny, yshift=-.3cm},
        xmin=.1, xmax=1,
        ymin=0, ymax=80,
        ytick={10,20,30,40,50,60,70,80},
        xtick={.1,.2,.3,.4,.5,.6,.7,.8,.9,1},
        xticklabel style={font=\tiny},
        yticklabel style={font=\tiny},
        width=2.8in,
        legend style={font=\tiny,at={(1.1,1)},anchor=north west}    
        ]               
        \addplot coordinates {(.2, 54.4086) (.3, 54.4086) (.4, 55.8423) (.5, 56.5591) (.6, 58.3513) (.7, 61.2186) (.8, 64.4444) (.9, 66.595)};
        \addplot coordinates {(.2, 50) (.3, 52.3214) (.4, 54.6429) (.5, 56.0714) (.6, 58.0357) (.7, 60) (.8, 62.1429) (.9, 64.1071)};
        \addplot coordinates {(.2, 54.5291) (.3, 59.0135) (.4, 60.3587) (.5, 61.0314) (.6, 61.4798) (.7, 63.9462) (.8, 63.722) (.9, 67.3094)};
        \addplot coordinates {(.2, 50.4569) (.3, 53.2487) (.4, 54.5178) (.5, 57.0558) (.6, 60.3553) (.7, 63.1472) (.8, 64.6701) (.9, 66.9543)};
        \addplot coordinates {(.2, 48.7097) (.3, 51.2903) (.4, 53.871) (.5, 55.1613) (.6, 58.0645) (.7, 59.0323) (.8, 61.6129) (.9, 64.8387)};  
        \addplot coordinates {(.2, 51.25) (.3, 55.1562) (.4, 55.1562) (.5, 55.1562) (.6, 59.0625) (.7, 61.4062) (.8, 64.5312) (.9, 66.875)};
        \addplot coordinates {(.2, 52.6039) (.3, 55.2298) (.4, 56.5427) (.5, 56.3239) (.6, 58.2932) (.7, 60.0438) (.8, 60.4814) (.9, 63.7722)};
        \addplot coordinates {(.2, 48.0992) (.3, 48.9256) (.4, 48.0992) (.5, 50.5785) (.6, 54.7107) (.7, 58.843) (.8, 60.4959) (.9, 59.6694)};
        \addplot coordinates {(.2, 50.9609) (.3, 53.0961) (.4, 54.5196) (.5, 57.3665) (.6, 59.1459) (.7, 62.3488) (.8, 62.3488) (.9, 63.7722)};             
        \addplot coordinates {(.2, 40.7792) (.3, 44.6753) (.4, 44.6453) (.5, 47.2727) (.6, 51.1688) (.7, 55.0649) (.8, 56.3636) (.9, 62.8571)};
        \addplot coordinates {(.2, 39.4093) (.3, 42.7848) (.4, 47.0042) (.5, 47.4262) (.6, 48.27) (.7, 52.4895) (.8, 53.3333) (.9, 56.7089)};
        \addplot coordinates {(.2, 45) (.3, 45) (.4, 49.5455) (.5, 51.8182) (.6, 55.2273) (.7, 56.3636) (.8, 60.9091) (.9, 64.3182)};
        \addplot coordinates {(.2, 51.8367) (.3, 54.449) (.4, 54.9388) (.5, 55.7551) (.6, 55.2653) (.7, 57.2245) (.8, 58.9388) (.9, 59.4286)};
        \addplot coordinates {(.2, 53.1325) (.3, 53.7349) (.4, 55.9036) (.5, 57.7108) (.6, 58.4337) (.7, 59.8795) (.8, 62.6506) (.9, 65.0602)}; 
        \addplot coordinates {(.2, 56.0269) (.3, 58.3838) (.4, 62.4242) (.5, 65.1178) (.6, 65.7912) (.7, 67.138) (.8, 68.8215) (.9, 70.1684)};
        \legend{X1/Y1,X1/Y2,X1/Y3,X1/Y4,X2/Y1,X3/Y1,X4/Y1,X4/Y2,X5/Y1,X5/Y2,X6/Y1,X6/Y2,X7/Y1,X8/Y1,X9/Y1}
     \end{axis}
  \end{tikzpicture}       
\end{document}

在此处输入图片描述

答案2

legend columns=3可能是一个选择。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\begin{document}         
\begin{tikzpicture}[scale=1.2, transform shape]
    \begin{axis}[           
        xlabel style={font=\tiny},        
        ylabel style={font=\tiny, yshift=-.3cm},
        xmin=.1, xmax=1,
        ymin=0, ymax=80,
        ytick={10,20,30,40,50,60,70,80},
        xtick={.1,.2,.3,.4,.5,.6,.7,.8,.9,1},
        xticklabel style={font=\tiny},
        yticklabel style={font=\tiny},
        width=2.5in,
        legend style={font=\tiny},
        legend pos=south east,
        legend columns=3 % <---- added this
        ]               
        \addplot coordinates {(.2, 54.4086) (.3, 54.4086) (.4, 55.8423) (.5, 56.5591) (.6, 58.3513) (.7, 61.2186) (.8, 64.4444) (.9, 66.595)};
        \addplot coordinates {(.2, 50) (.3, 52.3214) (.4, 54.6429) (.5, 56.0714) (.6, 58.0357) (.7, 60) (.8, 62.1429) (.9, 64.1071)};
        \addplot coordinates {(.2, 54.5291) (.3, 59.0135) (.4, 60.3587) (.5, 61.0314) (.6, 61.4798) (.7, 63.9462) (.8, 63.722) (.9, 67.3094)};
        \addplot coordinates {(.2, 50.4569) (.3, 53.2487) (.4, 54.5178) (.5, 57.0558) (.6, 60.3553) (.7, 63.1472) (.8, 64.6701) (.9, 66.9543)};
        \addplot coordinates {(.2, 48.7097) (.3, 51.2903) (.4, 53.871) (.5, 55.1613) (.6, 58.0645) (.7, 59.0323) (.8, 61.6129) (.9, 64.8387)};  
        \addplot coordinates {(.2, 51.25) (.3, 55.1562) (.4, 55.1562) (.5, 55.1562) (.6, 59.0625) (.7, 61.4062) (.8, 64.5312) (.9, 66.875)};
        \addplot coordinates {(.2, 52.6039) (.3, 55.2298) (.4, 56.5427) (.5, 56.3239) (.6, 58.2932) (.7, 60.0438) (.8, 60.4814) (.9, 63.7722)};
        \addplot coordinates {(.2, 48.0992) (.3, 48.9256) (.4, 48.0992) (.5, 50.5785) (.6, 54.7107) (.7, 58.843) (.8, 60.4959) (.9, 59.6694)};
        \addplot coordinates {(.2, 50.9609) (.3, 53.0961) (.4, 54.5196) (.5, 57.3665) (.6, 59.1459) (.7, 62.3488) (.8, 62.3488) (.9, 63.7722)};             
        \addplot coordinates {(.2, 40.7792) (.3, 44.6753) (.4, 44.6453) (.5, 47.2727) (.6, 51.1688) (.7, 55.0649) (.8, 56.3636) (.9, 62.8571)};
        \addplot coordinates {(.2, 39.4093) (.3, 42.7848) (.4, 47.0042) (.5, 47.4262) (.6, 48.27) (.7, 52.4895) (.8, 53.3333) (.9, 56.7089)};
        \addplot coordinates {(.2, 45) (.3, 45) (.4, 49.5455) (.5, 51.8182) (.6, 55.2273) (.7, 56.3636) (.8, 60.9091) (.9, 64.3182)};
        \addplot coordinates {(.2, 51.8367) (.3, 54.449) (.4, 54.9388) (.5, 55.7551) (.6, 55.2653) (.7, 57.2245) (.8, 58.9388) (.9, 59.4286)};
        \addplot coordinates {(.2, 53.1325) (.3, 53.7349) (.4, 55.9036) (.5, 57.7108) (.6, 58.4337) (.7, 59.8795) (.8, 62.6506) (.9, 65.0602)}; 
        \addplot coordinates {(.2, 56.0269) (.3, 58.3838) (.4, 62.4242) (.5, 65.1178) (.6, 65.7912) (.7, 67.138) (.8, 68.8215) (.9, 70.1684)};
        \legend{X1/Y1,X1/Y2,X1/Y3,X1/Y4,X2/Y1,X3/Y1,X4/Y1,X4/Y2,X5/Y1,X5/Y2,X6/Y1,X6/Y2,X7/Y1,X8/Y1,X9/Y1}
     \end{axis}
  \end{tikzpicture}       
\end{document}

相关内容