Updating Dr. Berendsen's Python programs

(4) Logarithmic graphs and error bars

To (3)      To (5)      Workbench Python

Updating Python Code 2.5 (p.172) for Figure 2.7 (p.16)
<code2.5.py>

The time-dependent changes in concentration are represented by a logarithmic graph with errors. What follows is the original code by Dr. Berendsen.

  1. from plotsvg import *
  2. time = [20., 40., 60., 80., 100., 120., 140., 160., 180.]
  3. conc = [75., 43., 26., 16., 10., 5., 3.5, 1.8, 1.6]
  4. err = [4., 3., 3., 3., 2., 2., 1., 1., 1.]
  5. f = Figure()
  6. f.frame([0,200],[1,100],xlabel='time <i> t</i>/s', ylabel='concentration <i>c</i>mmol L< sup >-1</sup>', yscale='log')
  7. f.plotp([time,conc],ybars=err)
  8. f.show()
Because python cannot recognize plotsvg, I made the revised code2.5.pyproducing the graph as shown in the right. Note that italic forms and superscripts are specified in the HTML style for plotsvg and in the TEX style for matplotlib.
<Graphics output from the revised code>

<Revised code2.5.py>

In many laboratories it is likely that data are changed but programs remain unchanged. Thus the revised code2.5.py reads csv files (contents). The first line of the csv file is a headling, comprising 3 items corresponding to i, x, y. If an item begins with a letter i, the data of that column are understood as integers.

<The module hwbfiles.py>

readData(file_name,check) of hwbfiles.py is invoked to read file. Part of the test program is shown below.

  1. import hwbfiles as hf
  2. f = fileRead('tab2.5.csv', False)
  3. print(f.fname + ' has ' + str(f.ndata) + ' data')
  4. print('item size =',f.nitem)
  5. print('x=',f.xa)

9-18-2023, S. Hayashi