我有以下 MWE:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 4,xticklabels at=edge bottom, vertical sep=0.5cm},
minor tick num = 1,
xmajorgrids=true,
ymajorgrids=true,
width = 7cm,
height= 5cm
]
\nextgroupplot[ylabel = {Out 1}]
\addplot [
domain=0.0001:2,
samples=100,
color=red,
line width = 1.2pt,
]
{-(x*x*x)/36};
\nextgroupplot[ylabel = {Out 2}]
\addplot [
domain=0.0001:2,
samples=100,
color=red,
line width = 1.2pt,
]
{-(x*x*x)/36};
\nextgroupplot[ylabel = {Out 3}]
\addplot [
domain=0.0001:2,
samples=100,
color=red,
line width = 1.2pt,
]
{x/100};
\nextgroupplot[ylabel = {Out 4}]
\addplot [
domain=0.0001:2,
samples=100,
color=red,
line width = 1.2pt,
]
{-1+(x*x)/50};
\end{groupplot}
\end{tikzpicture}
\end{document}
得出
我怎样才能使“Out n”对齐?
答案1
编辑: 同时,我弄清楚了你的子问题。下面建议的解决方案现在也解决了它们!
只需拼写出我的评论即可。像这样?
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=1 by 4,xticklabels at=edge bottom, vertical sep=0cm},
width = 7cm, height= 5cm,
grid=major,
minor tick num = 1,
yticklabel style = {scaled ticks=false, % <---
text width=2.4em, align=right}, % <--- added
domain=0:2,
samples=51,
no marks,
every axis plot post/.append style={very thick, color=red}
]
\nextgroupplot[ylabel = Out 1]
\addplot {-(x*x*x)/36};
\nextgroupplot[ylabel = Out 2]
\addplot {-(x*x*x)/36};
\nextgroupplot[ylabel = Out 3,
/pgf/number format/fixed
]
\addplot {x/100};
\nextgroupplot[ylabel = Out 4]
\addplot {-1+(x*x)/50};
\end{groupplot}
\end{tikzpicture}
\end{document}
- 主要变化添加
scaled ticks=false
到yticklabel style
和/pgf/number format/fixed
第三个图表中,但它groupplot
也可以是选项的一部分。这两个变化删除了第三个图表中的比例因子。 - 如您所见,我稍微缩短了您的代码,即,将所有常见样式(减少的样本数量、更改的域、曲线宽度和颜色)移至
groupplot
选项。我还向它们添加了no marks
选项。