程式碼

程式碼

使用以下程式碼:

\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=4, ymin=0, ymax=10,
width=9cm, height=6cm,
legend style={draw=none}]

\addplot[only marks,color=red] coordinates {
(0, 10) (0.5, 8.5) (1, 2) (2, 0.5) (3.5, 1.9)};
\addlegendentry{Experimental Data Point}

\end{axis}
\end{tikzpicture}

我得到圖像:

在此輸入影像描述

根據我的口味,圖例中的符號與圖例文字有點接近。有沒有辦法增加兩者之間的間距?

答案1

根據pgfplots手冊,

圖例是一個 TikZ 矩陣,因此可以使用任何影響節點和矩陣的 TikZ 選項 [...]。矩陣是由類似的東西創建的

\matrix[style=every axis legend] {
    draw plot specification 1 & \node{legend 1}\\
    draw plot specification 2 & \node{legend 2}\\
    ...
};

因此,您可以增加 的column seplegend style達到所需的效果。

程式碼

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=4, ymin=0, ymax=10,
width=9cm, height=6cm,
legend style={draw=none,column sep=10pt}]

\addplot[only marks,color=red] coordinates {
(0, 10) (0.5, 8.5) (1, 2) (2, 0.5) (3.5, 1.9)};
\addlegendentry{Experimental Data Point}

\end{axis}
\end{tikzpicture}
\end{document}

輸出

在此輸入影像描述

答案2

如何\hphantom{A}在圖例條目中使用來增加兩者之間的空間。

在此輸入影像描述

程式碼

\documentclass[]{article}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0, xmax=4, ymin=0, ymax=10,
width=9cm, height=6cm, legend pos= north east,
legend style={}]
\addplot[only marks,color=red] coordinates {
(0, 10) (0.5, 8.5) (1, 2) (2, 0.5) (3.5, 1.9)};
\addlegendentry{\hphantom{A}Experimental Data Point}
\end{axis}
\end{tikzpicture}
\end{document}

相關內容