2 行图例和对齐

2 行图例和对齐

我有一个包含两行的图例,我想让每行有不同的对齐方式。 可以吗?

在我当前的代码中,第二行的图例条目比第一行的图例条目长得多。这导致第一行图例条目之间有额外的空间,我想避免这种情况。这是我的代码:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{semilogyaxis}[xmin=0, xmax=600, ymin=1e-1, ymax=1e7, axis x line*=bottom, axis y line*=left, xlabel={X}, ylabel={Y},width=0.9\textwidth, height=0.5\textwidth, legend columns=3, legend style={cells={anchor=west}, at={(1,0.3)}, anchor=east}]

\addplot [color=red, domain=0:600, samples=1000, thick, mark=none] {(1+4*x^2) };
\addlegendentry{A}
\addplot [color=blue, domain=0:600, samples=1000, thick, mark=none] {1+2*x };
\addlegendentry{B}
\addplot [color=green!80!black, domain=0:600, samples=1000, thick, mark=none] {1.};
\addlegendentry{C}

\addlegendimage{black, thick}
\addlegendentry{Numerical}
\addlegendimage{black, ultra thick, loosely dashed}
\addlegendentry{Analytical}

\addplot[color=red, domain=0:600, loosely dashed, samples=1000, ultra thick] {(1+4*x^2) };
\addplot[color=blue, domain=0:600, loosely dashed, samples=1000, ultra thick] {1+2*x };
\addplot[color=green!80!black, domain=0:600, loosely dashed, samples=1000, ultra thick] {1.};

\end{semilogyaxis}
\end{tikzpicture}
\end{figure}
\end{document}

谢谢 !

答案1

我发现了一个肮脏的方法......它有效,但我认为这不是最好的方法:)有人有其他想法吗?

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{semilogyaxis}[xmin=0, xmax=600, ymin=1e-1, ymax=1e7, axis x line*=bottom, axis y line*=left, xlabel={X}, ylabel={Y},width=0.9\textwidth, height=0.5\textwidth, legend columns=3, legend style={fill=none, draw=none, cells={anchor=west}, at={(0.74,0.3)}, anchor=south}
]

\addplot [color=red, domain=0:600, samples=10, thick, mark=none] {(1+4*x^2) };
\addlegendentry{A}
\addplot [color=blue, domain=0:600, samples=10, thick, mark=none] {1+2*x };
\addlegendentry{B}
\addplot [color=green!80!black, domain=0:600, samples=10, thick, mark=none] {1.};
\addlegendentry{C}

\addplot[color=red, domain=0:600, loosely dashed, samples=10, ultra thick] {(1+4*x^2) };
\addplot[color=blue, domain=0:600, loosely dashed, samples=10, ultra thick] {1+2*x };
\addplot[color=green!80!black, domain=0:600, loosely dashed, samples=10, ultra thick] {1.};

\end{semilogyaxis}
\begin{semilogyaxis}[xmin=0, xmax=600, ymin=1e-1, ymax=1e7, axis x line*=bottom, axis y line*=left, xlabel={X}, ylabel={Y},width=0.9\textwidth, height=0.5\textwidth, legend columns=2, legend style={fill=none, draw=none, cells={anchor=west}, at={(0.74,0.3)}, anchor=north}
]

\addlegendimage{black, ultra thick, loosely dashed}
\addlegendentry{Analytical}
\addlegendimage{black, thick}
\addlegendentry{Numerical}

\draw[black, solid, thick] (axis description cs:0.47,0.18) rectangle (axis description cs:1,0.42);

\end{semilogyaxis}
\end{tikzpicture}
\end{figure}
\end{document}

相关内容