1

I have 5 columns of data in a txt. file as nxI Bfield1 magmoment1 Bfield2 magmoment2. I am attempting to implement nXI - x axis, Bfield1 and Bfield 2 as my y axis and magmoment1 and magmoment 2 as second y axis on RHS. What I need to do is scale the 2nd y axis w.r.t magmoment 1. I don't want the plot for magmoment to show just scale RHS y axis for their respective magnetic moments. Thanks. I changed the .txt file name the code below is unchanged. ellipbmoment

enter image description here

    \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}
  • Perhaps I can plot magmoment1 as i did above then somehow hide the plot. This way it adjust the RHS y axis. – Joseph Hamad Apr 6 '14 at 4:03
  • Ok I've solved it by brute force by scaling both axis and hiding the last plot – Joseph Hamad Apr 6 '14 at 5:28
  • FYI, it would be great to add content of the moment.txt file to your post as well, otherwise solvers can't reproduce your document. – Malipivo Apr 6 '14 at 6:10
  • Could you please make your comment an answer to this post if you already found a solution which fits you. This is a way how to notify others, even brute force is a solution. It would be also great if you could change the display name from userxxxxx to something more descriptive. We are all humans, right? :-) – Malipivo Apr 6 '14 at 6:21
1

I have changed the same .txt file name above to ellipbmoment.txt. I've solved it by brute force by scaling both axis and hiding the last plot. Solution below. I have also added the .txt file. ellipbmoment.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}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.