Example: Cyclic voltammetry

Published 2014-03-30 | Author: Joseph Wright

Visualization of chemical experiment data with Tufte style axes.

This plot uses two data files and does some calculations in pgfplots to standardise them. It shows 'scan rate normalised cyclic voltammograms', and could more generally be used for 'cyclic voltammetry' results. I've shown a few things here:

  • Loading 'raw' data
  • Altering the data in the plot rather than the files themselves
  • Making legends from the data files
  • Tufte-style plots (axes)

Datafile download: 50.ocw 500.ocw

Download as: [PDF] [TEX]  •  [Open in Overleaf]

Cyclic voltammetry

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.

% This is a 'standalone' plot, so uses the standalone class
% Making plots, so load the pgfplots package of course!

% A bit of font set-up: use Latin Modern and T1 encoding

% For typesetting units

% For chemical information

% Use the latest settings, so we don't get trapped with old bugs or
% limited features.
\pgfplotsset{compat = newest}

% A few changes to how legends look: this is done for all plots.
  every axis legend/.append style =
      % Change the text alignment so the end of the text (rather than the
      % start) lines up.
      cells = { anchor = east },
      % The standard pgfplots settings use a box around legends:
      % I prefer without this.
      draw  = none

% Create a style to allow control of the settings: this will allow
% several plots to share the same setting without copy-pasting
  cyclic voltammetry/.style =
      % Using a cycle list just altering colour means that there are no
      % marks: that is normal for this sort of plot.
      cycle list name = color list , 
      % Ensure that the x-axis values always have the same number of 
      % decimal places, to avoid e.g. "1" but "1.2".
      every x tick label/.append style  =
          /pgf/number format/.cd ,
           precision = 1 , 
           fixed         ,
      % The labels apply to all plots of this type.
      % Notice that in this case the zero is ferrocenium/ferrocene, but that
      % will depend on the experiment.
      xlabel = $E / \si{\volt} \textrm{ \emph{versus} } \ch{Fc+}/\ch{Fc}$,
      % The normalised y-axis has something of a nightmare label!
      ylabel =
          ( i / \si{\micro\ampere} )
            / \sqrt{\nu / ( \si{\milli\volt\per\second} ) }

% Not everyone likes the 'axis box' effect which is the pgfplots default.
% Here, we'll set up to use 'Tufte-like' settings: see
% https://www.tug.org/members/TUGboat/tb34-2/tb107dugge.pdf for more on
% this.
  tufte axes/.style =
      after end axis/.code =
          \draw ({rel axis cs:0,0} -| {axis cs:\pgfplots@data@xmin,0})
            -- ({rel axis cs:0,0}  -| {axis cs:\pgfplots@data@xmax,0});
          \draw ({rel axis cs:0,0} |- {axis cs:0,\pgfplots@data@ymin})
            -- ({rel axis cs:0,0}  |-{axis cs:0,\pgfplots@data@ymax});
      axis line style = {draw = none},
      tick align      = outside,
      tick pos        = left

      % Choose the general settings
      cyclic voltammetry,
      % and the Tufte style
      tufte axes,
      % Place the legend 'out of the way': this needs a bit of
      % experimentation!
      every axis legend/.append style = {at = {(0.9,0.5)}}
    % Loop for each scan rate
    \foreach \datafile in {50,500}
        % For each case, add a plot
              % This plot extracts data directly from the instrument files.
              % To do that, we skip the first couple of lines.
              skip first n = 2 ,
              % The x-axis has a correction for the zero: that is done using
              % a simple expression
              x expr       = \thisrowno{0} + 0.412,
              % The y-axis is more complicated! There is a scaling so the
              % currents are in microamperes, and also a division by the
              % scan rate. The data files themselves are named using the
              % scan rate in millivolts per second: that is converted to 
              % volts per second before doing the square root.
              y expr       = 
                ( 1000000 * \thisrowno{1} )
                  / sqrt ( \datafile  / 1000 )
          from {\datafile.ocw}; 
        % Add a legend entry: the \datafile has to be forced to expand!  


Adding comments is currently not enabled.

There are currently 0 comments on this entry.

Scientific and technical areas

Creative Commons License