使用圖例條目

使用圖例條目

我寫了一個顯示曲線的程式碼,程式碼如下:

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{amsmath} 
\pgfplotsset{compat=1.18}
\usepackage{xcolor}
\begin{document}
\pgfplotstableread[col sep=comma]{
       -1.00000000e+00,  1.00000000e+00, -3.50000000e+00,         9.75000000e+00, -2.62500000e+01,  7.35937500e+01, -3.50000000e+00,         9.75000000e+00, -2.62500000e+01,  1.23005515e+02
       -5.78947368e-01,  1.00000000e+00, -3.07894737e+00,         6.97991690e+00, -1.45631652e+01,  3.17518749e+01, -3.07894737e+00,         6.97991690e+00, -1.45631652e+01,  5.91648918e+01
       -1.57894737e-01,  1.00000000e+00, -2.65789474e+00,         4.56440443e+00, -6.15144336e+00,  7.79163062e+00, -2.65789474e+00,         4.56440443e+00, -6.15144336e+00,  1.93708181e+01
        2.63157895e-01,  1.00000000e+00, -2.23684211e+00,         2.50346260e+00, -5.66955824e-01, -3.42580172e+00, -2.23684211e+00,         2.50346260e+00, -5.66955824e-01, -2.35859076e+00
        6.84210526e-01,  1.00000000e+00, -1.81578947e+00,         7.97091413e-01,  2.63817612e+00, -6.28491883e+00, -1.81578947e+00,         7.97091413e-01,  2.63817612e+00, -1.12508974e+01
        1.10526316e+00,  1.00000000e+00, -1.39473684e+00,        -5.54709141e-01,  3.91183117e+00, -4.41589541e+00, -1.39473684e+00,        -5.54709141e-01,  3.91183117e+00, -1.17793423e+01
        1.52631579e+00,  1.00000000e+00, -9.73684211e-01,        -1.55193906e+00,  3.70188803e+00, -6.94584190e-01, -9.73684211e-01,        -1.55193906e+00,  3.70188803e+00, -7.66284401e+00
        1.94736842e+00,  1.00000000e+00, -5.52631579e-01,        -2.19459834e+00,  2.45622540e+00,  2.75748416e+00, -5.52631579e-01,        -2.19459834e+00,  2.45622540e+00, -1.86599894e+00
        2.36842105e+00,  1.00000000e+00, -1.31578947e-01,        -2.48268698e+00,  6.22721971e-01,  4.57310099e+00, -1.31578947e-01,        -2.48268698e+00,  6.22721971e-01,  3.40091845e+00
        2.78947368e+00,  1.00000000e+00,  2.89473684e-01,        -2.41620499e+00, -1.35074355e+00,  4.13937964e+00,  2.89473684e-01,        -2.41620499e+00, -1.35074355e+00,  6.68195573e+00
        3.21052632e+00,  1.00000000e+00,  7.10526316e-01,        -1.99515235e+00, -3.01629246e+00,  1.59775549e+00,  7.10526316e-01,        -1.99515235e+00, -3.01629246e+00,  7.27548248e+00
        3.63157895e+00,  1.00000000e+00,  1.13157895e+00,        -1.21952909e+00, -3.92604607e+00, -2.15601404e+00,  1.13157895e+00,        -1.21952909e+00, -3.92604607e+00,  5.23419032e+00
        4.05263158e+00,  1.00000000e+00,  1.55263158e+00,        -8.93351801e-02, -3.63212567e+00, -5.47184956e+00,  1.55263158e+00,        -8.93351801e-02, -3.63212567e+00,  1.36509289e+00
        4.47368421e+00,  1.00000000e+00,  1.97368421e+00,         1.39542936e+00, -1.68665257e+00, -5.94534961e+00,  1.97368421e+00,         1.39542936e+00, -1.68665257e+00, -2.77047418e+00
        4.89473684e+00,  1.00000000e+00,  2.39473684e+00,         3.23476454e+00,  2.35825193e+00, -4.17790734e-01,  2.39473684e+00,         3.23476454e+00,  2.35825193e+00, -4.85685319e+00
        5.31578947e+00,  1.00000000e+00,  2.81578947e+00,         5.42867036e+00,  8.95046654e+00,  1.50238725e+01,  2.81578947e+00,         5.42867036e+00,  8.95046654e+00, -1.82406447e+00
        5.73684211e+00,  1.00000000e+00,  3.23684211e+00,         7.97714681e+00,  1.85378700e+01,  4.50470077e+01,  3.23684211e+00,         7.97714681e+00,  1.85378700e+01,  1.01521937e+01
        6.15789474e+00,  1.00000000e+00,  3.65789474e+00,         1.08801939e+01,  3.15683409e+01,  9.50733043e+01,  3.65789474e+00,         1.08801939e+01,  3.15683409e+01,  3.56505451e+01
        6.57894737e+00,  1.00000000e+00,  4.07894737e+00,         1.41378116e+01,  4.84897580e+01,  1.71278774e+02,  4.07894737e+00,         1.41378116e+01,  4.84897580e+01,  8.00039353e+01
        7.00000000e+00,  1.00000000e+00,  4.50000000e+00,         1.77500000e+01,  6.97500000e+01,  2.80593750e+02,  4.50000000e+00,         1.77500000e+01,  6.97500000e+01,  1.49299632e+02 
                
}\loadedtable
\begin{figure}[h]
\tikzset{ellipsenode/.style={draw, ellipse, thick, text width=5ex, align=center, inner sep=2pt}}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
xmin=-0.6,  xmax=6.6,
ymin=-17,  ymax=28,
axis on top,
xtick distance=1,
ytick distance=5,
tick label style={font=\footnotesize, inner sep=1pt, fill=white},
no marks, samples=15, smooth,
legend entries={
        $Q^{1/2,1/2,5}_{0}(x)$,
        $Q^{1/2,1/2,5}_{1}(x)$,
        $Q^{1/2,1/2,5}_{2}(x)$,
        $Q^{1/2,1/2,5}_{3}(x)$,
        $Q^{1/2,1/2,5}_{4}(x)$
},                ]
\addplot[color=red] table[x index=0,y index=1] {\loadedtable};
\addplot[color=blue]table[x index=0,y index=2] {\loadedtable};
\addplot[color=green] table[x index=0,y index=3] {\loadedtable};
\addplot[color=purple] table[x index=0,y index=4] {\loadedtable};
\addplot[color=yellow] table[x index=0,y index=5] {\loadedtable};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
xmin=-0.6,  xmax=6.6,
ymin=-17,  ymax=28,
axis on top,
xtick distance=1,
ytick distance=5,
tick label style={font=\footnotesize, inner sep=1pt, fill=white},
no marks, samples=15, smooth,
legend entries={
        $Q^{(3)}_{0}(x)$,
        $Q^{(3)}_{1}(x)$,
        $Q^{(3)}_{2}(x)$,
        $Q^{(3)}_{3}(x)$,
        $Q^{(3)}_{4}(x)$
},    
   ]
