绘制多个 y 轴图形很常见,但有时由普格夫。
\documentclass{article}
\usepackage{lmodern}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{tikz}
\usepackage[showframe]{geometry}
\begin{document}
\begin{figure}
\centering
\pgfplotsset{
scale only axis,
enlargelimits=false,
width=0.4\textwidth,
height=2cm,
xmin=0.5,
xmax=16.5,
xticklabel=\empty,
xtick={1,2,...,16},
leftinnery/.style={
every y tick label/.append style=green!75!black,
ytick style=green!75!black,
ylabel=a,
ylabel style=green!75!black,
axis y line*=left,
y axis line style=green!75!black,
},
rightinnery/.style={
every y tick label/.append style=blue,
ytick style=blue,
ylabel=b,
ylabel style=blue,
axis y line*=right,
y axis line style=blue,
},
leftoutery/.style={
every y tick label/.append style={red,xshift=-1.7cm},
ytick style={red,xshift=-1.7cm},
ylabel=c,
ylabel style=red,
axis y line*=left,
y axis line style={red,xshift=-1.7cm},
},
rightoutery/.style={
every y tick label/.append style={brown,xshift=1.4cm},
ytick style={brown,xshift=1.4cm},
ylabel=d,
ylabel style=brown,
axis y line*=right,
y axis line style={brown,xshift=1.4cm},
},
}
\begin{tikzpicture}
\begin{axis}[leftinnery]
\addplot[green!75!black, mark=o, draw] table[x index=0]{
1 10
};
\node[anchor=north west] at (rel axis cs:0,1) {东湖};
\end{axis}
\begin{axis}[rightinnery]
\addplot[blue, mark=x, draw] table[x index=0]{
2 1.6
3 2
};
\end{axis}
\begin{axis}[leftoutery]
\addplot[red, mark=+, draw] table[x index=0]{
3 2
};
\end{axis}
\begin{axis}[rightoutery]
\addplot[brown, mark=Mercedes star, draw] table[x index=0]{
1 3
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
可以做到
有时需要更改许多图形以添加这些刻度,那么这是一种自动添加的方法吗? 如果可以添加,如何省略底部的刻度标签和顶部的刻度,以便在垂直方向上排列两个图形而不重叠标签。