0

Initially, I displayed all my data with a single y axis (without concern for scale for the quantities a0, a1 and a2 which go from 0 to 1). I would like, for these 3 quantities, to display them on a second y axis on the right: the problem is that the display does not correspond at all when I go with 2 y axes and I don't understand why

The initial code :

\documentclass[border=0.2cm,11pt,convert={ghostscript,outext=.png,density=800x800}]{standalone}%conversion en png avec ghostscript

%COMPILé AVEC XeLaTeX

\usepackage[T1]{fontenc}
\usepackage[dvipsnames,svgnames]{xcolor}
\usepackage{lmodern}
\mathcode`\.="013B%virgule décimale en mode math
%\usepackage{tikz}% chargé automatiquement par pgfplots
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\pgfplotsset{/pgf/number format/.cd,1000 sep={~},use comma}
\pgfplotsset{compat=newest}            % Permet l'affichage de deux axes y
\usepackage{siunitx}% unités et écriture de valeurs
\usepackage{mhchem}

\begin{document}
    
\footnotesize
    \begin{tikzpicture}
    \begin{axis}[% mise en forme du graphique :
    xmin=0,xmax=25,
    ymin=0,ymax=14,
    xlabel=volume versé (mL),
    ylabel=pH,
    ytick distance=2,
    minor y tick num=1,
    minor x tick num=4,
    grid,
    grid=both,% grilles primaire et secondaire
    title=titrage pH-métrique d'un acide faible,
    axis line shift=3pt,
    xtick align=outside,
    ytick align=outside,
    tickpos=left,
    legend pos=north west,
    ]
    % courbe calculée :
    \addplot [thick,NavyBlue]
     table [x=V,y=pH,col sep=semicolon]
    {donnees_fumarique.csv};
    \addlegendentry{pH}

    % tracé concentration AH2 :
    \addplot [densely dashed,red,
            yscale=12 % 
            ]
    table [x=V,y=a0,col sep=semicolon]
    {donnees_fumarique.csv};
    \addlegendentry{\ce{AH2}}
    
    % tracé concentration acide :
    \addplot [densely dotted,OliveGreen,thick,yscale=12,
    ]
    table [x=V,y=a1,col sep=semicolon]
    {donnees_fumarique.csv};
    \addlegendentry{\ce{HA^-}}
    
    % tracé concentration A2- :
\addplot [densely dotted,purple,thick,yscale=12,
]
table [x=V,y=a2,col sep=semicolon]
{donnees_fumarique.csv};
\addlegendentry{\ce{A^2-}}
    \end{axis}
    \end{tikzpicture}
\end{document}

initial

The code I'm trying for the 2 axes :

\documentclass[border=0.2cm,11pt,convert={ghostscript,outext=.png,density=800x800}]{standalone}%conversion en png avec ghostscript

%COMPILé AVEC XeLaTeX

\usepackage[T1]{fontenc}
\usepackage[dvipsnames,svgnames]{xcolor}
\usepackage{lmodern}
\mathcode`\.="013B%virgule décimale en mode math
%\usepackage{tikz}% chargé automatiquement par pgfplots
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\pgfplotsset{/pgf/number format/.cd,1000 sep={~},use comma}
\pgfplotsset{compat=newest}            % Permet l'affichage de deux axes y
\usepackage{siunitx}% unités et écriture de valeurs
\usepackage{mhchem}

\begin{document}
    
\footnotesize
    \begin{tikzpicture}
    \begin{axis}[% mise en forme du graphique :
    xmin=0,xmax=25,
    ymin=0,ymax=14,
    xlabel=volume versé (mL),
    ylabel=pH,
    ytick distance=2,
    minor y tick num=1,
    minor x tick num=4,
    grid,
    grid=both,% grilles primaire et secondaire
    title=titrage pH-métrique d'un acide faible,
    axis line shift=3pt,
    xtick align=outside,
    ytick align=outside,
    tickpos=left,
    legend pos=north west,
    ]
    % courbe calculée :
    \addplot [thick,NavyBlue]
     table [x=V,y=pH,col sep=semicolon]
    {donnees_fumarique.csv};
    \addlegendentry{pH}
    \end{axis}
    
    \begin{axis}[% mise en forme du graphique :
    ymin=0,ymax=120,
    axis y line*=right,
    axis x line = none,
    ytick align=outside,
    yticl=right,
    legend pos=north west,
    ]
    
    % tracé concentration AH2 :
    \addplot [densely dashed,red,
            yscale=100 % 
            ]
    table [x=V,y=a0,col sep=semicolon]
    {donnees_fumarique.csv};
    \addlegendentry{\ce{AH2}}
    
    % tracé concentration acide :
    \addplot [densely dotted,OliveGreen,thick,yscale=100,
    ]
    table [x=V,y=a1,col sep=semicolon]
    {donnees_fumarique.csv};
    \addlegendentry{\ce{HA^-}}
    
    % tracé concentration A2- :