\addplot[color=red] table[x index=0,y index=1] {\loadedtable};
\addplot[color=blue]table[x index=0,y index=6] {\loadedtable};
\addplot[color=green] table[x index=0,y index=7] {\loadedtable};
\addplot[color=purple] table[x index=0,y index=8] {\loadedtable};
\addplot[color=yellow] table[x index=0,y index=9] {\loadedtable};
\end{axis}
\end{tikzpicture}
\caption{Graph of $Q^{1/2,1/2,5}_n$ and $Q^{(3)}_n$ for $n = 0, 1, 2, 3, 4$}
\end{figure}
\end{document}

結果

在此輸入影像描述

但在編譯結果中,我希望兩個描述表夠小,以便更好地看到圖形。請給個主意

答案1

沃特。我的評論帶有鏈接這是設計或排版您自己的圖例的方法。為了更好地看到差異並避免混亂,我將其作為單獨的答案。

結果較小

評論

前言

對於設計,最好使用 class standalone,因為它會根據需要調整到「紙張」尺寸。xcolor這裡不需要包。我們需要 tikzlibrarymatrix來排版圖例。

\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{pgfplots}
\usepackage{amsmath} 
\pgfplotsset{compat=1.18}
%\usepackage{xcolor}    % <<< not needed in pgfplots
\usetikzlibrary{matrix} % <<< to typeset the legend, later

