Tutorials

Introduction

This chapter provides a “how-to” on nomogram construction using the PyNomo library. It assumes you’ve already installed and tested PyNomo in your environment and can successfully build the nomograms in the block type descriptions.

Program listings for all the tutorials are at the end of this chapter.

Tutorial 1: Vehicle economy calculator

Objective

Construct an “N” type nomogram to calculate a vehicle’s range, fuel consumption or fuel economy given any two of these values. The nomogram will be built using linear scales.

Nomogram construction

Nomogram construction involves several steps. The first is always to identify the variables and their relationship. In this tutorial we need to consider three variables:

  • distance (\(d\)) measured in kilometres,

  • fuel consumed (\(c\)) measured in litres, and

  • fuel economy (\(e\)) measured in kilometres driven per litre consumed.

The relationship between these variables is:

\(d = {e\times c}.\)

This equation satisfies the form for a Type 2 nomogram (see section 6.2) as follows:

\(F_1(u_1) = {F_2(u_2)F_3(u_3)},\)

where

\(F_1(u_1) = u_1 = d\),

\(F_2(u_2) = u_2 = e\)

and

\(F_3(u_3) = u_3 = c\).

All scales are linear and we choose a reasonable range of values (u_min and u_max) for each axis.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
dist_SI = {
    # distance in kilometers (u1)
    'u_min': 100.0,
    'u_max': 1000.0,
    'function': lambda u: u,
    'title': r'kms',
    'tick_levels': 3,
    'tick_text_levels': 2,
}

eff_SI = {
    # fuel efficiency in km / litre) (u2)
    'u_min': 5.0,
    'u_max': 20.0,
    'function': lambda u: u,
    'title': r'kms per litre',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'scale_type': 'linear smart',
}

fuel_SI = {
    # fuel consumption in litres (u3)
    'u_min': 10.0,
    'u_max': 100.0,
    'function': lambda u: u,
    'title': r'litres',
    'tick_levels': 3,
    'tick_text_levels': 2,
}

These scales are linked into a single block as follows:

42
43
44
45
46
47
block_SI = {
    'block_type': 'type_2',
    'f1_params': dist_SI,
    'f2_params': eff_SI,
    'f3_params': fuel_SI,
}

Note

Parameters f1_params, f2_params and f3_params represent parameters including functions for variables \(u_1\), \(u_2\) and \(u_3\) respectively.

Finally, we define main parameters of the nomogram and generate the chart:

49
50
51
52
53
54
55
56
57
main_params = {
    'filename': 'tutorial1a.eps',
    'paper_height':15.0,
    'paper_width':15.0,
    'block_params': [block_SI],
    'transformations': [('rotate', 0.01), ('scale paper',)],
    'title_str': r'\LARGE Fuel economy calculator',
}
Nomographer(main_params)

Generated nomogram

../_images/tutorial1a.png

A variation on vehicle economy calculator

The previously generated nomogram is complete but doesn’t express the vehicle’s economy the way we would like. A vehicle’s fuel economy is more often expressed in litres consumed per 100 kilometres driven, 100 times the reciprocal of the original function. How do we do this?

Recall that

\(d = {e\times c}\)

and thus

\({\frac{d}{c}} = e\).

We express the reciprocal of the economy by rearranging the formula as

\(\frac{c}{d} = \frac{1}{e}\).

Since our goal is to describe fuel economy in terms of litres per 100 km we multiply \(\frac{1}{e}\) by 100 to achieve the correct units:

\(\frac{c}{d} = \frac{100.0}{e}\).

\(u_2 = e\) so our function for \(u_2\) becomes

\(\frac{100.0}{u_2}\)

and we amend the axis definition:

21
22
23
24
25
26
27
28
29
30
eff_SI = {
    # fuel efficiency in litres / 100 kilometres) (u2)
    'u_min': 5.0,
    'u_max': 20.0,
    'function': lambda u: 100.0/u,
    'title': r'litres per 100 kms',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'scale_type': 'linear smart',
}

Generated nomogram

../_images/tutorial1b.png

Tutorial 2: Vehicle economy calculator (Metric and US)

Objective

Create a new nomogram similar to the one shown in Tutorial 1 but add scales for American units of measure (miles and US gallons). This tutorial will cover:

  • Aligning and adjusting compatible scales.

  • Modifying axis parameters (titles and tick location) to improve readability.

  • Creating isopleths.

  • Combining blocks into a single nomogram.

Nomogram construction

Recapping from the first part of Tutorial 1, we know that

\(d = {e\times c}\),

where \(e\) (economy) was expressed in terms of distance travelled per unit volume of fuel. This is precisely what we want but we need to adjust the scales for American units of measure. This is accomplished by:

  1. Converting the minimum (u_min) and maximum (u_max) values in the axis to match those in the SI unit axis.

  2. Aligning the distance and fuel consumed axis so that they match the height of the SI unit axis.

  3. Tagging the distance and fuel scales so that they align horizontally with their metric system counterparts.