\addplot [densely dotted,purple,thick,yscale=100,
]
table [x=V,y=a2,col sep=semicolon]
{donnees_fumarique.csv};
\addlegendentry{\ce{A^2-}}
    \end{axis}
    \end{tikzpicture}
\end{document}

try

The data : https://drive.google.com/file/d/106SCvB_KQE9uZdy66H2a7OpulVESyjsP/view?usp=sharing

4
  • Sorry, what do you mean by „ the display does not correspond at all“?
    – MS-SPO
    Commented Jun 9 at 5:43
  • @MS-SPO in the 1st figure, we see that the red dotted curve decreases from 0 mL while in the 2nd figure this is only the case from 12 mL: the graphic representation is therefore not at all the same
    – Nicolas
    Commented Jun 10 at 6:53
  • Thank you. Assuming the data files are identical, to me it looks like in some cases you didn’t specify xmin and xmax, did you?
    – MS-SPO
    Commented Jun 10 at 7:18
  • the data file is the same. Indeed, I did not specify xmin and xmax for the 2nd y axis
    – Nicolas
    Commented Jun 10 at 7:23

1 Answer 1

1

Hm, still not sure, what your problem is. However, with some minor changes your 2nd code results in:

result

Some minor changes:

  • disable ghostscript and fontenc
  • 2nd \begin{axis}: assign same range xmin=0,xmax=25,
  • dto.: this way there is no grid-mismatch between left and right scales ymin=0,ymax=140,
  • moving 2nd legend to make it visible AND assignment of left/right scales more evident

%\documentclass[border=0.2cm,11pt,convert={ghostscript,outext=.png,density=800x800}]{standalone}%conversion en png avec ghostscript
%
%%COMPILé AVEC XeLaTeX
%
%\usepackage[T1]{fontenc}

\documentclass[10pt,border=3mm,tikz]{standalone}

\usepackage[dvipsnames,svgnames]{xcolor}
\usepackage{lmodern}
%\mathcode`\.="013B%virgule décimale en mode math
%\usepackage{tikz}% chargé automatiquement par pgfplots
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\pgfplotsset{/pgf/number format/.cd,1000 sep={~},use comma}
\pgfplotsset{compat=newest}            % Permet l'affichage de deux axes y
\usepackage{siunitx}% unités et écriture de valeurs
\usepackage{mhchem}

\begin{document}
    
%\footnotesize
 \begin{tikzpicture}
  \begin{axis}[% mise en forme du graphique :
    xmin=0,xmax=25,
    ymin=0,ymax=14,
    xlabel=volume versé (mL),
    ylabel=pH,
    ytick distance=2,
    minor y tick num=1,
    minor x tick num=4,
    grid,
    grid=both,% grilles primaire et secondaire
    title=titrage pH-métrique d'un acide faible,
    axis line shift=3pt,
    xtick align=outside,
    ytick align=outside,
    tickpos=left,
    legend pos=north west,
    ]
    % courbe calculée :
    \addplot [thick,NavyBlue]
            table [x=V,y=pH,col sep=semicolon]
            {donnees_fumarique.csv};
    \addlegendentry{pH}
  \end{axis}
    
  \begin{axis}[% mise en forme du graphique :
    ymin=0,ymax=140,        % <<<<<<<<
    xmin=0,xmax=25,         % <<<<<<<<
    axis y line*=right,
    axis x line = none,
    ytick align=outside,
%    yticl=right,
    legend pos=south east,  % <<<<<<<<
    ]
    
    % tracé concentration AH2 :
    \addplot [densely dashed,red,
              yscale=100 % 
              ]
            table [x=V,y=a0,col sep=semicolon]
            {donnees_fumarique.csv};
    \addlegendentry{\ce{AH2}}
    
    % tracé concentration acide :
    \addplot [densely dotted,OliveGreen,thick,yscale=100,
            ]
            table [x=V,y=a1,col sep=semicolon]
            {donnees_fumarique.csv};
    \addlegendentry{\ce{HA^-}}
    
    % tracé concentration A2- :
    \addplot [densely dotted,purple,thick,yscale=100,
            ]
            table [x=V,y=a2,col sep=semicolon]
            {donnees_fumarique.csv};
            \addlegendentry{\ce{A^2-}}
  \end{axis}
 \end{tikzpicture}
\end{document}

P.S.: Perhaps the ylabel for the right y axis should be [a.u.] (arbitrary units)?

1
  • 1
    thanks for your return. The unit is the percentage of the second y axis
    – Nicolas
    Commented Jun 10 at 11:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .