
如圖中圓圈所示,之間有一點間隙0和邊界。我怎樣才能消除這個小間隙?
微量元素
產生上圖的範例程式碼
% in preamble
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
x,y
0.01,0.9583333333
0.02,0.8125
%...100 in total...
\end{filecontents*}
% in document
\begin{figure}[t]
\begin{tikzpicture}
\pgfplotsset{legend style={font=\tiny}}
\begin{axis}[
xlabel={Recall},
xtick={0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1},
ylabel={Precision},
ytick={0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1},
legend cell align=left,
legend pos=north east]
\addplot[c1, thin, mark=square, mark repeat=5] table[x=x, y=y, col sep=comma] {data.csv};
\addlegendentry{x-y};
\end{axis}
\end{tikzpicture}
\caption{plot}\label{fig:plot}
\end{figure}
更新:
這是我使用 Matlab 所期望的。注意左下角有一個0x 軸和 y 軸共享的標籤。
答案1
評論中的一些建議導致了解決方案。
預設情況下,pgfplots
當它根據繪圖資料自動偵測軸限制時,將稍微放大繪圖視窗。鍵設定enlargelimits=false
或enlarge x limits=false
可以分別用於防止所有軸或單一軸發生這種情況。
但是,在這種情況下,繪製資料的邊界與所需的軸限制不符。在這裡,明確設定軸限制(xmin=0
等)可以得到所需的結果:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
x,y
0.01,0.9583333333
0.02,0.8125
%...100 in total...
0.99,0.1875
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
enlarge x limits=false,
xlabel={Recall},
xmin=0,xmax=1,
xtick={0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1},
ylabel={Precision},
ymin=0.1,ymax=1,
ytick={0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1},
]
\addplot table[x=x, y=y, col sep=comma] {data.csv};
\addlegendentry{x-y};
\end{axis}
\end{tikzpicture}
\end{document}