两条 Y 轴平行对应

两条 Y 轴平行对应

您能帮助平行关联两个 Y 轴吗 - 这意味着我希望我的第三个 Y 轴 0 号开始与第二个轴 3 号平行。是的,我知道我可能用糟糕的英语解释,因为我画了图并上传了 - 您看到了我想要的。

在此处输入图片描述

这是我的代码

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{etoolbox}
\begin{document}

\begin{tikzpicture}
% f1
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=168,
%xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24},
xtick={0,12,24,48,72,168}, %%%<------------- here
xlabel=\ {Time},
ymin=0,
ymax=10,
ytick={0,1,2,3,4,5,6,7,8,9,10},% your code
yticklabels={0,1,2,3,4,5,6,7,8,9,10},% your code
ylabel=\ {log(Cfu/cm$^{2}$)},
y axis line style={black},
ytick style={black},
yticklabel style={black},
axis x line*=bottom,
axis y line*=left, 
tick align = outside,]
\addplot [black, fill=white, mark=square*]
        table[row sep=crcr]{
            0 7.005\\
2 7\\
4 7.035\\
6 7.005\\
8 7.015\\
10 7.025\\
12 6.98\\
14 6.985\\
16 6.94\\
18 6.89\\
20 6.81\\
22 6.63\\
24 6.46\\
48 5.945\\
72 6.445\\
168 6.845\\};
             \addplot [black, fill=white, mark=*]
        table[row sep=crcr]{
            0 7\\
2 7.02\\
4 7.03\\
6 7.01\\
8 7.025\\
10 7.03\\
12 6.98\\
14 6.92\\
16 6.895\\
18 6.78\\
20 6.62\\
22 6.415\\
24 6.205\\
48 6.37\\
72 6.49\\
168 6.865\\};
            \addplot [black, fill=white, mark=diamond*]
        table[row sep=crcr]{
           0 7.01\\
2 7.02\\
4 7.045\\
6 7.01\\
8 7.03\\
10 7.025\\
12 6.98\\
14 6.955\\
16 6.905\\
18 6.825\\
20 6.725\\
22 6.575\\
24 6.43\\
48 6.27\\
72 6.345\\
168 6.975\\};
            \addplot [black, fill=white, mark=triangle*]
        table[row sep=crcr]{
          0 7.005\\
2 7.02\\
4 7.03\\
6 7.02\\
8 7.01\\
10 7.02\\
12 6.99\\
14 6.975\\
16 6.93\\
18 6.845\\
20 6.715\\
22 6.53\\
24 6.315\\
48 6.32\\
72 6.405\\
168 6.785\\};
\end{axis}
% f2
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=168,
ymin=0,
ymax=6,
ytick={0,1,2,3,4,5},
yticklabels={0,1,2,3,4,5},
axis x line*=none,
axis y line*=right,
ylabel=\ {Relative Expression},
ylabel style=black,
hide x axis,
tick align =outside,]
\addplot [black, mark=square*]
        table[row sep=crcr]{
           0 0.051\\
2 0.0175\\
4 0.0945\\
6 0.122\\
8 0.135\\
10 0.14\\
12 0.1745\\
14 0.1855\\
16 0.29\\
18 0.423\\
20 0.574\\
22 0.8165\\
24 1.061\\
48 1.985\\
72 2.0285\\
168 1.9215\\};
\addplot [black, mark=*]
        table[row sep=crcr]{
0 0.052\\
2 0.0165\\
4 0.1495\\
6 0.1805\\
8 0.1835\\
10 0.1855\\
12 0.2005\\
14 0.3795\\
16 0.5425\\
18 0.8065\\
20 1.046\\
22 1.2005\\
24 1.483\\
48 2.369\\
72 2.0315\\
168 2.3025\\};
 \addplot [black, mark=diamond*]
        table[row sep=crcr]{
            0 0.053\\
2 0.0485\\
4 0.1365\\
6 0.164\\
8 0.1595\\
10 0.1725\\
12 0.1935\\
14 0.2315\\
16 0.3345\\
18 0.473\\
20 0.6015\\
22 0.8185\\
24 1.0415\\
48 2.082\\
72 1.919\\
168 1.711\\};
 \addplot [black, mark=triangle*]
        table[row sep=crcr]{
0 0.0525\\
2 0.0325\\
4 0.0285\\
6 0.108\\
8 0.1255\\
10 0.1475\\
12 0.1405\\
14 0.2495\\
16 0.3955\\
18 0.529\\
20 0.7175\\
22 0.9715\\
24 1.2455\\
48 1.94\\
72 1.696\\
168 1.942\\};
\end{axis}
% f3
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=168,
ymin=0,
ymax=6,
ytick={0,1,2,3,4,5,6},% your code
yticklabels={0,2,4,6},% your code
axis x line*=none,
axis y line*=right,
ylabel=\ {Enterotoxin production (pg/ml)},
ylabel style=black,
hide x axis,
tick align =outside,]
\pgfplotsset{every outer y axis line/.style={xshift=1.5cm}, every tick/.style={xshift=1.5cm}, every y tick label/.style={xshift=1.5cm} }
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark=triangle*,
mark options={solid,,fill=white}]
table[row sep=crcr]{
0 2\
4 3.8\\
8 3.2\\
12 3.123\\
24 2.385\\};
\end{axis}
\end{tikzpicture}%
\end{document}

