我在 txt 文件中有 5 列数据,即 nxI Bfield1 magmoment1 Bfield2 magmoment2。我试图实现 nXI - x 轴、Bfield1 和 Bfield 2 作为我的 y 轴,以及 magmoment1 和 magmoment 2 作为 RHS 上的第二个 y 轴。我需要做的是缩放第二个 y 轴 wrt magmoment 1。我不希望 magmoment 的图仅显示 RHS y 轴的各自磁矩比例。谢谢。我更改了 .txt 文件名,但下面的代码没有变化。 椭圆矩
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\providecommand{\plotdataDir}{plotdata}
\begin{tikzpicture}
\begin{semilogxaxis}[
xlabel={$n \times I$},
ylabel={$B_z \left(T\right)$},xmin=1,ymin=0,xmax=100000,
xtick pos=left,
ytick pos=left,grid=major,legend entries={$Supermendur \:2V$,$Metallic\:Glass$},legend pos=north west]
\addplot[blue,ultra thick] table[x=nxI,y=Bfield1] {\plotdataDir/moment.txt} node[fill=white, fill opacity=0.5, text opacity=1,anchor=south east,font=\tiny]{$\mu_r=80,000$};
\addplot[red,ultra thick] table[x=nxI,y=Bfield2] {\plotdataDir/moment.txt} node[fill=white, fill opacity=0.5, text opacity=1,anchor=south east,font=\tiny]{$\mu_r=1,250,000$};
\end{semilogxaxis}
%%
\begin{axis}[
axis y line*=right,
ylabel={$M$},xmin=0,
axis x line=none,
]
\addplot[green,ultra thick] table[x=nxI,y=magmoment1] {\plotdataDir/moment.txt};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我已将上面的相同 .txt 文件名更改为 ellipbmoment.txt。我通过缩放两个轴并隐藏最后一个图,通过蛮力解决了这个问题。解决方案如下。我还添加了 .txt 文件。椭圆矩.txt
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\providecommand{\plotdataDir}{plotdata}
\begin{tikzpicture}
\pgfplotsset{set layers}
\begin{semilogxaxis}[scale only axis,
xlabel={$turns \times I \left(n \cdot A\right)$},
ylabel={$B_z \left(T\right)$},xmin=1,ymin=0,xmax=100000,
xtick pos=left,
ytick pos=left,xmajorgrids,legend entries={$Supermendur \:2V$,$Metallic\:Glass$},legend pos=north west]
\addplot[blue,ultra thick] table[x=nxI,y=Bfield1] {\plotdataDir/ellipbmoment.txt} node[fill=white, fill opacity=0.7, text opacity=1,anchor=south east,font=\tiny] {$\mu_r=80,000$};
\addplot[red,ultra thick] table[x=nxI,y=Bfield2] {\plotdataDir/ellipbmoment.txt} node[fill=white, fill opacity=0.7, text opacity=1,anchor=south east,font=\tiny] {$\mu_r=1,250,000$};
\end{semilogxaxis}
%%
\begin{axis}[scale only axis,axis y line*=right,
ytick={500,1000,1500,2000,2500,3000,3500,4000},ylabel={$Magnetic\:Moment\left(A \cdot m^2\right)$},axis x line=none,ymin=0]
\addplot[draw=none] table[x=nxI,y=magmoment1] {\plotdataDir/ellipbmoment.txt};
\end{axis}
%
%
\end{tikzpicture}
\end{document}