这是我的代码:
\documentclass[11pt]{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{float}
\usepackage{pgfplots,pgfplotstable, booktabs}
\usetikzlibrary{pgfplots.groupplots, matrix}
\pgfplotsset{compat=1.10, title/.append style={align =center}}
\pgfplotsset{minor grid style={dashed,red}}
\pgfplotsset{major grid style={dotted,green!50!black}}
\begin{filecontents*}{jobname}
1 0.055 0.348
2 0.123 0.565
3 0.110 0.304
4 0.068 0.609
5 0.137 0.435
6 0.096 0.304
7 0.110 0.261
8 0.082 0.522
9 0.123 0.435
10 0.123 0.435
100 0.192 0.217
\end{filecontents*}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{groupplot}[group style={
group size=2 by 2,
vertical sep=1.7cm,
horizontal sep = 1cm,
ylabels at=edge left,group name=ape},
width=8.2cm,
height=5.0cm,
try min ticks=5,
tick label style={font=\footnotesize},
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd}
]
\nextgroupplot[align =center, title={\hspace*{1cm}\textbf{Cost Sensitivity Plots}}, grid=both, every major grid/.style={gray, opacity=0.5},
smooth,
xlabel = (a) Bagging--J8,xmin=0,ymax=0.8,ymin=0.00]
\addplot [line width=1.6pt,
mark=none,
blue,
mark options={scale=.65}]%
table[x index=0,y index=1,col sep=space]
{jobname};\label{plots:plot1}
\addplot [line width=1.6pt,
mark=none,
red,
mark options={scale=.65}]%
table[x index=0,y index=2,col sep=space] {jobname};\label{plots:plot2}
\coordinate (top) at (rel axis cs:0,1);
\nextgroupplot[grid=both, every major grid/.style={gray, opacity=0.5},smooth,xlabel = (c) Bagging--Decision Stump,xmin=0, ymax=0.8]
\addplot [line width=1.6pt,
mark=none,
blue,
mark options={scale=.65}]%
table[x index=0,y index=1,col sep=space]
{jobname};
\addplot [line width=1.6pt,
mark=none,
red,
mark options={scale=.65}]%
table[x index=0,y index=2,col sep=space]
{jobname};
\nextgroupplot[grid=both, every major grid/.style={gray, opacity=0.5},smooth,xlabel = (e) AdaBoostM1--J8,xmin=0,ymax=0.8]
\addplot [line width=1.6pt,
mark=none,
blue,
mark options={scale=.65}]%
table[x index=0,y index=1,col sep=space]
{jobname};
\addplot [line width=1.6pt,
mark=none,
red,
mark options={scale=.65}]%
table[x index=0,y index=2,col sep=space]
{jobname};
\nextgroupplot[grid=both, every major grid/.style={gray, opacity=0.5},
smooth,
xlabel = (g) AdaBoostM1--Decision Stump,xmin=0,ymin=0,ymax=0.8]
\addplot [legend pos=north west,
line width=1.6pt,
mark=none,
blue,
mark options={scale=.65}]%
table[x index=0,y index=1,col sep=space]
{jobname};
\addplot [line width=1.6pt,
mark=none,
red,
mark options={scale=.65}]%
table[x index=0,y index=2,col sep=space]
{jobname};
\coordinate (bot) at (rel axis cs:1,0);
\end{groupplot}
\foreach \row in {1,2}
\path (ape c1r\row.south east) --node[below=1cm]{\textbf{Ratio}} (ape c2r\row.south west);
\path (top-|current bounding box.west)--
node[anchor=south,rotate=90] {\large{\bf{Misclassification Rate}}}
(bot-|current bounding box.west);
% legend
\path (top|-current bounding box.north)--
coordinate(legendpos)
(bot|-current bounding box.north);
\matrix[
matrix of nodes,
anchor=south,
draw,
inner sep=0.2em,
draw
]at([yshift=1ex]legendpos)
{
\ref{plots:plot1}& Type 1 &[5pt]
\ref{plots:plot2}& Type 2 &[5pt]\\};
\end{tikzpicture}
\caption[FIT and TEST Data for various Classifier and Meta Learning Schemes]{FIT and TEST Data for various Classifier and Meta Learning Schemes.}\label{FIT_TEST}
\end{figure}
\end{document}
答案1
您可以对标题使用与 相同的技巧\textbf{Ratio}
。但是,我应该指出, tikzpicture 不适合页边距(showframe)。
\documentclass[11pt]{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{float}
\usepackage{pgfplots,pgfplotstable, booktabs}
\usetikzlibrary{pgfplots.groupplots, matrix}
\pgfplotsset{compat=1.10, title/.append style={align =center}}
\pgfplotsset{minor grid style={dashed,red}}
\pgfplotsset{major grid style={dotted,green!50!black}}
\begin{filecontents*}{jobname}
1 0.055 0.348
2 0.123 0.565
3 0.110 0.304
4 0.068 0.609
5 0.137 0.435
6 0.096 0.304
7 0.110 0.261
8 0.082 0.522
9 0.123 0.435
10 0.123 0.435
100 0.192 0.217
\end{filecontents*}
\begin{document}
\begin{figure}% friends don't let frineds use [H]
\centering
\begin{tikzpicture}
\begin{groupplot}[group style={
group size=2 by 2,
vertical sep=1.7cm,
horizontal sep = 1cm,
ylabels at=edge left,group name=ape},
width=8.2cm,
height=5.0cm,
try min ticks=5,
tick label style={font=\footnotesize},
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd}
]
\nextgroupplot[align =center, grid=both, every major grid/.style={gray, opacity=0.5},
xlabel = (a) Bagging--J8,xmin=0,ymax=0.8,ymin=0.00]
\addplot [line width=1.6pt,
mark=none,
blue,
mark options={scale=.65}]%
table[x index=0,y index=1,col sep=space]
{jobname};\label{plots:plot1}
\addplot [line width=1.6pt,
mark=none,
red,
mark options={scale=.65}]%
table[x index=0,y index=2,col sep=space] {jobname};\label{plots:plot2}
\coordinate (top) at (rel axis cs:0,1);
\nextgroupplot[grid=both, every major grid/.style={gray, opacity=0.5},xlabel = (c) Bagging--Decision Stump,xmin=0, ymax=0.8]
\addplot [line width=1.6pt,
mark=none,
blue,
mark options={scale=.65}]%
table[x index=0,y index=1,col sep=space]
{jobname};
\addplot [line width=1.6pt,
mark=none,
red,
mark options={scale=.65}]%
table[x index=0,y index=2,col sep=space]
{jobname};
\nextgroupplot[grid=both, every major grid/.style={gray, opacity=0.5},xlabel = (e) AdaBoostM1--J8,xmin=0,ymax=0.8]
\addplot [line width=1.6pt,
mark=none,
blue,
mark options={scale=.65}]%
table[x index=0,y index=1,col sep=space]
{jobname};
\addplot [line width=1.6pt,
mark=none,
red,
mark options={scale=.65}]%
table[x index=0,y index=2,col sep=space]
{jobname};
\nextgroupplot[grid=both, every major grid/.style={gray, opacity=0.5},
xlabel = (g) AdaBoostM1--Decision Stump,xmin=0,ymin=0,ymax=0.8]
\addplot [legend pos=north west,
line width=1.6pt,
mark=none,
blue,
mark options={scale=.65}]%
table[x index=0,y index=1,col sep=space]
{jobname};
\addplot [line width=1.6pt,
mark=none,
red,
mark options={scale=.65}]%
table[x index=0,y index=2,col sep=space]
{jobname};
\coordinate (bot) at (rel axis cs:1,0);
\end{groupplot}
\path (ape c1r1.north east) --node[above]{\textbf{Cost Senditivity Plot}} (ape c2r1.north west);
\foreach \row in {1,2}
\path (ape c1r\row.south east) --node[below=1cm]{\textbf{Ratio}} (ape c2r\row.south west);
\path (top-|current bounding box.west)--
node[anchor=south,rotate=90] {\large{\bf{Misclassification Rate}}}
(bot-|current bounding box.west);
% legend
\path (top|-current bounding box.north)--
coordinate(legendpos)
(bot|-current bounding box.north);
\matrix[
matrix of nodes,
anchor=south,
draw,
inner sep=0.2em,
draw
]at([yshift=1ex]legendpos)
{
\ref{plots:plot1}& Type 1 &[5pt]
\ref{plots:plot2}& Type 2 &[5pt]\\};
\end{tikzpicture}
\caption[FIT and TEST Data for various Classifier and Meta Learning Schemes]{FIT and TEST Data for various Classifier and Meta Learning Schemes.}\label{FIT_TEST}
\end{figure}
\end{document}