繪圖集

它已經過時了,因為我們不使用內建圖例。

%    \pgfplotsset{
%       every axis legend/.append style={
%           at={(1.02,1)},
%           anchor=north west,
%       },
%    }

軸環境

  • 讓我們取個標題
  • 刪除所有圖例語句
  • \label在每個之後添加一個\addplot ... ;
  • 定義一個\coordinate稍後再使用,這裡稱為(label)
    \begin{axis}[
        ...
        no marks, samples=15, smooth,
        title=$Q^{1/2,1/2,5}_n(x)$; % <<<
    ]
    % <<< new: put labels, to reference them later ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    \addplot[color=red] table[x index=0,y index=1] {\loadedtable};\label{plot:L1}
    ...
    
    % <<< new: legend will go here, in plot coordinates
    \coordinate (legend) at (.3,25);
    \end{axis}

排版你的傳奇

基本結構\matrix[...] at (legend) { ... };很像您對\node.您需要定義一些樣式才能按照您想要的方式查看它。

可以將\matrix其視為 Tikz 的下屬Latex table。這就是為什麼您會看到& & \\一行資料的結構。在裡面,您只需像常規文字一樣進行排版,並引用先前設定的所有繪圖標籤。與所有引用一樣,它們在引入更改後需要進行第二次編譯。

    % ~~~ building your legend using a matrix (it's like a table within Tikz) ~~~~
    \matrix[
        draw,               % to see it, with
        matrix of nodes,    % see manual
        anchor=north west,  % upper left corner
        font={\tiny},       % use smaller font, if you like
    ] at (legend) {
        Index $n$: &&\\
        \ref{plot:L1} 0&\ref{plot:L2} 1&\ref{plot:L3} 2\\
        \ref{plot:L4} 3&\ref{plot:L5} 4&\\
    };  

結果及程式碼

結果

\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{pgfplots}
\usepackage{amsmath} 
\pgfplotsset{compat=1.18}
%\usepackage{xcolor}    % <<< not needed in pgfplots
\usetikzlibrary{matrix} % <<< to typeset the legend, later

% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
    \pgfplotstableread[col sep=comma]{
           -1.00000000e+00,  1.00000000e+00, -3.50000000e+00,         9.75000000e+00, -2.62500000e+01,  7.35937500e+01, -3.50000000e+00,         9.75000000e+00, -2.62500000e+01,  1.23005515e+02
           -5.78947368e-01,  1.00000000e+00, -3.07894737e+00,         6.97991690e+00, -1.45631652e+01,  3.17518749e+01, -3.07894737e+00,         6.97991690e+00, -1.45631652e+01,  5.91648918e+01
           -1.57894737e-01,  1.00000000e+00, -2.65789474e+00,         4.56440443e+00, -6.15144336e+00,  7.79163062e+00, -2.65789474e+00,         4.56440443e+00, -6.15144336e+00,  1.93708181e+01
            2.63157895e-01,  1.00000000e+00, -2.23684211e+00,         2.50346260e+00, -5.66955824e-01, -3.42580172e+00, -2.23684211e+00,         2.50346260e+00, -5.66955824e-01, -2.35859076e+00
            6.84210526e-01,  1.00000000e+00, -1.81578947e+00,         7.97091413e-01,  2.63817612e+00, -6.28491883e+00, -1.81578947e+00,         7.97091413e-01,  2.63817612e+00, -1.12508974e+01
            1.10526316e+00,  1.00000000e+00, -1.39473684e+00,        -5.54709141e-01,  3.91183117e+00, -4.41589541e+00, -1.39473684e+00,        -5.54709141e-01,  3.91183117e+00, -1.17793423e+01
            1.52631579e+00,  1.00000000e+00, -9.73684211e-01,        -1.55193906e+00,  3.70188803e+00, -6.94584190e-01, -9.73684211e-01,        -1.55193906e+00,  3.70188803e+00, -7.66284401e+00
            1.94736842e+00,  1.00000000e+00, -5.52631579e-01,        -2.19459834e+00,  2.45622540e+00,  2.75748416e+00, -5.52631579e-01,        -2.19459834e+00,  2.45622540e+00, -1.86599894e+00
            2.36842105e+00,  1.00000000e+00, -1.31578947e-01,        -2.48268698e+00,  6.22721971e-01,  4.57310099e+00, -1.31578947e-01,        -2.48268698e+00,  6.22721971e-01,  3.40091845e+00
            2.78947368e+00,  1.00000000e+00,  2.89473684e-01,        -2.41620499e+00, -1.35074355e+00,  4.13937964e+00,  2.89473684e-01,        -2.41620499e+00, -1.35074355e+00,  6.68195573e+00
            3.21052632e+00,  1.00000000e+00,  7.10526316e-01,        -1.99515235e+00, -3.01629246e+00,  1.59775549e+00,  7.10526316e-01,        -1.99515235e+00, -3.01629246e+00,  7.27548248e+00
            3.63157895e+00,  1.00000000e+00,  1.13157895e+00,        -1.21952909e+00, -3.92604607e+00, -2.15601404e+00,  1.13157895e+00,        -1.21952909e+00, -3.92604607e+00,  5.23419032e+00
            4.05263158e+00,  1.00000000e+00,  1.55263158e+00,        -8.93351801e-02, -3.63212567e+00, -5.47184956e+00,  1.55263158e+00,        -8.93351801e-02, -3.63212567e+00,  1.36509289e+00
            4.47368421e+00,  1.00000000e+00,  1.97368421e+00,         1.39542936e+00, -1.68665257e+00, -5.94534961e+00,  1.97368421e+00,         1.39542936e+00, -1.68665257e+00, -2.77047418e+00
            4.89473684e+00,  1.00000000e+00,  2.39473684e+00,         3.23476454e+00,  2.35825193e+00, -4.17790734e-01,  2.39473684e+00,         3.23476454e+00,  2.35825193e+00, -4.85685319e+00
            5.31578947e+00,  1.00000000e+00,  2.81578947e+00,         5.42867036e+00,  8.95046654e+00,  1.50238725e+01,  2.81578947e+00,         5.42867036e+00,  8.95046654e+00, -1.82406447e+00
            5.73684211e+00,  1.00000000e+00,  3.23684211e+00,         7.97714681e+00,  1.85378700e+01,  4.50470077e+01,  3.23684211e+00,         7.97714681e+00,  1.85378700e+01,  1.01521937e+01
            6.15789474e+00,  1.00000000e+00,  3.65789474e+00,         1.08801939e+01,  3.15683409e+01,  9.50733043e+01,  3.65789474e+00,         1.08801939e+01,  3.15683409e+01,  3.56505451e+01
            6.57894737e+00,  1.00000000e+00,  4.07894737e+00,         1.41378116e+01,  4.84897580e+01,  1.71278774e+02,  4.07894737e+00,         1.41378116e+01,  4.84897580e+01,  8.00039353e+01
            7.00000000e+00,  1.00000000e+00,  4.50000000e+00,         1.77500000e+01,  6.97500000e+01,  2.80593750e+02,  4.50000000e+00,         1.77500000e+01,  6.97500000e+01,  1.49299632e+02 
                
}\loadedtable

\tikzset{
    ellipsenode/.style={
        draw, ellipse, thick, text width=5ex, 
        align=center, inner sep=2pt
    }
}

    \begin{tikzpicture}
%    \pgfplotsset{
%       every axis legend/.append style={
%           at={(1.02,1)},
%           anchor=north west,
%       },
%    }
    \begin{axis}[
        axis lines=center,
        xmin=-0.6,  xmax=6.6,
        ymin=-17,  ymax=28,
        axis on top,
        xtick distance=1,
        ytick distance=5,
        tick label style={font=\footnotesize, inner sep=1pt, fill=white},
        no marks, samples=15, smooth,
        title=$Q^{1/2,1/2,5}_n(x)$; % <<<
    ]
    % <<< new: put labels, to reference them later ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    \addplot[color=red] table[x index=0,y index=1] {\loadedtable};\label{plot:L1}
    \addplot[color=blue]table[x index=0,y index=2] {\loadedtable};\label{plot:L2}
    \addplot[color=green] table[x index=0,y index=3] {\loadedtable};\label{plot:L3}
    \addplot[color=purple] table[x index=0,y index=4] {\loadedtable};\label{plot:L4}
    \addplot[color=yellow] table[x index=0,y index=5] {\loadedtable};\label{plot:L5}
    
    % <<< new: legend will go here, in plot coordinates
    \coordinate (legend) at (.3,25);
    \end{axis}
    
    % ~~~ building your legend using a matrix (it's like a table within Tikz) ~~~~
    \matrix[
        draw,               % to see it, with
        matrix of nodes,    % see manual
        anchor=north west,  % upper left corner
        font={\tiny},       % use smaller font, if you like
    ] at (legend) {
        Index $n$: &&\\
        \ref{plot:L1} 0&\ref{plot:L2} 1&\ref{plot:L3} 2\\
        \ref{plot:L4} 3&\ref{plot:L5} 4&\\
    };  
    \end{tikzpicture}
\end{document}

答案2

這是一種方法。最簡單的方法是將圖例放置在繪圖之外,例如右側。章。 《4.9.5 圖例外觀》(pdf)或者「20.9 圖例外觀」(html)在 pgfplots 手冊中對此進行了描述。

我嘗試將圖例放在上面,但看起來不太好。您也可以使用上述章節第一頁中所述的方法 Tikz 來繪製您自己的圖例:

% from said chapter, sth. like this:
 \matrix [style=every axis legend] {
    draw plot specification 1 & \node{legend 1}\\
...

另一種選擇可能是在文章中引入許多函數的縮寫,並將其與繪圖一起使用。當它們較短時,這兩張圖可能適合您發布的 1 行圖。

與您的程式碼的區別在於這行程式碼,我將其添加到您的兩個圖表中:

  • 指定軸圖例樣式
  • 回想手冊中,(0,0) 是左下角,(1,1) 是右上角
  • 將圖例稍微移至右上角
  • 將其左上角 ( north west) 錨定到該位置
\begin{tikzpicture}
\pgfplotsset{                                 % <<<
    every axis legend/.append style={
        at={(1.02,1)},
        anchor=north west
    },
}
\begin{axis}[

結果

% https://tex.stackexchange.com/questions/705129/using-legend-entries

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{amsmath} 
\pgfplotsset{compat=1.18}
\usepackage{xcolor}
\begin{document}
\pgfplotstableread[col sep=comma]{
       -1.00000000e+00,  1.00000000e+00, -3.50000000e+00,         9.75000000e+00, -2.62500000e+01,  7.35937500e+01, -3.50000000e+00,         9.75000000e+00, -2.62500000e+01,  1.23005515e+02
       -5.78947368e-01,  1.00000000e+00, -3.07894737e+00,         6.97991690e+00, -1.45631652e+01,  3.17518749e+01, -3.07894737e+00,         6.97991690e+00, -1.45631652e+01,  5.91648918e+01
       -1.57894737e-01,  1.00000000e+00, -2.65789474e+00,         4.56440443e+00, -6.15144336e+00,  7.79163062e+00, -2.65789474e+00,         4.56440443e+00, -6.15144336e+00,  1.93708181e+01
        2.63157895e-01,  1.00000000e+00, -2.23684211e+00,         2.50346260e+00, -5.66955824e-01, -3.42580172e+00, -2.23684211e+00,         2.50346260e+00, -5.66955824e-01, -2.35859076e+00
        6.84210526e-01,  1.00000000e+00, -1.81578947e+00,         7.97091413e-01,  2.63817612e+00, -6.28491883e+00, -1.81578947e+00,         7.97091413e-01,  2.63817612e+00, -1.12508974e+01
        1.10526316e+00,  1.00000000e+00, -1.39473684e+00,        -5.54709141e-01,  3.91183117e+00, -4.41589541e+00, -1.39473684e+00,        -5.54709141e-01,  3.91183117e+00, -1.17793423e+01
        1.52631579e+00,  1.00000000e+00, -9.73684211e-01,        -1.55193906e+00,  3.70188803e+00, -6.94584190e-01, -9.73684211e-01,        -1.55193906e+00,  3.70188803e+00, -7.66284401e+00
        1.94736842e+00,  1.00000000e+00, -5.52631579e-01,        -2.19459834e+00,  2.45622540e+00,  2.75748416e+00, -5.52631579e-01,        -2.19459834e+00,  2.45622540e+00, -1.86599894e+00
        2.36842105e+00,  1.00000000e+00, -1.31578947e-01,        -2.48268698e+00,  6.22721971e-01,  4.57310099e+00, -1.31578947e-01,        -2.48268698e+00,  6.22721971e-01,  3.40091845e+00
        2.78947368e+00,  1.00000000e+00,  2.89473684e-01,        -2.41620499e+00, -1.35074355e+00,  4.13937964e+00,  2.89473684e-01,        -2.41620499e+00, -1.35074355e+00,  6.68195573e+00
        3.21052632e+00,  1.00000000e+00,  7.10526316e-01,        -1.99515235e+00, -3.01629246e+00,  1.59775549e+00,  7.10526316e-01,        -1.99515235e+00, -3.01629246e+00,  7.27548248e+00
        3.63157895e+00,  1.00000000e+00,  1.13157895e+00,        -1.21952909e+00, -3.92604607e+00, -2.15601404e+00,  1.13157895e+00,        -1.21952909e+00, -3.92604607e+00,  5.23419032e+00
        4.05263158e+00,  1.00000000e+00,  1.55263158e+00,        -8.93351801e-02, -3.63212567e+00, -5.47184956e+00,  1.55263158e+00,        -8.93351801e-02, -3.63212567e+00,  1.36509289e+00
        4.47368421e+00,  1.00000000e+00,  1.97368421e+00,         1.39542936e+00, -1.68665257e+00, -5.94534961e+00,  1.97368421e+00,         1.39542936e+00, -1.68665257e+00, -2.77047418e+00
        4.89473684e+00,  1.00000000e+00,  2.39473684e+00,         3.23476454e+00,  2.35825193e+00, -4.17790734e-01,  2.39473684e+00,         3.23476454e+00,  2.35825193e+00, -4.85685319e+00
        5.31578947e+00,  1.00000000e+00,  2.81578947e+00,         5.42867036e+00,  8.95046654e+00,  1.50238725e+01,  2.81578947e+00,         5.42867036e+00,  8.95046654e+00, -1.82406447e+00
        5.73684211e+00,  1.00000000e+00,  3.23684211e+00,         7.97714681e+00,  1.85378700e+01,  4.50470077e+01,  3.23684211e+00,         7.97714681e+00,  1.85378700e+01,  1.01521937e+01
        6.15789474e+00,  1.00000000e+00,  3.65789474e+00,         1.08801939e+01,  3.15683409e+01,  9.50733043e+01,  3.65789474e+00,         1.08801939e+01,  3.15683409e+01,  3.56505451e+01
        6.57894737e+00,  1.00000000e+00,  4.07894737e+00,         1.41378116e+01,  4.84897580e+01,  1.71278774e+02,  4.07894737e+00,         1.41378116e+01,  4.84897580e+01,  8.00039353e+01
        7.00000000e+00,  1.00000000e+00,  4.50000000e+00,         1.77500000e+01,  6.97500000e+01,  2.80593750e+02,  4.50000000e+00,         1.77500000e+01,  6.97500000e+01,  1.49299632e+02 
                
}\loadedtable
\begin{figure}[h]
\tikzset{ellipsenode/.style={draw, ellipse, thick, text width=5ex, align=center, inner sep=2pt}}
\begin{tikzpicture}
\pgfplotsset{
    every axis legend/.append style={
        at={(1.02,1)},
        anchor=north west
    },
}
\begin{axis}[
axis lines=center,
xmin=-0.6,  xmax=6.6,
ymin=-17,  ymax=28,
axis on top,
xtick distance=1,
ytick distance=5,
tick label style={font=\footnotesize, inner sep=1pt, fill=white},
no marks, samples=15, smooth,
legend entries={
        $Q^{1/2,1/2,5}_{0}(x)$,
        $Q^{1/2,1/2,5}_{1}(x)$,
        $Q^{1/2,1/2,5}_{2}(x)$,
        $Q^{1/2,1/2,5}_{3}(x)$,
        $Q^{1/2,1/2,5}_{4}(x)$
},                ]
\addplot[color=red] table[x index=0,y index=1] {\loadedtable};
\addplot[color=blue]table[x index=0,y index=2] {\loadedtable};
\addplot[color=green] table[x index=0,y index=3] {\loadedtable};
\addplot[color=purple] table[x index=0,y index=4] {\loadedtable};
\addplot[color=yellow] table[x index=0,y index=5] {\loadedtable};
\end{axis}
\end{tikzpicture}
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{tikzpicture}
\pgfplotsset{
    every axis legend/.append style={
        at={(1.02,1)},
        anchor=north west
    },
}
\begin{axis}[
axis lines=center,
xmin=-0.6,  xmax=6.6,
ymin=-17,  ymax=28,
axis on top,
xtick distance=1,
ytick distance=5,
tick label style={font=\footnotesize, inner sep=1pt, fill=white},
no marks, samples=15, smooth,
legend entries={
        $Q^{(3)}_{0}(x)$,
        $Q^{(3)}_{1}(x)$,
        $Q^{(3)}_{2}(x)$,
        $Q^{(3)}_{3}(x)$,
        $Q^{(3)}_{4}(x)$
},    
   ]
\addplot[color=red] table[x index=0,y index=1] {\loadedtable};
\addplot[color=blue]table[x index=0,y index=6] {\loadedtable};
\addplot[color=green] table[x index=0,y index=7] {\loadedtable};
\addplot[color=purple] table[x index=0,y index=8] {\loadedtable};
\addplot[color=yellow] table[x index=0,y index=9] {\loadedtable};
\end{axis}
\end{tikzpicture}
\caption{Graph of $Q^{1/2,1/2,5}_n$ and $Q^{(3)}_n$ for $n = 0, 1, 2, 3, 4$}
\end{figure}
\end{document}

附:

作為參考,這是將圖例移到圖頂部時得到的結果:

結果2

透過用於兩者:

\pgfplotsset{
    every axis legend/.append style={
        at={(.5,1.03)},
        anchor=south
    },
}

PS 2

title這是使用 a並僅關注相關更改的替代方案: n。然而,即使只列出 0, 1, ... 也不會使這裡的圖例足夠小。

結果3

\begin{axis}[
    axis lines=center,
    xmin=-0.6,  xmax=6.6,
    ymin=-17,  ymax=28,
    axis on top,
    xtick distance=1,
    ytick distance=5,
    tick label style={font=\footnotesize, inner sep=1pt, fill=white},
    no marks, samples=15, smooth,
    legend entries={
            $n=0$,              % <<<
            $n=1$,
            $n=2$,
            $n=3$,
            $n=4$,
    },
    title=$Q^{1/2,1/2,5}_n(x)$; % <<<
]

相關內容