使用该包制作带标签的子图有点棘手tikz
。有人可以告诉我如何为每个子图提供自己的字母(A 代表左侧子图,B 代表中间子图,C 代表右侧子图)吗?代码如下:
\documentclass[aps,amsmath,amssymb,letter,scriptaddress,twocolumn, prl,showkeys]{revtex4}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\usepackage{amssymb}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepackage{mathtools}
\usepackage{makeidx}
\usepackage{amsfonts}
\usepackage[ansinew]{inputenc}
\usepackage[usenames,dvipsnames]{pstricks}
\usepackage{subfigure}
\usepackage{epsfig}
\usepackage{pst-grad} % For gradients
\usepackage{pst-plot} % For axes
\usepackage[colorlinks,hyperindex]{hyperref}
\makeatletter
\newcommand{\rmnum}[1]{\romannumeral #1}
\newcommand{\Rmnum}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother
\begin{document}
\begin{figure*}
\begin{tikzpicture}[font=\footnotesize\sffamily]
\begin{groupplot}[
group style={group size=3 by 1,
ylabels at=edge left
},
view={0}{90},
width=5cm,
height=5cm,
scale only axis,
xmin=0, xmax=3,
ymin=-8, ymax=0,
xlabel={x},
ylabel={$y$},
name=plot2,
unbounded coords=jump]
]
\nextgroupplot
\addplot [only marks, mark=o, color=red] table{
1 -2.5
2 -3.3
3 -3.4
};
\addplot [domain=1:3, color=black] {-0.0538*x-2.8234};
\nextgroupplot
\addplot [only marks, mark=o, color=red] table{
1 -2.900422094
2 -3.244193633
3 -3.283414346
};
\addplot [domain=4:6, color=black] {-0.0333*x-3.1637};
\nextgroupplot
\addplot [only marks, mark=o, color=red] table{
4 -4.199705078
5 -4.674163057
6 -4.674163057
};
\addplot [domain=4:6, color=black] {-0.0749*x-1.7959};
\end{groupplot}
\end{tikzpicture}
\caption{My caption}
\label{myfig}
\end{figure*}
\end{document}
答案1
这是一个解决方案(由于目前无法安装 revtex4,因此这里使用了 article cass)。应用了两种不同的标签技能。一种(自动标题,需要 alphalph 包)使用
\makeatletter
\pgfplotsset{
auto title/.style={title=(\AlphAlph{\pgfplots@group@current@plot})
}
}
\makeatother
另一个(红色)用途
\node (A) at (group c1r1.north west) {A}; % c1r1 means column 1 row 1;
锚点位置可以是,,,,north
等等,等等south
east
west
代码
\documentclass[aps,amsmath,amssymb,letter,scriptaddress,twocolumn, prl,showkeys]{article}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\usepackage{amssymb}
\usepackage{pgfplots,alphalph}
\usepgfplotslibrary{groupplots}
%\usepackage{mathtools}
%\usepackage{makeidx}
%\usepackage{amsfonts}
%\usepackage[ansinew]{inputenc}
%\usepackage[usenames,dvipsnames]{pstricks}
%\usepackage{subfigure}
%\usepackage{epsfig}
%\usepackage{pst-grad} % For gradients
%\usepackage{pst-plot} % For axes
%\usepackage[colorlinks,hyperindex]{hyperref}
\makeatletter
\newcommand{\rmnum}[1]{\romannumeral #1}
\newcommand{\Rmnum}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother
\makeatletter
\pgfplotsset{
auto title/.style={ title=(\AlphAlph{\pgfplots@group@current@plot})
}
}
\makeatother
\begin{document}
\begin{figure*}
\begin{tikzpicture}[font=\footnotesize\sffamily]
\begin{groupplot}[
group style={group size=3 by 1,
ylabels at=edge left
},
view={0}{90},
width=5cm,
height=5cm,
scale only axis,
xmin=0, xmax=3,
ymin=-8, ymax=0,
xlabel={x},
ylabel={$y$},
name=plot2,
unbounded coords=jump]
]
\nextgroupplot [auto title]
\addplot [only marks, mark=o, color=red,auto title] table{
1 -2.5
2 -3.3
3 -3.4
};
\addplot [domain=1:3, color=black,auto title] {-0.0538*x-2.8234};
\nextgroupplot[auto title]
\addplot [only marks, mark=o, color=red] table{
1 -2.900422094
2 -3.244193633
3 -3.283414346
};
\addplot [domain=4:6, color=black] {-0.0333*x-3.1637};
\nextgroupplot[auto title]
\addplot [only marks, mark=o, color=red] table{
4 -4.199705078
5 -4.674163057
6 -4.674163057
};
\addplot [domain=4:6, color=black] {-0.0749*x-1.7959};
\end{groupplot}
\node (A) at ([yshift=0.5cm]group c1r1.north west) {\color{red} A};
\node (B) at ([yshift=0.5cm]group c2r1.north west) {\color{red} B};
\node (C) at ([yshift=0.5cm]group c3r1.north west) {\color{red} C};
\end{tikzpicture}
\caption{My caption}
\label{myfig}
\end{figure*}
\end{document}