I am producing two figures with the pgfplots package, where one is on top and another one is on bottom. There is blank space between them. How do I remove that blank? Additionally, how can I make all content to be as wide as \textwidth?
\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]{
1 2
};
\end{axis}
\begin{axis}[leftoutery]
\addplot[red, mark=+, draw] table[x index=0]{
1 1000
};
\end{axis}
\begin{axis}[rightoutery]
\addplot[brown, mark=Mercedes star, draw] table[x index=0]{
1 3
};
\end{axis}
\end{tikzpicture}\\
\begin{tikzpicture}[yshift=-\lineskip]
\begin{axis}[leftinnery]
\addplot[green!75!black, mark=o, draw] table[x index=0]{
1 400
};
\node[anchor=north west] at (rel axis cs:0,1) {东湖};
\end{axis}
\begin{axis}[rightinnery]
\addplot[blue, mark=x, draw] table[x index=0]{
1 2
};
\end{axis}
\begin{axis}[leftoutery]
\addplot[red, mark=+, draw] table[x index=0]{
1 3
};
\end{axis}
\begin{axis}[rightoutery]
\addplot[brown, mark=Mercedes star, draw] table[x index=0]{
1 40
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
This produces the following:
It seems there a little blank space to the left of the figure, so the figure is a little bit to the right. How can I remove this blank space too? How to align all the labels and y axes? I guess it is difficult. Using groupplot may do these, but how to draw multiple y axes?


groupplotenvironment for this task? It may also help to simplify your work, because currently, you're using eight different axis environments across two TikZ picture environments just to create a single graph. – gz839918 Sep 22 '23 at 08:41groupplotwith multiple y axes. – Y. zeng Sep 22 '23 at 08:49pgfplots? You'd probably have more options stacking two plots insidepfgplotsand have more control over margins (guess). You could try to appendinner sep=0pt, outer sep=0pttotikzpictures options but I doubt it will have a good effect. Finally, try to make a custom style and avoid repetitions. This answer provides example on using multiple parameters in custom styles. – Celdor Sep 22 '23 at 10:55! Package pgfkeys Error: I do not know the key '/pgfplots/inner sep', to which you passed '0pt', and I am going to ignore it. Perhaps you misspelled it.. Let me check it now. – Y. zeng Sep 22 '23 at 11:00inner sepandouter separe keys in/tikz/namespace and are usually used to set inner and outer margins fortikznodes. I meant to append them intikzpicturein the following way:\begin{tikzpicture}[inner sep=0pt, outer sep=0pt]...\end{tikzpicture}. However, I tested it and it doesn't work anyway. You could also have a look at section 4.20 The Picture’s Size: Bounding Box and Clipping of the documentation and see if you could reduce bounding box to inner axes. – Celdor Sep 22 '23 at 11:21