Thus our three new scales are defined as follows:

25
26
27
28
29
30
31
32
33
34
35
36
37
dist_US = {
    # distance in miles (u1)
    'tag': 'distance',
    'u_min': 100.0/1.609344,    # convert kilometers to miles
    'u_max': 1000.0/1.609344,
    'function': lambda u: u,    # plot the u values linearly ...
    'align_func': lambda u: u*1.609344,   # but adjust the length to match kilometers
    'title': r'$mi.$',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'tick_side': 'left',
    'title_x_shift': -1.0,
}
52
53
54
55
56
57
58
59
60
61
62
63
64
eff_US = {
    # fuel efficiency in miles per US gallon) u2
    'u_min': 235.189/20.0,      # magic value to coordinate length of SI and US scale
    'u_max': 235.189/5.0,
    'function': lambda u: u,
    'title': r'$\frac{mi.}{US \, gal.}$',
    'tick_levels': 4,
    'tick_text_levels': 3,
    'scale_type': 'linear smart',
    'tick_side': 'left',
    'title_draw_center': True,
    'title_distance_center': -1.5,
}
78
79
80
81
82
83
84
85
86
87
88
89
90
fuel_US = {
    # fuel consumption in US gallons
    'tag': 'consumption',
    'u_min': 10.0/3.785,    # convert liters to USG
    'u_max': 100.0/3.785,
    'function': lambda u: u,    # plot the gallons
    'align_func': lambda u: u*3.785,   # but must be scaled up to litres
    'title': r'$US \, gal.$',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'tick_side': 'left',
    'title_x_shift': -1.0,
}

Tags are also added to the SI units axis:

13
14
15
16
dist_SI = {
    # distance in kilometers (u1)
    'tag': 'distance',
    'u_min': 100.0,
66
67
68
69
fuel_SI = {
    # fuel consumption in litres (u3)
    'tag': 'consumption',
    'u_min': 10.0,

Notice no alignment function or tag is specified for the eff_US axis. None are required because this axis is a function of the dist_US and fuel_US axis which are already scaled appropriately therefore its alignment is automatic.

A new block is created to link the three new scales with an isopleth (solution line):

100
101
102
103
104
105
106
block_US = {
    'block_type': 'type_2',
    'f1_params': dist_US,
    'f2_params': eff_US,
    'f3_params': fuel_US,
    'isopleth_values': [[550, 40.0, 'x']],
}

Since all blocks must contain the same number of isopleths, we add one to the block_SI axis:

92
93
94
95
96
97
98
block_SI = {
    'block_type': 'type_2',
    'f1_params': dist_SI,
    'f2_params': eff_SI,
    'f3_params': fuel_SI,
    'isopleth_values': [[600, 'x', 90]],
}

Finally, block_US is added to the block_params key:

108
109
110
111
112
113
114
115
main_params = {
    'filename': 'tutorial2.pdf',
    'paper_height':15.0,
    'paper_width':15.0,
    'block_params': [block_SI, block_US],
    'transformations': [('rotate', 0.01), ('scale paper',)],
    'title_str': r'\LARGE Fuel economy calculator (Metric and US)',
}

This nomogram holds useful features. The individual scales for distance, fuel consumption and fuel economy can be used on their own to convert from one system of measurement to another. Another feature is the ability to use variables from different system of units (e.g. kilometres and US gallons) and calculate fuel economy in either miles per gallon or litres per 100 km.

Generated nomogram

../_images/tutorial2.png

Tutorial Program Listings

Tutorial 1 program listing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
    tutorial1a.py

    Simple nomogram of relationship between auto fuel consumption and distance travelled

"""
import sys
sys.path.insert(0, "..")
from pynomo.nomographer import *

dist_SI = {
    # distance in kilometers (u1)
    'u_min': 100.0,
    'u_max': 1000.0,
    'function': lambda u: u,
    'title': r'kms',
    'tick_levels': 3,
    'tick_text_levels': 2,
}

eff_SI = {
    # fuel efficiency in km / litre) (u2)
    'u_min': 5.0,
    'u_max': 20.0,
    'function': lambda u: u,
    'title': r'kms per litre',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'scale_type': 'linear smart',
}

fuel_SI = {
    # fuel consumption in litres (u3)
    'u_min': 10.0,
    'u_max': 100.0,
    'function': lambda u: u,
    'title': r'litres',
    'tick_levels': 3,
    'tick_text_levels': 2,
}

block_SI = {
    'block_type': 'type_2',
    'f1_params': dist_SI,
    'f2_params': eff_SI,
    'f3_params': fuel_SI,
}

main_params = {
    'filename': 'tutorial1a.eps',
    'paper_height':15.0,
    'paper_width':15.0,
    'block_params': [block_SI],
    'transformations': [('rotate', 0.01), ('scale paper',)],
    'title_str': r'\LARGE Fuel economy calculator',
}
Nomographer(main_params)

Tutorial 1 program listing (variation)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
    tutorial1b.py

    Simple nomogram of relationship between auto fuel consumption and distance travelled

"""
import sys
sys.path.insert(0, "..")
from pynomo.nomographer import *

dist_SI = {
    # distance in kilometers (u1)
    'u_min': 100.0,
    'u_max': 1000.0,
    'function': lambda u: u,
    'title': r'kms',
    'tick_levels': 3,
    'tick_text_levels': 2,
}

eff_SI = {
    # fuel efficiency in litres / 100 kilometres) (u2)
    'u_min': 5.0,
    'u_max': 20.0,
    'function': lambda u: 100.0/u,
    'title': r'litres per 100 kms',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'scale_type': 'linear smart',
}

fuel_SI = {
    # fuel consumption in litres (u3)
    'u_min': 10.0,
    'u_max': 100.0,
    'function': lambda u: u,
    'title': r'litres',
    'tick_levels': 3,
    'tick_text_levels': 2,
}

block_SI = {
    'block_type': 'type_2',
    'f1_params': dist_SI,
    'f2_params': eff_SI,
    'f3_params': fuel_SI,
}

main_params = {
    'filename': 'tutorial1b.eps',
    'paper_height':15.0,
    'paper_width':15.0,
    'block_params': [block_SI],
    'transformations': [('rotate', 0.01), ('scale paper',)],
    'title_str': r'\LARGE Fuel economy calculator (Variation)',
    # 'make_grid': True,
}
Nomographer(main_params)

Tutorial 2 program listing

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""
    tutorial2.py

    Compound nomogram of relationship between auto fuel consumption and distance traveled in metric and US units.

"""
import sys
sys.path.insert(0, "..")
from pynomo.nomographer import *

text.set(mode="latex")  # allows use of latex commands in PyX such as \frac{a}{b} and \par

dist_SI = {
    # distance in kilometers (u1)
    'tag': 'distance',
    'u_min': 100.0,
    'u_max': 1000.0,
    'function': lambda u: u,
    'title': r'$km$',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'title_x_shift': 1.0,
}

dist_US = {
    # distance in miles (u1)
    'tag': 'distance',
    'u_min': 100.0/1.609344,    # convert kilometers to miles
    'u_max': 1000.0/1.609344,
    'function': lambda u: u,    # plot the u values linearly ...
    'align_func': lambda u: u*1.609344,   # but adjust the length to match kilometers
    'title': r'$mi.$',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'tick_side': 'left',
    'title_x_shift': -1.0,
}

eff_SI = {
    # fuel efficiency in km / litre) (u2)
    'u_min': 5.0,
    'u_max': 20.0,
    'function': lambda u: 100.0/u,
    'title': r'$\frac{L}{100 \, km}$',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'scale_type': 'linear smart',
    'title_draw_center': True,
    'title_distance_center': -2.0,
}

eff_US = {
    # fuel efficiency in miles per US gallon) u2
    'u_min': 235.189/20.0,      # magic value to coordinate length of SI and US scale
    'u_max': 235.189/5.0,
    'function': lambda u: u,
    'title': r'$\frac{mi.}{US \, gal.}$',
    'tick_levels': 4,
    'tick_text_levels': 3,
    'scale_type': 'linear smart',
    'tick_side': 'left',
    'title_draw_center': True,
    'title_distance_center': -1.5,
}

fuel_SI = {
    # fuel consumption in litres (u3)
    'tag': 'consumption',
    'u_min': 10.0,
    'u_max': 100.0,
    'function': lambda u: u,
    'title': r'$L$',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'title_x_shift': 1.0,
}

fuel_US = {
    # fuel consumption in US gallons
    'tag': 'consumption',
    'u_min': 10.0/3.785,    # convert liters to USG
    'u_max': 100.0/3.785,
    'function': lambda u: u,    # plot the gallons
    'align_func': lambda u: u*3.785,   # but must be scaled up to litres
    'title': r'$US \, gal.$',
    'tick_levels': 3,
    'tick_text_levels': 2,
    'tick_side': 'left',
    'title_x_shift': -1.0,
}

block_SI = {
    'block_type': 'type_2',
    'f1_params': dist_SI,
    'f2_params': eff_SI,
    'f3_params': fuel_SI,
    'isopleth_values': [[600, 'x', 90]],
}

block_US = {
    'block_type': 'type_2',
    'f1_params': dist_US,
    'f2_params': eff_US,
    'f3_params': fuel_US,
    'isopleth_values': [[550, 40.0, 'x']],
}

main_params = {
    'filename': 'tutorial2.pdf',
    'paper_height':15.0,
    'paper_width':15.0,
    'block_params': [block_SI, block_US],
    'transformations': [('rotate', 0.01), ('scale paper',)],
    'title_str': r'\LARGE Fuel economy calculator (Metric and US)',
}
Nomographer(main_params)