这就是结果

在此处输入图片描述

答案1

我不是tikz专家,只是改变一下你的思路

ytick={0,1,2,3,4,5,6},% your code

ytick={3,4,5,6},% your code

因为你最后axis应该做的工作。

在此处输入图片描述

完整代码

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{etoolbox}
\begin{document}

\begin{tikzpicture}
% f1
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=168,
%xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24},
xtick={0,12,24,48,72,168}, %%%<------------- here
xlabel=\ {Time},
ymin=0,
ymax=10,
ytick={0,1,2,3,4,5,6,7,8,9,10},% your code
yticklabels={0,1,2,3,4,5,6,7,8,9,10},% your code
ylabel=\ {log(Cfu/cm$^{2}$)},
y axis line style={black},
ytick style={black},
yticklabel style={black},
axis x line*=bottom,
axis y line*=left,
tick align = outside,]
\addplot [black, fill=white, mark=square*]
        table[row sep=crcr]{
            0 7.005\\
2 7\\
4 7.035\\
6 7.005\\
8 7.015\\
10 7.025\\
12 6.98\\
14 6.985\\
16 6.94\\
18 6.89\\
20 6.81\\
22 6.63\\
24 6.46\\
48 5.945\\
72 6.445\\
168 6.845\\};
             \addplot [black, fill=white, mark=*]
        table[row sep=crcr]{
            0 7\\
2 7.02\\
4 7.03\\
6 7.01\\
8 7.025\\
10 7.03\\
12 6.98\\
14 6.92\\
16 6.895\\
18 6.78\\
20 6.62\\
22 6.415\\
24 6.205\\
48 6.37\\
72 6.49\\
168 6.865\\};
            \addplot [black, fill=white, mark=diamond*]
        table[row sep=crcr]{
           0 7.01\\
2 7.02\\
4 7.045\\
6 7.01\\
8 7.03\\
10 7.025\\
12 6.98\\
14 6.955\\
16 6.905\\
18 6.825\\
20 6.725\\
22 6.575\\
24 6.43\\
48 6.27\\
72 6.345\\
168 6.975\\};
            \addplot [black, fill=white, mark=triangle*]
        table[row sep=crcr]{
          0 7.005\\
2 7.02\\
4 7.03\\
6 7.02\\
8 7.01\\
10 7.02\\
12 6.99\\
14 6.975\\
16 6.93\\
18 6.845\\
20 6.715\\
22 6.53\\
24 6.315\\
48 6.32\\
72 6.405\\
168 6.785\\};
\end{axis}
% f2
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=168,
ymin=0,
ymax=6,
ytick={0,1,2,3,4,5},
yticklabels={0,1,2,3,4,5},
axis x line*=none,
axis y line*=right,
ylabel=\ {Relative Expression},
ylabel style=black,
hide x axis,
tick align =outside,]
\addplot [black, mark=square*]
        table[row sep=crcr]{
           0 0.051\\
2 0.0175\\
4 0.0945\\
6 0.122\\
8 0.135\\
10 0.14\\
12 0.1745\\
14 0.1855\\
16 0.29\\
18 0.423\\
20 0.574\\
22 0.8165\\
24 1.061\\
48 1.985\\
72 2.0285\\
168 1.9215\\};
\addplot [black, mark=*]
        table[row sep=crcr]{
0 0.052\\
2 0.0165\\
4 0.1495\\
6 0.1805\\
8 0.1835\\
10 0.1855\\
12 0.2005\\
14 0.3795\\
16 0.5425\\
18 0.8065\\
20 1.046\\
22 1.2005\\
24 1.483\\
48 2.369\\
72 2.0315\\
168 2.3025\\};
 \addplot [black, mark=diamond*]
        table[row sep=crcr]{
            0 0.053\\
2 0.0485\\
4 0.1365\\
6 0.164\\
8 0.1595\\
10 0.1725\\
12 0.1935\\
14 0.2315\\
16 0.3345\\
18 0.473\\
20 0.6015\\
22 0.8185\\
24 1.0415\\
48 2.082\\
72 1.919\\
168 1.711\\};
 \addplot [black, mark=triangle*]
        table[row sep=crcr]{
0 0.0525\\
2 0.0325\\
4 0.0285\\
6 0.108\\
8 0.1255\\
10 0.1475\\
12 0.1405\\
14 0.2495\\
16 0.3955\\
18 0.529\\
20 0.7175\\
22 0.9715\\
24 1.2455\\
48 1.94\\
72 1.696\\
168 1.942\\};
\end{axis}
% f3
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=168,
ymin=0,
ymax=6,
ytick={3,4,5,6},% your code
yticklabels={0,2,4,6},% your code
axis x line*=none,
axis y line*=right,
ylabel=\ {Enterotoxin production (pg/ml)},
ylabel style=black,
hide x axis,
tick align =outside,]
\pgfplotsset{every outer y axis line/.style={xshift=1.5cm}, every tick/.style={xshift=1.5cm}, every y tick label/.style={xshift=1.5cm} }
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark=triangle*,
mark options={solid,,fill=white}]
table[row sep=crcr]{
0 2\\
4 3.8\\
8 3.2\\
12 3.123\\
24 2.385\\};
\end{axis}
\end{tikzpicture}%
\end{document} 

相关内容