130 5 13MB
English Pages [415] Year 2000
Scientific Visualization and Information Architecture
John P. Boyd
University of Michigan Ann Arbor, Michigan 48109-2143 email: [email protected] http://www-personal.engin.umich.edu/∼jpboyd/
2000
TO BE PUBLISHED
1
2
Contents I
Theory
1
1 How to Graph Badly or What NOT to Do 1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2 Chartjunk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.1 Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.2 Moir´e Shading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.3 Pseudo 3-D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.4 Artificial Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.5 Hype, I: Overinterpretation . . . . . . . . . . . . . . . . . . . . . . 1.2.6 Hype, II: Graphical Carpet Bombing . . . . . . . . . . . . . . . . . 1.3 Wainer’s Rules for Bad Graphs . . . . . . . . . . . . . . . . . . . . . . . . 1.4 High Data Density . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5 Data-Hiding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.1 Data-Hiding by Graphing Disparate Quantities on the Same Scale 1.6 Inconsistent Visual Metaphor . . . . . . . . . . . . . . . . . . . . . . . . . 1.7 Context-Free Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.8 Area Instead of Length as a Visual Metaphor . . . . . . . . . . . . . . . . 1.9 Label Woes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.10 Emphasize the Unimportant . . . . . . . . . . . . . . . . . . . . . . . . . . 1.11 Unnecessary Graphic Novelty . . . . . . . . . . . . . . . . . . . . . . . . . 2 The Gospel According to Tufte 2.1 Data-Ink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Show the Data . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.2 Emphasize the Data . . . . . . . . . . . . . . . . . . . . . . . 2.1.3 Erase Non-Data-Ink or Down with the Grid! . . . . . . . . . 2.1.4 Erase Non-Data-Ink: Hurrah for Half-Framing! . . . . . . . . 2.1.5 Erase Non-Data-Ink: Example of the Simplified Bar Graph . 2.1.6 Erase Redundant Data-Ink: Symmetry and Wrap-Around and 2.1.7 Erasing: Eliminating the Graph Entirely . . . . . . . . . . . . 2.1.8 Revise and Edit . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 High Data Density . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.1 The Shrink Principle . . . . . . . . . . . . . . . . . . . . . . . 2.3 Multifunctioning Graphical Elements . . . . . . . . . . . . . . . . . . 2.4 Small Multiples or Animations-on-a-Page . . . . . . . . . . . . . . . 2.5 One Plus One Is Three . . . . . . . . . . . . . . . . . . . . . . . . . . 2.6 Layering, Separation and Rubrication . . . . . . . . . . . . . . . . . 2.7 Word-Labels Are Better Than Letter-Labels . . . . . . . . . . . . . . 2.8 Collapsing a Dimension or Escaping Flatland . . . . . . . . . . . . . i
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . All That . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 3 3 5 5 6 7 7 9 12 12 14 16 18 18 19 21 22 24 27 27 28 28 28 34 35 36 39 41 43 48 51 56 60 61 66 67
ii
CONTENTS 2.9
2.10 2.11 2.12 2.13
II
Supplementary Material . . . . . . . . . . . . . . 2.9.1 Small Multiples or Animations-on-a-Page 2.9.2 Separation: Inset Graphs . . . . . . . . . Wide is Wonderful: Aesthetics of Aspect Ratio . Color or Why the Rainbow Isn’t Golden . . . . . Parallelism . . . . . . . . . . . . . . . . . . . . . The Friendly Graphic . . . . . . . . . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
Scientific Graphs
3 Axis Magic 3.1 Introduction . . . . . . . . . . . . . . . . 3.2 Squeezing the Axis . . . . . . . . . . . . 3.3 Log, Log-Log and All That . . . . . . . 3.4 Probability, Arctanh and Arcsinh Scales 3.5 Monetary Inflation . . . . . . . . . . . . 3.6 Nomography and Graphical Calculators
73 73 75 77 79 89 92
93 . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
95 95 95 98 101 105 107
4 Contour (Isoline) Plots 4.1 Contour Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 The Central Problem of Contour Plots: Coding the Isolines . . . . . . 4.3 Solid Positive-Valued/Dashed Negative-Valued Contour Plot . . . . . 4.4 Hachure Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.5 Filled Contour Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.6 Scalloping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.7 Choosing the Number of Contour Lines . . . . . . . . . . . . . . . . . 4.8 What to Contour: Variable Isoline-Spacing and Isolines of Logarithms 4.9 Contouring in Irregular Regions . . . . . . . . . . . . . . . . . . . . . . 4.10 Label Troubles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.10.1 Numerical Labels . . . . . . . . . . . . . . . . . . . . . . . . . . 4.11 Jaggies or Piecewise Linear Plots of Contours . . . . . . . . . . . . . . 4.12 Contouring Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.13 Contouring in Non-Rectangular Domains, II . . . . . . . . . . . . . . . 4.14 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
109 109 111 112 113 114 116 118 119 121 122 126 129 130 135 138
5 Mesh Plots Scientific Visualization & Information Architecture 5.1 Mesh Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Mesh Plot with a Curtain or Skirt . . . . . . . . . . . . . . . . . . . . 5.3 Mesh-Over-Contour Plot . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Waterfall Graph or Mesh-Lines-Parallel-To-One-Axis Only . . . . . . . 5.5 Truncated Mesh Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6 Cutaway Mesh Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7 Variable Grid Spacing to Code Positive and Negative Heights . . . . . 5.8 Compromise in Grid Density . . . . . . . . . . . . . . . . . . . . . . . 5.9 Importance of Viewpoint . . . . . . . . . . . . . . . . . . . . . . . . . . 5.10 Spinning the Mesh Plot or Three-Dimensionality Through Animation 5.11 Mesh Plots on Non-Rectangular Domains . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
143 143 144 145 149 151 153 154 155 156 157 158
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
CONTENTS
iii
6 Arrow/Vector Plots 165 6.1 Quiver/Arrow/Vector Plots/Porcupine Plot . . . . . . . . . . . . . . . . . . . 165 6.2 Vector Plots Superimposed on Other Graphs . . . . . . . . . . . . . . . . . . 165 6.3 Vectors Derived from Scalars: Gradients and Hamiltonian-Field/Streamfunction Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 6.4 Area Quiver Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 6.5 Three-Dimensional Arrow/Vector/Quiver Plots . . . . . . . . . . . . . . . . . 172
III
Graphical Arts
7 Fonts and Typography 7.1 Fonts . . . . . . . . . . . . . . . . . . . . . . 7.2 Type Dimensions . . . . . . . . . . . . . . . 7.2.1 Monospaced and Proportional Type 7.2.2 Font Sizes . . . . . . . . . . . . . . . 7.3 Serifs . . . . . . . . . . . . . . . . . . . . . . 7.4 Fonts and Graphs . . . . . . . . . . . . . . . 7.5 Fonts in LaTeX . . . . . . . . . . . . . . . .
181 . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
183 183 183 183 184 186 188 189
8 Drawing 8.1 Why Draw? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2 Drawing in Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.2 Importing Images Into Matlab . . . . . . . . . . . . . . . . . . . 8.2.3 Tracing an Image in Matlab . . . . . . . . . . . . . . . . . . . . . 8.2.4 Translating, Rescaling and Rotating . . . . . . . . . . . . . . . . 8.3 Fractals: When the Algorithm is Mightier Than the Brush . . . . . . . . 8.4 Texture Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.5 Line Graphs on Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.6 Splines and Bezier Curves . . . . . . . . . . . . . . . . . . . . . . . . . . 8.7 Drawing versus Painting or Bitmap versus Vector . . . . . . . . . . . . . 8.8 Drawing Programs: Tools . . . . . . . . . . . . . . . . . . . . . . . . . . 8.8.1 Selecting Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.8.2 Views and Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.9 Zoom and Grab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.9.1 Pens and Brushes . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.10 Stroke and Fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.11 Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.12 Joins, Intentional and Inadverdent . . . . . . . . . . . . . . . . . . . . . 8.13 Cutting Paths, Add/Delete Anchor Points & Converting Corner Points . 8.14 Text Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15 Shape Drawing Tools: Ellipses, Rectangles, Stars, Etc. . . . . . . . . . . 8.16 Transformation: Rotate, Reflect, Shear, Scale . . . . . . . . . . . . . . . 8.17 Filters, Styles and All That . . . . . . . . . . . . . . . . . . . . . . . . . 8.18 Rasterizing Objects or Photoshop-in-Illustrator . . . . . . . . . . . . . . 8.19 Painting Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.20 Image-processing in Science . . . . . . . . . . . . . . . . . . . . . . . . . 8.21 Pictographs alias Visual Tables . . . . . . . . . . . . . . . . . . . . . . . 8.22 Scan-and-Decorate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.23 Drawing Theory and Drawing Programs . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
191 191 192 192 194 194 194 202 204 206 208 210 211 211 214 215 215 219 222 224 225 227 228 235 238 242 244 244 247 249 251
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
iv
CONTENTS 8.24 Logos and Overheads: Cosmology According to Michael Turner . . . . . . . . 255 8.25 Summary of Illustration Program Ideas . . . . . . . . . . . . . . . . . . . . . 257 8.26 Features That Are Useful in Scientific and Engineering Graphics . . . . . . . 258
9 Scanning 9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . 9.2 Why-To or Reasons Scanning is Useful in Scientific 9.2.1 Recycling Graphs . . . . . . . . . . . . . . . 9.2.2 Scan and Modify . . . . . . . . . . . . . . . 9.3 Copyright and All That . . . . . . . . . . . . . . . 9.3.1 Copyright-Expired Images . . . . . . . . . . 9.3.2 Scan, Trace and Delete the Original . . . . 9.3.3 Asking Permission . . . . . . . . . . . . . . 9.4 How-To . . . . . . . . . . . . . . . . . . . . . . . . 9.5 Scanning Transparencies and Photographs . . . . .
IV
. . . . . . . Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
Visualization as a Fine Art
. . . . . . . . . .
259 259 259 259 260 260 260 260 261 261 263
265
10 Visualization as Fine Art 10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2 Gilbert: De Magnete(1600), Illustration of Experimental Method . . . . 10.3 Cosmology Models of the Seventeenth Century . . . . . . . . . . . . . . 10.4 Nodal Patterns of the Vibrations of a Thin Metal Plate . . . . . . . . . 10.5 Darwin’s Flowers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.6 Hertzian’s Discovery of Electromagnetic Waves . . . . . . . . . . . . . . 10.7 Byerly (1893): Integrating Text and Graphics . . . . . . . . . . . . . . . 10.8 The Difference Between Two-Dimensional and One-Dimensional Waves 10.9 The Importance of Color Schemes . . . . . . . . . . . . . . . . . . . . . 10.10Repetition: Turbulence in the Sargasso Sea . . . . . . . . . . . . . . . . 10.11Philander (1990): Equatorial Currents . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
267 267 268 269 270 272 272 273 275 276 280 282
11 Archetypes: D¨ urer’s Rhino and the Recycling 11.1 Introduction: Aref’s Rule . . . . . . . . . . . . 11.2 Lineages . . . . . . . . . . . . . . . . . . . . . . 11.3 Archetypes . . . . . . . . . . . . . . . . . . . . 11.4 Graphical Lineages of the Renaissance . . . . . 11.4.1 D¨ urer’s Rhino . . . . . . . . . . . . . . . 11.4.2 Hooke’s Snowflakes . . . . . . . . . . . . 11.4.3 The Isle of California . . . . . . . . . . . 11.5 Poincar´e’s Pear . . . . . . . . . . . . . . . . . . 11.6 Equatorial Waves . . . . . . . . . . . . . . . . . 11.6.1 Horizontal Plane . . . . . . . . . . . . . 11.6.2 Vertical Cross-Section . . . . . . . . . . 11.7 A Good Archetype . . . . . . . . . . . . . . . .
of Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
285 285 286 286 288 288 289 291 292 295 295 297 299
A A Bestiary of Graph Species A.1 Graph-As-Computer or Look-Up Table A.2 Graph-in-Table . . . . . . . . . . . . . A.3 Hermaphrodite Graphs . . . . . . . . . A.4 Filled Line Graph . . . . . . . . . . . . A.5 Pictograph/Visual Table Plot . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
301 301 303 304 306 307
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
CONTENTS A.6 A.7 A.8 A.9
Silouette Chart (Variant of Line Chart) Solid Models . . . . . . . . . . . . . . . Stem-and-Leaf Plots . . . . . . . . . . . Tables and Other Non-Graphs . . . . . . A.9.1 Table-As-Graphic . . . . . . . . . A.10 Timeline Graph . . . . . . . . . . . . . . A.11 Trajectory . . . . . . . . . . . . . . . . . A.12 Tree Charts . . . . . . . . . . . . . . . . A.13 Trilinear Plot . . . . . . . . . . . . . . .
v . . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
309 310 314 315 315 316 317 318 319
Chapter 1
How to Graph Badly or What NOT to Do “The aim of good data graphics is to display data accurately and clearly” —– H. Wainer (1997), pg. 12. “The greatest value of a picture is when it forces us to notice what we never expected to see.” —– John Tukey, quoted in (1997), pg. 47.
1.1
Introduction
Like umpiring a sports event, graph-making is best when completely inconspicuous. Therefore, much of the art of visualization is best learned by studying how to make poor, uninformative graphs and then doing the opposite. To put it another way, much of the skill in visualization lies in not making mistakes.
1.2
Chartjunk
“Chartjunk” is Edward Tufte’s term for extraneous features that add nothing to the information content of a graph. The worst collections of chartjunk are illustrations in newspapers and non-technical magazines. These figures are drawn by professional artists who are art-school graduates. To them, aesthetic beauty or visual interest is more important than statistics or the shape of a transcendental function. Indeed, many artists had their interests pushed towards art by flunking mathematics and/or science courses! Furthermore, drawing a minimalist graph — just the curves, M’am — is rather boring to an artist who spent years and years in college creating complex drawings and paintings with subtle shadings and color variations. For all these reasons, commercial artists tend to decorate even the simplest graphs — perhaps especially the simplest graphs — with lots of extraneous decoration, i. e., chartjunk. Instead of a simple bar graph in which the height of the bar is proportional to the quantity being graphed, such as the annual oil production of a given country, the artist will draw fancy oil barrels of different sizes whose area is proportional to oil production. The oil barrels will draw the newspaper reader’s eye to the graph, but the information is not improved at all by replacing bars by barrels. Indeed, the quantitative usefulness of the graph is actually reduced. Psychological studies have shown that people are much worse at estimating areas than lengths. If one asks a person to compare the relative magnitude of two areas, the 3
4
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
Figure 1.1: Several species of chartjunk. The piece in the upper right quadrant is “Hard to Read Fonts” using so-called “black letter” or “Gothic font” in a small typesize which is very hard to read.
1.2. CHARTJUNK
5
estimate will almost always underestimate the ratio of areas, and the error worsens as the area ratio increases. Scientific graphs rarely make the error of using area where length would do. Nor are scientists inclined to add decorations or cute icons to graphs, or make bars into barrels. (In resisting the temptation to add chartjunk, poor drawing ability is actually an advantage!) Nevertheless, there are some kinds of chartjunk that scientists are prone to including all depicted in Fig. 1.1.
1.2.1
Fonts
It is unlikely that an engineer would label a graph in a Gothic font. However, modern computers offer an enormous range of choices in fonts. This can sometimes tempt one to use five different fonts in a single graph. This may be good if (i) the fonts are all distinctive and are applied to different elements of the graph and (ii) look good together. Since engineers have no training in font design, the results often are rather garish.1 Howevr, the big danger is not ugliness but illegibility. Graphic designers are taught to always think in terms of the end medium, whether printed page or Web site. Engineers don’t, and often use type sizes which are too small. A graph may be reduced by 50% in printing; if one doesn’t allow for that, a figure that looks fine in the manuscript may be an incomprehensible mess after the publisher has resized the graph, and made all the labels too small to read.
1.2.2
Moir´ e Shading
Tufte and Wainer, social scientists who have written books on graphics, feel the same way about shading that Scipio Africanus did about Carthage2 Scientists and engineers are more tolerant because to label complicated regions, there may be no practical alternative, at least in black-and-white graphics. Still, it is important to understand the reasons for Tufte’s pique. The most important is that shading is very attention-getting. If part of a region is marked by white, and the rest by cross-hatching, our eyes will be drawn only to the crosshatched region. With sufficient will and attention, we can recognize the shape of the other region that is delineated only by a line curve enclosing white. However, this does take will and attention. A hurried reader will remember only the shaded region. If the shaded region indeed is the most important, then all is well. If the unshaded region is the more interesting, or if both areas are equally important, then we have committed the graphical crime of using an emphatic, attention-getting feature for a part of the graph that doesn’t deserve it. Tufte, Wainer, and illustrators whose training has been primarily in graphic design or commercial art get very upset about graphic emphasis of the wrong thing. Furthermore, the various patterns of shading and cross-hatching, which are often called “Moir´e” patterns by analogy with the patterns found on watered silk, are frequently garish and ugly, and visually overwhelm the rest of the graph. Cross-hatched lines often seem to “shimmer” if one looks at them too long. Greyscale shading is free of this problem, but the reproduction of greyscales is rather dicey; a shade that looked good on your local laser printer may look horrible after being copied and reprinted by the publisher. 1T
EXand LATEXrestrict the user to families of fonts that go well together; for example, Knuth’s Computer Roman font, the default in TEX, was designed for visual compatibility with the italic fonts used for equations and mathematical symbols. 2 Scipio was a Roman politician, flourished circa 170 B. C., who ended every speech in the Roman Senate, even if he was talking about a completely unrelated topic, with “Carthago delenda est”, which means “Carthage must be destroyed”.
6
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
Figure 1.2: The lip that has been added to make this pie chart three-dimensional gives a misleading impression. The eye perceives both the front lip and the segment on top of the “pie” as a single entity, making the share of the United States seem larger than the others. Another point to remember is that black-and-white can be stored as 1 bit-per-pixel. Grayscale drawings require 8 bits-per-pixel. It is rather silly to amplify storage needs just to make the drawing more confusing!
1.2.3
Pseudo 3-D
Plots that project into the third dimension, such as surface mesh or “net” plots, can be very useful. However, newspapers and magazines are often victimized by the artist’s creativity. A simple bar chart may be drawn with elaborate three-dimensional columns in perspective. The difficulties of accurately perceiving size in three-dimensional space — a column that appears small may look small only because it is located at the back of the projected space — that the graph becomes almost useless for gaining a visual feel for the numbers. Fig. 1.2 shows an ordinary pie chart which has been elaborated, quite needlessly, into a three-dimensional cylinder. The height of the cylinder magnifies the perceived area of the pie segment which is nearest the viewer. In this case, a lot of extra care and trouble in drawing the graph has made it better art but poorer science. As computer graphics software becomes more ubiquitous and capable, scientists and engineers can easily succumb to the same temptation.
1.2. CHARTJUNK
7
Figure 1.3: The relative abundance of the Africanized (horizontal axis) and stingless bees (vertical) as measured on flowering Melochia villosa. The solid line is a quadratic polynomial which gave the best fit to the points. (Taken from a note by by David W. Roubik, 1978.)
1.2.4
Artificial Color
Color is a powerful tool in scientific visualization, but precisely because it is powerful, it is easily misused. It has been my experience that when a research group purchases a color printer, the result is a flood of illustrations which are very colorful but don’t actual convey much information. Furthermore, color is very expensive in storage (a color image requires at least eight times as much storage as a line graph (black-and-white) of the same resolution). It is very expensive to print, and so most journals require the author to pay the cost of color reproduction, often $1000/page or more. So, the moral is: Use color. But use it wisely, which means when you really need it to make clear what would otherwise be confusing.
1.2.5
Hype, I: Overinterpretation
One big danger for scientists and engineers is over-interpreting the data. Sometimes, experiments just don’t work. The experimental noise may overwhelm the signal. The honest reaction is to admit this. The pressures to keep publishing so that one can keep grant funding, get tenure, etc., make it difficult to do this. Fig. 1.3 shows the results of an experiment in biology: measurements of the numbers of bees of two different species of honeybee on a single species of flower. The purpose of the experiment was to understand the relationship between the two species. The Africanized bees are ferocious, aggressive stingers, very dangerous to humans. The stingless bees are
8
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
Figure 1.4: Satirical redrawing of the figure from Roubik(1978), published by Hazen (1978).
1.2. CHARTJUNK
9
quite harmless to people. One expect that the aggressive African bees would chase the other species away, or sting them to death. The actual result of the measurements is a nearlyrandom cloud. Nevertheless, the experimenter went ahead and fitted a parabola through the data. The mathematical form of the parabola is given in the original caption, but the average value of the difference between the parabola and the data points is not omitted from both caption and abstract. Robert M. Hazen, a geophysicist who has written half a dozen popular (and very readable) nonfiction books about science, was moved by what he describes as the “rather fanciful curve fitting of Roubik” to propose “an alternative interpretation”. Dr. Roubik replied, “I think Dr. Hazen was right in being sceptical, but I do not think it would justify disregarding the study or my conclusions. I thought that his letter to the editor was hilarious, but some of my colleagues did not. It seems to me that biologists are often obliged to take a different view of quantitative data from that of physical scientists. They have more or less set rules, while we must often try to discover nature’s meaning. And there is a lot of slop in nature.” Well, yes, but it was still idiotic to fit a parabola. The danger of fitting a curve to data that is all over the place is that the tidiness of the curve suggests that we actually understand the underlying phenomena, that we have a useful theory for it. If one looks at the center of the graph (20 Africanized bees on a flower), one sees that the observed number of stingless bees ranges from a low of 2 to a high of about 25. What predictive value has a theory so crude? It is likely that the ratio of stingless bees to Africanized bees is really controlled by factors different from the only factor considered in the graph: the number of bees of the other species. One can’t be too hard on Dr. Roubik. He had the good grace to describe Hazen’s satire as “hilarious”. Graphical crimes as bad or worse are very common, alas, and most of the time there is no Hazen to inject a note of common sense.
1.2.6
Hype, II: Graphical Carpet Bombing
The ease of making graphs by computer has lead many students to the following (false!) attitudes: • I graph, therefore I think. • I graph, therefore I work. • I graph, therefore I progress in understanding. Graphs can be very useful to the goals of thinking and understanding; indeed, the whole purpose of the course is to improve the connection. It is very easy, however, to become so caught up in the mechanics of running cases and printing graphs that one forgets what it all means. The result is that many Ph. D. theses consist largely of an endless progression of graphs, interrupted by brief bits of text that do little except repeat what’s in the captions. To make the thesis even more boring, the graphs are usually all of the same type: there are contour plot theses, and line graph theses, but rarely are different types of graphs mixed together in the same thesis. Complicated phenomenon unfortunately necessitate using a lot of intricate graphs. However, it is easy to fall into the trap of lobbing graphs at the reader, one after another, until the reader is hopelessly lost and bored. Students are especially prone to this because there is no page limit for a thesis. Older scientists are less vulnerable because during the review
10
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
process, they will be yelled at by referees and editors, and thereby encouraged to shorten their journal articles, and be more selective in choosing graphs for inclusion. We may dub this a kind of graphical “carpet bombing” after the military practice of dumping large numbers of bombs to saturate an area when individual targets can’t be identified. In the Pacific Gulf War, for example, carpet bombing was done by three-plane elements of B-52s, all dropping their loads of 84 500-pound bombs per plane simultaneously over an area of perhaps a square kilometer or so. Many scientists do the same thing only with almost-identical illustrations replacing the bombs. If the goal is to daze and confuse, carpet bombing is quite effective. The Allies took tens of thousands of prisoners who had been protected by trenches from the bomb fragments, but who nevertheless were left too dazed, deafened and disoriented to fight. If the goal is to enlighten rather than to concusse into submission, carpet bombing is not a good idea. When a phenomenon is complicated and intrinsically requires a lot of graphs, more visualization skill is needed, too. There are several remedies when one needs to present a lot of complicated information graphically including: • Varying the graph type; mix contour plots, surface plots, line graphs and so on. • In each graph, highlight the key figures in the caption and on the graphic itself. • Triage3 the analysis: spend a lot of words (and graphs) on the important points, but few words and perhaps no graphs on the unimportant ones. • Combine many closely-related graphs into a single multi-panel graph. Fig. 1.5 shows a rather extreme example of a multi-panel graph: 384 separate line graphs combined into one illustration. There are some obvious difficulties with combining so much information into a single figure. (The journal, which uses 8.5 inch by 11 inch pages, tried to ameliorate the legibility problem by turning the figure sideways and then filling the entire page with this single graph.) Nevertheless, it is a lot better than printing each of these 384 panels on a separate page — although I have seen technical reports of similar ocean data that did just that!
3 “Triage”
is a medical term for a practice which is now standard in most American emergency rooms, but was originally developed by French military surgeons during World War I. Overwhelmed by casualties, the French field hospitals split the wounded into three groups (“tri”) by preliminary examinations: (i) Those whose wounds were not serious and would recover without treatment (ii) those whose wounds were fatal even with treatment and (iii) those who had serious wounds but might survive if treated promptly. The triage system has saved uncounted numbers of lives. Scientists need to set priorities with graphs, too.
1.2. CHARTJUNK
11
Figure 1.5: A graph containing 384 separate line graphs (excluding the land areas). Each one-dimensional plot shows the mean Brunt-Vaisala frequency within a given square. From Houry, Dombromsky, de Mey and Minster(1987).
12
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
1.3
Wainer’s Rules for Bad Graphs
1. Show as little data as possible [minimize the data density] 2. Hide what data you do show [minimize the ratio of data/ink] 3. Show the data inaccurately [ignore the visual metaphor and randomize the connection between graphical elements and the numbers] 4. Use length as the visual metaphor when the area of two-dimensional icons is what is actually perceived 5. Graph data out of context [sparse captions and vague text] 6. Obfuscation #1: Change scales in mid-axis 7. Obfuscation #2: Emphasize the trivial [ignore the important] 8. Obfuscation #3: Jiggle the baseline [use different axis ranges for two graphs which will be printed side-by-side and need to be compared] 9. Obfuscation #4: Alabama first! [Order the data by some criterion, such as alphabetical order, which is irrelevant to all of the interesting patterns in the data] 10. Obfuscation #5: Label: (a) illegibly (b) incompletely (c) incorrectly (d) ambiguously 11. Obfuscation #6: More is murkier: (a) more decimal places and (b) more dimensions 12. If it has been done well in the past, think of a new way to do it [New graph types are sometimes needed, but they require a lot of concentration from the reader, and should be used sparingly in good graphics] In the next few sections, we will illustrate some of these principles.
1.4
High Data Density
A theme that is reiterated again and again by Tufte, Wainer and other authors is that highdensity illustrations are good: it is possible to pack a tremendous amount of information in a single picture if it is designed carefully. Fig. 1.6 is an example. Conversely, graphing badly is to display graphs with little information. Occasionally, a low-density graph is justified if used to emphasize information or concepts that are very important. A low-density graph is always justified if it is sufficient to illustrate a concept. Sometimes, though a bar graph that presents only four or five numbers is a just a bad alternative to a table.
1.4. HIGH DATA DENSITY
13
[h] Figure 1.6: A good example. Although this graph is crammed with a great diversity of information, it is quite readable. One can learn the high and low temperatures for the year, the annual trends, unusual weather on individual days and visually perceive the fluctuations of temperature with time. Taken from annual weather summary of the New York Times newspaper.
14
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
Figure 1.7: A bad example of “Data Hiding” : the grid is so heavy that it almost totally obscures the theoretical line and the data points. Inspired by an example published in a scientific journal and later analyzed by Tufte and Wainer.
1.5
Data-Hiding
An excellent strategy for making a really bad graph is to add so many extraneous elements to the graph that the data and/or information content is obscured. Fig. 1.7 is similar to one in an article in a scientific journal, subsequently analyzed (in very unfriendly fashion) by Tufte and Wainer. The grid is so heavy that the data points are almost invisible. But any child can make a grid; the data points are the heart of the illustration! Amazingly, a textbook author made an even worse graph by reprinting the earlier figure without the data points (Fig. 1.8)! If the curve were complicated and tracked the data closely, this decision could perhaps be defended — but probably not; why not include the points? Here, however, the plot is sheer lunancy because the fitted curve is just a diagonal straight line. Never use a graph where words would be just as clear. The right way to present the information is to include both the scattered points and the fitted curve but to omit the grid as shown in Fig. 1.9.
1.5. DATA-HIDING
15
Figure 1.8: A later author reprinted the figure in a textbook, but omitted all the data points! The straight line, which is the result of a theoretical model, is a diagonal line with a slope of exactly forty-five degrees. This graph really conveys no information at all — a classic bad example.
Figure 1.9: E. Tufte’s redrawing of the figure: eliminating the grid enormously improves clarity. Nothing remains but the essentials: the scatter points, the straight line which is fitted to them, and the axes.
16
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
Approximation of cos([π/2] x) by parabola 1
0.8
0.6
0.4
0.2
0 -1
-0.5
0 x
0.5
1
Figure 1.10: Comparison of the cosine function (solid) with a parabola uparab = −x2 that approximates it (dashed) and the difference between them (dotted). The difference is so small compared to the cosine, however, that it is almost invisible.
1.5.1
Data-Hiding by Graphing Disparate Quantities on the Same Scale
A common problem is to depict quantities which are all significant even though their magnitudes are very different. It is then very easy for the curve of the small to be so dwarfed by the graph of the large that no useful information about the small variable can be gleaned from the graph except its order of magnitude. Fig. 1.10 depicts such a case. The difference between the cosine function and the approximating parabola is important because it tells us the accuracy of the approximation. Unfortunately, the error is so small that its graph, when plotted on the same scale for the cosine, is almost a horizontal line. Is the maximum difference 6%? 2%? Hard to tell from the graph. The best strategy is to split the graph into multiple panels and graph the big and the small separately, each with its own scale, as in Fig. 1.11. It is now possible to draw a couple of conclusions from the graph: (i) the maximum error is about 6% of the maximum of the function which is being approximated and (ii) the error is highly oscillatory and uniform over the interval, unlike the error in the power series approximation upower ≈ 1 − (π 2 /8)x2 , which rises sharply away from the origin.
1.5. DATA-HIDING
17
cos([π/2] x) & parabola
Difference 0
1
-0.01
0.8
-0.02 0.6 -0.03 0.4 -0.04 0.2 -0.05 0 -1
0 x
1
-0.06 -1
0 x
1
Figure 1.11: Same as the previous figure except that the plot has been split in two so that the error (right panel) can be plotted on its own scale.
18
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
Exact
Exact
Numerical Numerical Figure 1.12:
1.6
Inconsistent Visual Metaphor
“Visual metaphor” is a broad term for the relationship between specific graphical elements and the data. For example, in a sequence of graphs that compare the exact solution with the corresponding numerical solution, one visual metaphor might be to associate the solid curve with the exact solution and the dashed line with the numerical calculation. Fig. 1.12 shows a graph that apparently employs this metaphor except that in the right graph, the metaphor has been accidentally reversed so that the exact solution is dashed. Inconsistent use of a visual metaphor is rather common. When testing a numerical algorithm against a set of problems with known solutions, it may take a week or two to run all the test cases. It is terribly easy to forget on Wednesday that the exact solution was a solid curve on Monday.
1.7
Context-Free Data
The “context” of a graph is the engineering or physics background. It is difficult to describe “context” in purely graphical terms because the lack of adequate context is more a technical deficiency than a visual failure. A few general remarks are possible. First, a graph is a failure if the text and caption fail to give the reader enough information so that the graph is comprehensible. A good graph-with-caption will label all the elements of the graph and specify the key parameters of the numerical calculation or experiment that generated the graph. However, it is not sufficient to clearly label a curve “Supercalifragilousness” and state in the caption that the “humdinger” was set at 360 “klingons” if these terms are unfamiliar to the reader and the text fails to explain. A physicist or engineer may be reasonably expected to know the meaning of “acceleration” and “mass”, but it is not reasonable to expect all readers to know the atomic number of praseodymium or the decay rate of the chief isotope of meitnerium. Second, much of science is about comparisons. Indeed, it has been argued that the primary function of graphs is to facilitate comparisons. A graph will fail through lack of context if its curves fail to make all the important comparisons. For example, suppose one has developed a new algorithm for numerical quadrature. A graph that demonstrates that the error decreases with an increasing number of quadrature points is encouraging. But a single curve is limited by its lack of context. How does the algorithm compare with older methods like Romberg integration and Gauss-Legendre quadrature? How does the execution time vary with the number of quadrature points, both in absolute terms and also relative to competing methods?
1.8. AREA INSTEAD OF LENGTH AS A VISUAL METAPHOR
19
The most important characteristic of a good graph is that it show enough curves — and the article as a whole contain enough information — so that these kinds of questions can be answered. A graph showing error versus the number of points N is meaningless. A graph showing three curves for three different algorithms may make you immortal. An analogy may be helpful. Each year, over two thousand home runs are hit in major league baseball. Most are insignificant. A home run by Mark McGwire in September of 1998 made him one of the immortals of baseball, and guaranteed his future election to the Baseball Hall of Fame in Cooperstown, New York. The context of his 62d home run of the season was: no one in the hundred year history of professional baseball had ever previously hit more than 61 in a single season. The home run by itself was nothing. (His team lost the game!) The context was everything.
1.8
Area Instead of Length as a Visual Metaphor
Newspaper artists love dearly to turn even the simplest graph into a Work-of-Art. This is often a really bad idea. Fig. 1.13(top) has several flaws. First, beer sales is represented by various sizes of beer barrels. The use of an icon can be helpful; it is almost impossible to forget the topic of the graph — beer sales — while staring at icons of barrels plus the name of one of the world’s largest brewers (Schlitz) in bold letters on the graph. However, the surface area and volume of the barrels both grow wildly out of proportion to the associated numbers. The largest barrel has at least ten times the volume of the smallest, but sales actually grew by less than 30%. Even if the artist had been more careful, the use of area or volume to represent quantity is questionable. The problem is that it is difficult for the eye to estimate areas and volumes accurately. Psychological studies have shown that estimates of volume increase more slowly in the mind than on the graph. The reason seems to be that unconsciously, we simultaneously estimate the length, area and volume of three-dimensional objects. If we see two barrels that differ by 30% in volume, the mind also registers that their surface area differs by just 20% and the width and height by only 10%. When test subjects are asked to estimate the change in volume, these three different numbers seem to be averaged in the reader’s mind to arrive at an answer of 20% when the volumes differ by 30%. The figure also has unnecessary greyscale shading (in the main panel) and solid black shading (with “Schlitz” incised in white within) in the inset. The barrels themselves also distract the eye from the numbers and the axis labels, which are almost invisible in comparison. The lower graph is Wainer’s minimalist rendering of the same data. It is much easier to see what is really happening. First, overall sales are up (good!) but not by a huge amount. Second, Schlitz’ market share is going down for the last couple of years. Schlitz management cannot take credit for the increase in sales; beer has simply become more popular, and Schlitz’ competitors have been increasing their sales even faster. No wonder Schlitz wanted to hide the truth in rapidly-expanding beer barrels and garish shading!
20
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
Figure 1.13:
1.9. LABEL WOES
1.9
21
Label Woes
Obfuscation #5 is to use labels that are illegible, incomplete, incorrect, and ambiguous. These would seem to be such obvious boo-boos that no one past elementary school would make them, but they are actually rather common. Illegible labels usually result from the following causes: 1. Too small type size. 2. Poor placement. 3. Too few labels. One must be careful about choosing a sufficiently large type size because of reproduction during publishing. When the journal is typeset by the publisher, figures are almost always reduced in size from the manuscript. When a figure is published in an Internet journal or by being included on your own Web page, the resolution is reduced to the 72 dpi of a standard monitor — perhaps lower if the figure has to be converted from its original format (Postscript, say) to a format popular on the Web, such as JPEG. Thus, an illustration which looks good as 300 dpi laserprinter output may display illegible labels on the screen. Label placement can be a difficulty, too. A contouring routine offers automatic placement of numbers to label each contour line. However, to find sufficient room to place the numbers without overlapping other contour lines, the labels may be scattered widely — the label for 1.0 near the top, the label for 0.75 on the far left, that for 0.5 on the far right, etc. This can be very confusing for the reader. Manual placement is sometimes a great improvement. However, manual label placement is time-consuming at best. At worst, one may be faced with clustering of lines which makes effective labeling between the lines impossible. Sometimes, what one really needs to do is to erase parts of each line to insert the labels in the erasure regions, but most computer graphics programs do not allow this. Sometimes, a drawing program will permit such modifications.
Figure 1.14: The left panel is over-labeled; so many numbers are written out that they distract the eye from the plotted curve. Does one really need to know all the local minima or maxima, or is the overall shape of the curve (zig-zag and irregular) the important thing? The right curve is better because the labelling is more restrained. Labelling one or two key numbers, here the global maxima and minima, may be useful if these are important numbers that the author wants badly to convey to the reader. Often, however, information such as maxima and minima is given in the caption instead.
22
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
Figure 1.15: These two figures, taken from Kosslyn, are identical except that the graph on the right has a few additional labels which greatly improve clarity. Choosing the proper number of labels can be difficult. If one adds labels with too much enthusiasm, the plotted curves may disappear under a blizzard of text. Fig. 1.14 is overlabeled on the left because the labels merely specify the numbers which are already indicated by the plotted points and the axis label. The reader is likely to spend so much time reading the labels that the curve, which shows the rather unpredictable ups and downs of the realestate market, may be lost in the perception. Labelling a couple of key values, such as the absolute minimum and maximum as done on the right, may be useful because (i) a couple of labels does not distract from the curve very much and (ii) if the reader wants to know the maximum and minimum, it is easier to read labels than to estimate numbers from the curve and axis labels. If the graph has too few labels, the information content can be seriously degraded. Fig. 1.15 is an example of inadequate labeling. The “Don’t” graph already has eight labels; every black dot (representing a person) is already labelled. Nevertheless, the clarity of the graph can be significantly improved by adding another six labels. Without the additions, the reader has to strain to decode some of the relationships between people.
1.10
Emphasize the Unimportant
Emphasizing the essential elements of a graph can be tricky. Fig. 1.16 shows two versions of the same bar graph. The use of differential shading — white for one bar, cross-hatching for another, solid black for the third — has inadvertently emphasized the black bar and deemphasized the unshaded bar. It is often a good idea to use different shadings to distinguish different graphical elements from one another. Here, however, the differential shading is inappropriate because all three elements are bars, and the eye can distinguish them just fine without shading. The “Do” version shades all three bars equally so as to let the numbers themselves do the talking. Another example is Fig. 1.17. The theme of the graph is to illustrate the driver’s controls. Perhaps the best way to do the graph would be show the driver’s compartment only, especially for an audience of engineers. However, the illustrator wanted to place the controls is context, as might be appropriate for a non-technical readership, by showing the whole car. If the publication depicts the controls for several different types of vehicles, such as trucks, minivans, etc., then providing this graphical context would be especially useful. The vehicle type could be specified in the caption, but the less information the reader needs from the
1.10. EMPHASIZE THE UNIMPORTANT
23
Figure 1.16: The solid black color of the rightmost bar in the “Don’t” figure makes it practically jump off the page; we have emphasized this datum through choice of color whether we intended this or not. The “Do” figure shades all three bars equally so that the bars are distinguished only by their length, that is, by their numerical value. caption, the more rapidly she will comprehend the graph. The left version of the figure, however, is a bad way to provide context because the entire car is depicted in exactly the same style so that nothing is emphasized. The “Do” figure is superior because the detailed line drawing illustrates only the driver’s compartment.
Figure 1.17: The goal of this pair of figures is to depict the driver’s controls. The left figure is bad because it shows the rest of the car in the same detail and visual appearance as the important stuff: the driver’s controls. The right graph is better because the extraneous details have been shaded out; the eye is drawn to the driver’s compartment. At the same time, the shaded areas give a context; the controls are those of an automobile.
24
1.11
CHAPTER 1. HOW TO GRAPH BADLY OR WHAT NOT TO DO
Unnecessary Graphic Novelty
One aim of this course is to encourage imaginative graphics when conventional line plots or contour plots are inadequate. However, unfamiliar species of graphs should only be used from desperate necessity. The reason is that unfamiliar graph types make heavy demands on the reader, who must not only master the data of the figure, but also learn the organization and content of a new species of graph. Every graphics maven has a weakness for certain graph species. Howard Wainer, whose book is otherwise a masterpiece of visualization technique and common sense, has an ordinate fondness for the so-called Nightingale rose. This is a kind of polar plot which is so named because it was popularized by Florence Nightingale in her successful efforts to dramatize British losses to disease during the Crimean War, and the need to establish military hospitals, nursing corps, and improved sanitation. Fig. 1.18 compares two versions of the same data. Wainer greatly prefers the top graph because it is a Nightingale rose. However, I find this incomprehensible because I lack Wainer’s familiarity with rose charts. The ordinary pie chart is much more successful with me in presenting the information: Most Francophones (native speakers of French) can speak English as a second language, but only a minority of the English-speaking population of Canada can speak French. The moral of this story is that in choosing graphical species, ask: What is familiar to my audience? What will they find comprehensible? For example, meteorologists are extremely familiar with contour plots because the usual weather map is this type of graph. One may use contour graphs with reckless abandon in The Journal of the Atmospheric Sciences. In contrast, biologists use contour plots much less frequently. Therefore, one should employ a contour plot in article intended for a biology journal only when it is really necessary.
1.11. UNNECESSARY GRAPHIC NOVELTY
25
Figure 1.18: Two plots of the same data which show linguistic ability among Canadians as correlated with their primary language. (Both French and English are official languages in Canada.) The top graph is a Nightingale rose chart, prepared by Stephen Fienberg in 1975. Wainer greatly prefers this to the ordinary pie chart (bottom graph) which he prepared as a bad example.
Chapter 2
The Gospel According to Tufte “Above all else show the data” —– Edward Tufte (1983)
2.1
Data-Ink
One of Tufte’s major themes is the good graphics present their message as simply as possible. A good principle, surely, but as vague as the Christian theme of “Love Thy Neighbor”. Who is thy neighbor? And what is graphical simplicity? To turn simplicity into more practical ideas, Tufte defined the following: Definition 1 (DATA-INK) The non-erasable core of a graphic. Definition 2 (DATA-INK RATIO) data-ink ratio
data-ink total ink used to print the graphic = the proportion of a graphic’s ink devoted to the non-redundant display of data-information = 1.0 − proportion of a graphic that can be erased without loss of data-information
=
The concept of “data-ink” doesn’t completely solve the problem because the question of what actually is “non-erasable” depends on both the problem and the readership. This concept is much more concrete than the vaguer idea of “simplicity”, however. Tufte further elaborates his concepts in the form of five maxims. Tufte’s Five Laws of Data-Ink: • Above all else show the data. • Maximize the data-ink ratio • Erase non-data-ink. • Erase redundant data-ink. • Revise and edit. 27
28
2.1.1
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Show the Data
This is the most important part of the five maxims because the “data-ink” is undefined until one has first developed a purpose for the graphic. Composition teachers press their students to begin the creation of an essay by first writing a “topic sentence” that summarizes: What is the essay about? What is the big idea I want to get across to my readers? Writing a topic sentence for each graph before you begin to compose it is not a bad idea for visualization either. Exploratory graphics is different; in the early stages of a study, one may simply mess around with different views of a hydrodynamic flow, looking for something interesting. When the time comes to design a graph for a journal article or a thesis, one had darn well better be able to supply a topic sentence for the graph, or the work simply isn’t ready for a final draft. “This graph will show the variation of the growth rates of the Charney instability as a function of the zonal wavenumber.” This is an example of a topic sentence. With this in hand, we can then begin to ask a slew of other questions before we begin to draw. First, what do we need to compare with the Charney growth rates? In other words, can this curve stand alone, or is it useful only if plotted with other curves on the same axes? Second, is it useful to compare the graph with other figures, such as the growth rates as a function of latitudinal wavenumber? We can’t plot both curves on the same axis since the zonal wavenumber is different from the latitudinal wavenumber. We might nevertheless wish to compare them to show that growth rate is insensitive to the latitudinal wavenumber, but varies strongly with the zonal wavenumber. In this situation, we make it easier for the reader if both graphs have a common format, linestyle, consistent labels and so on and also if both graphs have clear labels that call the reader’s attention to the fact the ordinate is the same, but the abscissa variable is different. Third, what wider context needs to be explained to the reader so that the concept of “Charney growth rates” is meaningful? The “Charney problem” is a model for the development of midlatitude storm systems. To connect the Charney problem with the real world, it might be necessary to include some graphs of atmospheric observations, perhaps copied with permission from other authors, in an introductory section. And what are “growth rates”? Context is a mixture of good graphs and explanations that orient the reader like the compass rose on a map.
2.1.2
Emphasize the Data
“Maximize the data-ink ratio” is a very general precept that motivates Tufte’s remaining three maxims. Unfortunately, almost all graphics require some non-data elements, such as axis lines, tic marks and labels. One can, however, deemphasize these elements. One way is to draw the data curves using thicker lines than the axis lines and frames. Fig. 2.1 compares two graphs which are identical except that the right panel has a higher data-ink ratio because more ink has been used to draw the thick line for the data. Emphasizing the data is purely an artistic touch because the cognitive content of the graph is not altered. However, design touches do matter because scientists and engineers always have too many papers to read and too little time. A paper with clear, easy-to-decode graphs will make a much more lasting impression than one with confusing illustrations that require a lot of concentrated attention.
2.1.3
Erase Non-Data-Ink or Down with the Grid!
Tufte and Howard Wainer both regard grid lines as the Spawn of Satan. This is perhaps too extreme, but one certainly should be selective in the use of grid lines.
2.1. DATA-INK
29
Little Green Men
Longitude
Little Green Men
Longitude
Figure 2.1: Two graphs identical except that the data-curve has been thickened on the right. Which graph do you prefer? Historically, grid lines became part of the mental framework of technologists because in the pre-computer days, figures were usually drawn by hand on “graph paper”. This was special paper which was printed with a fine checkboard pattern of both horizontal and vertical grid lines. This network of grid lines enormously simplified the task of plotting individual points by hand. Because scientists were accustomed to seeing grid lines when making graphs, they came to expect grid lines when reading graphs, too. At the very least, scientists of the precomputer-graphics era were very good at ignoring grid lines and focusing on the data. Even in those ancient days, however, there was a certain ambiguity about grid lines. First, printed “graph paper” always had the lines printed faintly so as to avoid clashing with the data curves — sound practice for twenty-first century grids, too. Second, the graph lines were printed in a special “non-reproducing” green ink. When a hand-drawn graph was xeroxed, the green ink was not visible on the copy. In the age of computer graphics, we should be even more sceptical of grid lines. Our readership is different from that of 1970: scientists and engineers under thirty-five have rarely used graph paper. They do not expect grid lines; their visual systems are not so good at unconsciously filtering them from the graph when the mind is trying to concentrate on the data-curves. Fig. 2.2 compares two graphs. The data-curve is much easier to read in the right panel because it does not have to compete with the grid. Are there exceptions when one should include a grid? One exception is when the figure is a nomogram, that is, a graph which will be used as a sort of graphical calculator. Grid lines are very helpful if the reader has to use the figure to generate numbers. Nomograms used to be very common, but are now reserved for special applications. One reason for the decline of the nomograph is that many key numbers, such as the maxima and minima of a curve and associate numbers with curve features. Longer strings of numbers can be supplied as a table. Third, in those rather desperate situations where one needs access to a lot of numbers with high accuracy, one option is to archive a data file on a Web site or a CD-ROM. Another option is to print a table which is a listing for a short computer code to reproduce the graph or to list the coefficients of a curve-fitting polynomial. A second exception to the general disparagement of grid lines is when the author expects the reader to carefully study a curve and try to pick out the heights of local maxima and minima. Again, the numbers could all be given in the caption, but when trying to absorb a
30
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Gridded
Gridless
Longitude
Longitude
Figure 2.2: Two graphs identical except that the grid has been omitted on the right. data-curve, the reader doesn’t want to keep his eyes moving back and forth between graph and caption. Grid lines can be helpful when the reader wants to do some “qualitative nomography”, so to speak. A third exception is for certain species of three-dimensional diagrams where a grid box may be helpful in supplying visual clues to correctly interpret ink patterns on a twodimensional plane as representing a shape in three-dimensional space (Fig. 2.3).
10 8 6 4 2 0 -2 -4 -6 -8 50 40
50 30
40 30
20 20
10
10 0
0
Figure 2.3: A surface mesh diagram with a faint grid box to help the reader visualize the three-dimensional shape.
2.1. DATA-INK
31
A fourth exception is when the grid itself carries the message. Fig. 2.4 is a graph twenty years ahead of its time. Pierre Welander showed through this illustration that a smooth vortex flow could distort a blob of fluid into a very wierd object. Although the word “fractal” did not exist in his time, he understood that as time increases, the shape of the marked portion of the fluid would tend to an object with an infinite boundary but a finite area. CarlGustav Rossby, perhaps the most celebrated meteorologist of the century, reproduced this figure in a 1959 review article. It was written for a book to honor Rossby’s sixtieth birthday, but he died of a heart attack shortly after finishing his review, and it appeared as part of the Rossby Memorial Volume. It was not until the appearance of Benoit Mandelbrot’s book Fractals in 1973 that a word for such wierdly-shaped objects, and an appreciation for their ubiquitous appearance in nature, gained currency. The most amazing thing about this figure, and the article in which it appeared, is that Welander had a good understanding of ideas that became popular only many years later. However, it is also a graphical masterpiece. The curve that bounds the marked region of fluid, initially a square, carries the most important message, which is that the perimeter of the blob is being stretched and stretched and stretched without limit. However, the checkerboard of black squares and white squares conveys another message: that distortion is also occurring within the marked blob of fluid. Note that this grid is not used for the usual purpose: To facilitate the conversion of the data curve into numerical values. Welander’s grid has no axis labels to allow such conversion. The checkerboard grid is not to serve as an adjunct to the data curves, but to be itself a graphical representation of the data.
32
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Figure 2.4: This diagram by the late Pierre Welander was published in Tellus(1955). The quasi-circular contours in the top diagram are the streamlines of an atmospheric or ocean vortex; the velocity vector is everywhere parallel to the streamlines. The lower figures show how the 25-cell checkerboard superimposed on the vortex is distorted over time by the vortex flow. The crucial point is that fluid mass is teased out into long, stringy filaments. To use modern language, although the vortex flow is laminar, the advection distorts the initial square of fluid into a curve whose perimeter is increasing without bound even though the area is constant (because of mass conservation). As t → ∞, the perimeter of the marked fluid approaches a fractal, that is, an object which has a fractional dimension in the sense that it is an object of infinite length with a finite area.
2.1. DATA-INK
33
The key guidelines for a grid are: • Don’t use a grid unless you really have to. • Make the grid lines faint compared to the data-curves by drawing the grid as thin lines or dotted lines or by using a thick line for the data. Fig. 2.5 illustrates these guidelines.
Gridded: Half Pt. Solid
Gridless
Longitude
Longitude
Gridded: Half Pt. Thick Data Curve
Gridded: Dotted
Longitude
Longitude
Figure 2.5: Strategies for a grid. The data curve is most visible when there is no grid at all (upper right). If a grid is used, it should be muted relative to the data curve. This can be done by using very thin grid lines (upper left), by thickening the data-curve so it is much darker than the grid lines (lower left), or by making the grid lines dotted (lower right).
34
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
2.1.4
Erase Non-Data-Ink: Hurrah for Half-Framing!
Tufte and some other technical artists such as Mary Helen Briscoe (1996) are advocates of another simplification: half-framing, which is to say, drawing only the the usual horizontal and vertical axes and omitting framing lines on top and the right. In contrast, the default in Matlab is to draw a full frame: whenever axes are drawn, a second line parallel to the horizontal axis is drawn at the top of the graph while a second vertical parallel to the vertical axis is drawn on the right so that the data curves are enclosed in a rectangle. Fig. 2.6 contrasts these two styles of framing. I have no strong opinions. A full frame is common, and I personally am most comfortable with this since it is what I am used to. However, no data is lost or hidden by using only a half-frame. The very notion of a half-frame emphasizes the “data-ink” theme: strive for simplicity and include nothing irrelevant.
Full Frame
Half Frame
Figure 2.6: Left: a graph with a full rectangular frame. Right: a “half-framed” graph in which only the two axes are visible boundaries to the data-curves.
2.1. DATA-INK
2.1.5
35
Erase Non-Data-Ink: Example of the Simplified Bar Graph
Tufte (1983) redesigned a bar chart to illustrate his theme that much can be erased in a graph without compromising the data. The bars have been replaced by thick vertical line segments; short horizontal segments connect each pair of bars, linking them into a single group as in the original bar graph shown on the left in Fig. 2.7. How much information has been lost in the redesign? Nothing. The bars themselves are redundant in the sense that they can be replaced by a simpler element (here, a line segment) that also has a length. Placing pairs of bars side-by-side and shading one of each pair is unnecessary, too. The bars can be grouped by a short, connecting segment. The shading is unnecessary because the left and right bars in each group are always distinguishable. Finally, one can replace a full frame by a half frame. The only disadvantage of Tufte’s format is unfamiliarity. Because a bar chart is familiar and intrinsically rather simple, a bar chart is quickly and easily decoded even though it is not, strictly speaking, maximally simple. Tufte’s new format is unfamiliar, and the reader is likely to stare hard at the text and caption to ask: Why did he choose this novel format? What information is supposed to be conveyed here? Do I understand this strange species of graph, or have I missed something important?
y ; ; y ;; yy ; y ; y ;; yy ;yy y ; y ;;
Standard Bar Chart
Tufte Minimalist Chart
Figure 2.7: Left: a standard bar graph with multiple comparisons. Right: the same in Tufte’s minimalist bar chart format.
36
2.1.6
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Erase Redundant Data-Ink: Symmetry and Wrap-Around and All That
If a function has the property f (x) = f (−x),
for all x
⇒ Symmetric
(2.1)
then the function is said to be “symmetric with respect to x = 0”. Similarly, if for all x, f (x) = − f (−x),
for all x
⇒ Antiymmetric
(2.2)
then f is “antisymmetric with respect to x = 0”. A function which is either symmetric or antisymmetric is said to be of “definite parity” where symmetry is “even parity” and antisymmetry is “odd symmetry”. One hardly needs to learn these jargon terms to know that symmetry and antisymmetry are very common in both the natural and man-made worlds. Human beings and most animals are approximately symmetric about a line draw from the middle of the head to between the feet. The right and left sides of a car or truck are externally symmetric but unsymmetric on the interior. Because parity is so common, our brains are very good at visualizing the complete object from a picture of only the left or right sides. Indeed, psychology experiments have shown that when a person studies a complete picture of a symmetric object, she looks carefully at one half and then barely glances at the other half, just enough to confirm that the object does indeed have definite parity. It follows that if the reader isn’t going to bother to look at the left half of a symmetric or antisymmetric object, one can save a lot of space by erasing the unlooked-at-half. (The figure caption must clearly state that the other half has been omitted because the object has parity, and also clearly state whether it is symmetric or antisymmetric.) Nevertheless, I sometimes graph both halves of a symmetric object. Why? The reason is that the most powerful way to convey the parity of an object is to allow the reader to see it for himself. As a verbal description, the key word “symmetry” might be missed. A graph that shows only positive values of the abscissa does not necessarily imply symmetry. For example, when polar coordinates are employed, the radial coordinate r is defined only for r ∈ [0, ∞]. It follows that if coordinate labels values are all positive, it is not possible to conclude that the object has definite parity. One needs additional information from the caption or text to unambiguously identify the symmetry of the figure. It is sometimes best, especially if symmetry is an important property that deserves emphasis, to simply show the symmetry. Fig. 2.9 shows two versions of flows in a global ocean. To depict the surface of a sphere, the ocean flow must be sliced along some longitude and then projected onto a flat map. The perceptual problem is that the left and right edges of the map are the same longitude. The reader must mentally connect the left and right edges to truly visualize the flow. Tufte’s proposed revision is to expand the graph so that it depicts two-thirds of the globe twice. Because of this redundancy — a necessary and helpful redundancy in Tufte’s opinion — the reader can see the flow in all parts of the globe without the need for mental reconstruction. The broad message is that sometimes redundancy is necessary for complicated visualization. This is certainly true. However, the narrow issue of whether redundancy is good for a particular illustration depends on the context and the readership. Being a political scientist, Tufte is not particularly adept at mentally stitching opposite sides of the globe together. However, oceanographers always have to perform this mental task because the earth is always round, and every physical oceanography article is forced
2.1. DATA-INK
37
Symmetric: One-Half Shown
Symmetric
-1
0
1
0
1
Antisymmetric: One-Half
Antisymmetric
-1
0
1
0
1
Figure 2.8: Schematic of a symmetric function (f (x) = f (−x) for all x, top pair of graphs) and an antisymmetric function (f (x) = −f (−x), bottom pair.) The left graphs illustrate the full function; the dotted line at x = 0 denotes the symmetry or antisymmetry plane. The right pair of graphs shows how the graphs can be simplified by plotting the right half of f (x). to describe spherical geometry through a flat map. So, oceanographers are not nearly as bothered by the Bryan-Cox diagram as Tufte himself. His suggested redundancy has rarely, if ever, been applied in oceanography.
38
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Figure 2.9: Top: Streamlines of ocean flow in a computational model as originally published by Kirk Bryan and the late Mike Cox in 1972. Bottom: Tufte’s suggestion revision, which shows 5/3 of the globe so that one may see all ocean basins without the need to mentally connect the left and right sides of the top figure, which are the same longitude although on opposite sides of the map.
2.1. DATA-INK
2.1.7
39
Erasing: Eliminating the Graph Entirely
Figure 2.10: A graph that should be a table. So many bars are needed that the labels must be nested at three different levels. Furthermore, it is necessary to shade the bars with different patterns to make them distinctive; the rather small number of data numbers is almost obliterated by all the shimmering Moir´e patterns. Sometimes the best way to cope with a flawed graph is to eliminate the illustration entirely, and use a table instead. Fig. 2.10 is a graph that Tufte asserts is better replaced by a table. The figure’s first flaw is that one should eliminate the legend, and directly label each bar. (This is sound general practice.) Unfortunately, it is not possible here because there simply isn’t room to tack nine lengthy labels under the horizontal axis. So, the authors stuck abbreviated, confusing labels — on three levels, no less — under the graph and added a legend box. The second flaw is that the shading patterns add a lot of extra visual elements, distracting attention from the height of the bars which actually carries the information. However, if the shading were omitted, it would be hard for the eye to distinguish one bar from another. One could do better by turning this bar graph on its side so that the bars project horizontally. This allows long labels for each bar. Furthermore, since the page is longer than it is wide, one can add enough white space between the bars so that they are distinguishable without Moir´e patterns in each bar. However, Tufte’s more radical solution is to replace the graph with Table 2.1.
40
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Table 2.1: Table replacing Graph from pg. 121 of Tufte(1983) Content and tone of front-page articles in 94 U. S. newspapers, October and November, 1974 Watergate: defendants and prosecutors, Ford’s pardon of Nixon
Number of articles 537
Percent of articles with negative criticism of specific person or policy 49%
Inflation, high cost of living
415
28%
Government competence: costs, quality, salaries of public employees
322
30%
Confidence in government: power of special interests, trust in political leaders, dishonesty in politics
266
52%
Government power: regulation of business, secrecy, control of CIA and FBI
154
42%
Crime
123
30%
Race
103
25%
Unemployment
100
13%
Shortages: energy, food
68
16%
2.1. DATA-INK
2.1.8
41
Revise and Edit
Writing teachers emphasize the important of multiple drafts. Indeed, “first draft” has become a perjorative term. The initial version of a document can almost always be clarified by revision and editing. Similarly, fine arts teachers and graphic designers stress the usefulness of preliminary sketches and of techniques for making changes on the painting or drawing itself. Revision and editing are equally important for scientific visualization. The intellectual content is not changed by editing, only the clarity. However, in an era of “Short Attention Span Theater”, a graph is pointless unless it is clear. Tufte illustrates the revise-and-edit cycle through a case study. The figure was originally published in a 1947 textbook by the Nobel Laureate Linus Pauling. It was drawn by Roger Hayward, whom Tufte describes as a “distinguished science illustrator” even though he strongly criticizes the published figure, which is shown as the upper left panel of Fig. 2.11. On the upper right are all the graphical elements that Tufte considers redundant. First, the full frame has been reduced to a half-frame by eliminating the boundary lines on the top and right. Second, the original figure labeled every tick mark, but labelling every other tick mark is satisfactory. Lastly, the grid, which here is a lattice of plus signs, is redundant. The middle left figure shows the result when all these redundant elements are eliminated. Version 2 is a vast improvement over the original. However, a pretty good graph is not the same as the best graph, so Tufte experimented with other variations. In Version 3 (middle right), the dashed curve connecting most of the points has been eliminated. Although it is unnecessary for cognitive content — the data points are still there — the curve is helpful in guiding the eye to make sense of a pattern of points. Without the dashed curve, the figure is simply harder to read. The next version (lower left) restores the grid. The result is both confusing and ugly. This was not a serious experiment, but rather another opportunity for Tufte to attack grids. His final version (lower right) is similar to Version 2 except that it has more labels. Each of the peaks is now labelled with the name of the element and its atomic number. The plateau between atomic numbers 60 and 70, which breaks the pattern for rapid rise or fall of the rest of the graph, is now labelled “the rare earths”. Because of the labels and the reference curve, the significance of the peaks and the plateau is almost instantly perceptible. This case study makes several points. First, experiment: try several versions of the same figure and save the one that you like the best. Experimentation is easy with Matlab, which allows one to add or subtract labels, delete or add axes and so on, with a single command. Second, “redundancy” is a matter of rather subtle judgment. One could, for example, thin out the axis labels still more, delete the dashed curve, and all the labels of the peaks and the plateau, and the data points would all still be there. The point is not that redundancy or non-data-ink is necessarily bad, but rather that non-data-ink should be there for a reason: to make the graph clearer.
42
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Original Publication (Pauling, 1947)
Redundant Grid, Labels & Frame
Version 2 (Tufte)
Version 3 --- Curve Removed
Version 4 --- Grid Restored
Final Version (5) --- No Grid, Added Labels
Figure 2.11: Upper left: a figure drawn by Roger Hayward for General Chemistry by L. Pauling. Upper right: the graphical elements that can be erased from the graph without damaging its intellectual content. Remaining panels: four different versions of Pauling’s graph. The lower right diagram is Tufte’s favorite.
2.2. HIGH DATA DENSITY
2.2
43
High Data Density
Another theme of Tufte’s is that good graphics have high “data density”. To calculate this quantity, note that the numbers to be plotted in a graphic can be written as an array of one or more dimensions. Definition 3 (Date Density) data density =
number of entries in data array area of data graphic
Figure 2.12: High data density graphic: illustration of many experimental measurements of the thermal conductivity of copper. Each string of dots, connected by a thin curve, is from a single publication which is identified by a number enclosed in a circle. Each of these 200-plus articles is listed with its identification number in the bibliography of the source of this figure, C. Y. Ho, R. W. Powell, P. E. Liley, “Thermal conductivity of the elements: A comprehensive review”, supplement no. 1, J. Phys. Chem. Reference Data, 3, pg. 1-244 (1974). The thick solid line is the recommended curve. Not withstanding this formal definition, the concept of a “high data density” graphic is perhaps best illustrated through some examples. Fig. 2.12 compares a large number of simultaneous measurements of thermal conductivity as a function of temperature. Because more than 200 different curves, each labelled, are combined into a single graph, Tufte has canonized this as a Good Example. Is it? Well, yes, but only up to a point. First, there is no really good way to present 200 data sets. A single figure is certainly much easier to grasp than a whole of lot of figures,
44
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
or a verbal description. The authors did as good a job as possible this vast amount of information. However, it is extremely unlikely that anyone would actually correlate all two hundredodd curves with the bibliographic references given many pages later. In that sense, most of the labels are useless for a given reader. Furthermore, for high temperatures (greater than the 250o K., say) the measurements are all superimposed on one another. The information presented in this range is really (i) a single curve plus (ii) a verbal description, graphically expressed by the article numbers, that all the measurements agree closely. For low temperatures (below 80o K.), many curves can be visually distinguished. However, these curves are not useful in and of themselves because most of them are gravely in error. The information conveyed in this range is: measurements of thermal conductivity at cryogenic temperatures is difficult and published estimates vary wildly. This sentence conveys the information almost as well as the graph. The authors also provide a solid curve which represents the “recommended” curve. This immediately raises an important question: How can one “recommend” anything when the measurements disagree by as much a factor of one hundred? One purpose of a good graphic is to raise questions, and this does. However, the answer must come from the text. This graph is a good figure. However, in designing high density graphs, one must recognize that the reader is never going to be able to remember or even visually identify all the curves, all the data. The crucial design principle for high density graphs is not: Let’s find a good way to cram lots of curves/points/arrows/labels in a small area. Rather, one should identify key themes or goals of the figure, and then design and edit so the graphs successfully presents these themes. Tufte is practically beside him in praising Fig. 2.13. The sky was divided into more than two million rectangles, and then the 1.3 million galaxies of the Lick Catalog were binned into one of the rectangles. The density within each rectangle was represented by a grayscale. The map was very influential because it suggested that there might be very large-scale structures, chains and filaments, in addition to the clusters and superclusters that were previously known. Later work has extended the graphics into three dimensions and confirmed that on a very large scale, the universe is filled with a kind of “cosmic foam”: bubbles of void surrounded by sheets with a relatively high density of galaxies. Is this a good graphic? Yes, but high data density is only part of the reason. First, the figure is good because its scientific message is important. This is the first qualification for graphic greatness! Second, the figure is good because it allows one to see new things in old data. The Lick Catalog had been expanding for many years before this 1974 illustration was extracted from it. Every one of the galaxies had been individually measured from a photographic plate. Nevertheless, filaments and clumps in the map were terra incognita1 before this illustration was published. However, high data density is only indirectly responsible for the usefulness of the graph. First, note that if the Lick Catalog had contained only half a million galaxies or as many ten million galaxies, the usefulness of the figure would not have been changed. The discovery of filaments is a qualitative property that cannot be altered by adding more galaxies. (However, the authors might have gained additional confidence in their discovery with a larger sample). Similarly, reducing the number of galaxies by two-thirds would have made the filaments fuzzier and less distinct, but not enough to have prevented the authors from noticing them. Second, one can analyze a high density graphic from the perspective of the branch of engineering known as “Information Theory”. This was created by Claude Shannon in the 1 “Terra
incognita” is Latin for “unknown lands”.
2.2. HIGH DATA DENSITY
45
1930’s to analyze telecommunications system. The amount of bandwidth needed to transmit a message obviously depends on the information in the message, but real messages have noise and redundancy. Shannon was able to quantify these complications. His definition of “information” is the number of computer bits needed to encode a message, sans redundancy. For graphics, it would perhaps be more meaningful to quantify the “information” as the number of words needed for a verbal description of the key themes of the graph or the number of brush strokes necessary for an artist to draw a copy of the graph that contains the key ideas. By either a verbal or artistic measure, the information theory-content of the galaxy map is much smaller than two million grey tones. The verbal information is one sentence: “The galaxies in the cosmos are clumped into filaments”. The artistic description is fuzzier. However, an artist could trace over the map and outline the clumps and filaments with considerably less than two million brushstrokes. Indeed, less than a thousand would suffice. The freehand sketch of the clumps and filaments (Fig. 2.14) took only a few minutes, and yet depicts the essential content of the density map. Indeed, it shows the filaments much more clearly than the grey tones of the figure it imitates. A reduced-density graph could have been made more systematically by applying a filter; points above a certain threshold density of galaxies are black while points of lower density are white. Again, this would show the filaments more clearly. The conclusion is that high data density is a virtue but should not be elevated above the more fundamental principles: clear labels, clear theme, and so on. It is very easy for a high density graphic to be fuzzy or hard to read. Indeed, perhaps the best way to present the important implications of the Lick Catalog would be to publish two graphs: a high density gray scale map to show the raw data with minimal editing, and a reduced density black-and-white graph to show the filaments and clumps more clearly.
46
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Figure 2.13: Density of galaxies. The sky was divided into more than two million rectangles. The number of galaxies in each rectangle is encoded by ten different gray tones. Although similar filaments appear even in randomly created data, the filamentary structure apparent in the map is real. Map created by Michael Seldner, B. H. Siebers, Edward J. Groth and P. James Peebles, “New reduction of the Lick Catalog of galaxies”, Astronomical Journal, 82, pg. 249-314 (1974).
2.2. HIGH DATA DENSITY
47
Figure 2.14: Sketch of the clumps and filaments in the previous figure of a galaxy density map, drawn in less than fifteen minutes in Adobe Illustrator
48
2.2.1
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
The Shrink Principle
Consistent with his theme that High-Data-Density-is-Good, Tufte advocates complicated multi-panel graphs that pack a lot of information into a single composite figure. This in turn is possible because of the following: Definition 4 (Shrink Principle) Graphics can be shrunk way down. — Tufte(1983), pg. 169 Fig. 2.15 illustrates this principle. Six one-dimensional graphs and six two-dimensional graphs are combined into a single composite. The top and middle pairs of two-dimensional graphs are contour plots; the bottom pair are satellite photos. The one-dimensional graphs on the left are a mixture of line graphs (time series of continuously recorded data) and histograms (precipitation, which is normally described by accumulations rather than rates). Several factors contribute to the success of this figure for its intended audience. First, this forecast was prepared as a special handout for attendees of an international meteorological conference, IAMAP ’89. Because the readers are all professional meteorologists, extensive labels and elaborate explanatory captions were unnecessary, which helps enormously in fitting a dozen graphs on a single page. Second, the purpose of the figure was mostly public relations; it was prepared by the European Centre for Medium-Range Forecasting, which generates weather prognostications for an eighteen-nation consortium, to illustrate the work of the Centre for conference guests who were given a tour of the Centre’s facilities. If the figure is “over-shrunk” or the labels too few, this is much less serious for public relations than for a research journal. Second, the figure filled the entire 8.5” x 11” (including the margins). If reproduced in a digest-sized journal, the diagrams would have to be shrunk considerably with a corresponding loss of legibility. High density, heavily shrunk graphics must be designed to fit the limits of the publication medium. Satellite photos and pressure contour plots are widely available on the Internet. However, no site attempts to pack twelve diagrams into a single screen. Instead, the photos or contour plots are presented one at a time. Composite figures are often used to organize thumbnail sketches to present a kind of visual index of the data. However, at the usual screen resolution of only 72 dots-per-inch, it is impossible to identify fronts and vortices from a thumbnail sketch an inch square. High density is good, but know your target! Fig. 2.16, originally published in Bertin’s classic Semiology of Graphics, is Tufte’s epitome of a good high density graphic. Seventeen different plots of several different graphics species are combined into a single composite figure. The data curves, however, are clearly visible so that this graph is successful. However, success must be defined carefully. At this density, almost all labels must be omitted from the graphs because there just isn’t room. Full frames, and not merely halfframes, are helpful in visually distinguishing one plot from another. Further, the graph is effective because none of the data curves are oscillating too wildly. Curves of complicated shape must be presented at a larger size than curves with but a single maximum and minimum and smooth, monotonic variations in between. The degree of allowable shrinking is data-dependent as well as resolution-dependent. With these caveats, Tufte’s principles of high data density, shrinking plots, and combining many graphs into a composite figure are all sensible. It is much easier for a reader to grasp a set of related figures if they are all one one page in a single multi-panel figure than if they are scattered over many pages. In the days before computer graphics, cartoon animators would draw a series of sketches and then check their work by rapidly flipping the sketches so that they would flash past
2.2. HIGH DATA DENSITY
49
the eye quickly enough to produce the illusion of continuous motion, as in the final filmed cartoon. Far too many scientific papers and doctoral theses require their readers to be “Disney animators”, treating the paper as a “flipbook”. What cannot be animated or converted into hypertext (as on a Web site) should be combined wherever possible.
Figure 2.15: A “meteogram”, created by the European Centre for Medium-Range Forecasting in Bracknell, England, for distributions to attendees of an international conference (IAMAP) in the adjoining town of Reading, England. Each of the four contour plots is a snapshot of two different weather variables, represented by isolines and by shading, respectively. The upper two show 500 mb geopotential height and 500-1000 mb thickness anomalies; the lower pair show surface pressure and accumulated precipation for the preceding 24 hours. The two photos at lower right show cloud thickness as observed by satellite. The line graphs and histograms on the left depict a variety of variables at the conference site of Reading.
50
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Figure 2.16: A seventeen-panel figure, originally from J. Bertin’s Semiology of Graphics.
2.3. MULTIFUNCTIONING GRAPHICAL ELEMENTS
2.3
51
Multifunctioning Graphical Elements
“Mobilize every graphical element, perhaps several times over, to show the data.” Tufte(1983), pg. 139 This good advice is not easily implemented, but on those rare occasions when it can, the results can be very useful to the reader. The best way to illustrate this theme is through concrete examples. The first example is Table 2.2, which is a table that also functions as a graphic. The reason that this table is effective for its intended audience of military specialists is that in the American army, the basic unit is the division, and each division is identified by a unique number. The 82d and 101st divisions, for example, became elite paratroop units that parachuted into Normandy on D-day. Later, these units converted to helicopters and became “air cavalry”, playing an important role in Vietnam. To a military man or woman, the division number conveys valuable information. Because this table has been designed so cleverly, one can almost instantly deduce three pieces of information: • The date each division came to France • The number of columns in France each month (by summing the nonzero entries in a column) • The duration of each division’s stay in France (by summing the nonzero entries in each row)
52
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Table 2.2: The American Build-up in World War I Table-graphic by Col. Leonard P. Ayres for his book The War with Germany, (1919), pg. 102. Each horizontal column indicates the months that a particular army division, denoted by its unique identification number, was present in France.
1 Jun
1 Jul
2 1 Aug
26 2 1 Sep 1917
26 2 1 Oct
42 26 2 1 Nov
41 42 26 2 1 Dec
41 42 26 2 1 Jan
32 41 42 26 2 1 Feb
3 5 32 41 42 26 2 1 Mar
77 3 5 32 41 42 26 2 1 Apr
80 30 33 6 27 4 28 35 82 77 3 5 32 41 42 26 2 1 May 1918
29 37 90 92 89 83 78 80 30 33 6 27 4 28 35 82 77 3 5 32 41 42 26 2 1 Jun
36 91 79 76 29 37 90 92 89 83 78 80 30 33 6 27 4 28 35 82 77 3 5 32 41 42 26 2 1 Jul
40 39 88 81 7 65 36 91 79 76 29 37 90 92 89 83 78 80 30 33 6 27 4 28 35 82 77 3 5 32 41 42 26 2 1 Aug
34 86 84 87 40 39 88 81 7 65 36 91 79 76 29 37 90 92 89 83 78 80 30 33 6 27 4 28 35 82 77 3 5 32 41 42 26 2 1 Sep
1 38 31 34 86 84 87 40 39 88 18 7 65 36 91 79 76 29 37 90 92 89 83 78 80 30 33 6 27 4 28 35 82 77 3 5 32 41 42 26 2 1 Oct
2.3. MULTIFUNCTIONING GRAPHICAL ELEMENTS
53
Fig. 2.17 is sort of the converse of Ayres: instead of a table that functions also as a graph, this drawing is a graph that functions also as a table. The thick vertical lines are the bars of a standard bar chart. The artist wanted to label each bar with its numerical value so that the graph would provide the same precise numbers as a table. Unfortunately, there are too many bars to allow direct labelling of each bar. Instead, the artist added thin horizontal lines to attach the top of each bar to the corresponding label. The labels can thus be stacked vertically, and contain as many digits or letters as necessary without crowding; the label stack functions as a table. The horizontal lines themselves have heights equal to the heights of the bars and thus carry data-information themselves ( although this is redundant to the heights of the bars, which provide the same visual sense of magnitude).
8.1
6.3 5.9
3.9 2.2 2.1 1.3
Figure 2.17: A graph that is also a table in the sense that the numerical heights of each bar are tabulated in a column on the left. An imitation of one by Carol Moore for a corporate annual report and reprinted in Tufte(1983), pg. 152 (bottom), and also in Walter Herdeg, Graphic/Diagrams, Zurich (1976), pg. 23.
54
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Ayres’ and Moore’s table-as-graph, graph-as-table inspired Tufte to try his hand at redesigning the flight-of-steps graph which is common in statistics. Fig. 2.18 shows a standard step chart on the left. On, the right, the same graph is presented in the style of Tufte’s curve-free graph on pg. 151 of his 1983 book. The integers are now “multifunctioning” in the sense that these not only label different steps, but their height on the graph conveys the same numerical information as the height of the steps does in the standard flight-of-stairs chart. The precise numerical values of each step are vertically stacked along the vertical axis. Thus, this is a graph that is a table, too. Multifunctioning graphs are always clever, but this isn’t the same as being effective. The floating pattern of integers in Tufte’s redesign does not give as good a visual sense of the steps as the standard flight-of-stairs graph. The figure would look less strange if the stairsteps were added, perhaps as a thin dotted curve in back of the digits. Similarly, Moore’s style of bar chart contains horizontal lines that are redundant. Furthermore, the eye must follow the thin horizontals rightward, then the thick bars downward to find the bar labels on the horizontal axis, and so connect them with the corresponding number. (The horizontal labels are omitted from our schematic, but would be included as essential information on any real graph.) In a table, the numbers and the alphanumerical labels would be side-by-side, which makes it much easier to determine that 2.3 was the number of barrels in millions sold by the Schlitz company this past year (or whatever).
yyy ;;; ;;; yyy ;;; yyy 0
2
4
1.77 1.43 1.21 1.18 0.71 0.51 0.33
1 2 3
4 5 6
7
6
Figure 2.18: Left: a standard step chart, similar to the exemplar on the style sheet of the Journal of the American Statistical Association. Right: The same plot in Tufte’s graphinto-numbers style.
2.3. MULTIFUNCTIONING GRAPHICAL ELEMENTS
55
Another Tufte example is a comparison of taxes as a percentage of gross domestic product for two different years for a variety of countries, printed on pg. 158 of Tufte(1983). Similar graphs are common in quantum chemistry and atomic physics where they are known as “level-crossing” diagrams. Fig. 2.19 is a schematic example. The reason for the name “level-crossing” is that the perturbation, whatever it may be, can change the ordering of the atomic states so that the third lowest energy state, “2p”, becomes the second lowest when the perturbation is at full strength. The numerical labels make this graph function as a table. However, the visual elements — the connecting lines between the two stacks of labels and numbers — are important, too, because they allow the reader to instantly grasp which states have switched relative positions when energy from lowest energies to highest.
2p
5.75
5.21
2s
2s
3.23
3.22
2p
1.97
1s
1s
1.11
0
0,5 Perturbation Parameter
1
Figure 2.19: A schematic “level-crossing” diagram from physics. Left: atomic states (by name) and energy levels for the unperturbed atom. Right: the same when the perturbation parameter is equal to one. The lines show how the eigenvalues [energy levels] of the Schroedinger equation vary with the strength of the perturbation parameter.
56
2.4
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Small Multiples or Animations-on-a-Page
Even though he devotes at least one chapter to “multiples” in each of his three books, Tufte never precisely defines the concept of “small multiples”. Indeed, he eventually abandoned the adjective “small” in his latest (1997) book where a chapter is entitled “Multiples in Space and Time”. The closest he comes to a definition is the following from Envisioning Information, pg. 67: “Illustrations of postage-stamp size are indexed by category or a label, sequenced over time like the frames of a movie, or ordered by a quantitative variable not used in the single image. Information slices are positioned within the eyespan, so that viewers make comparisons at a glance — uninterrupted visual reasoning. Constancy of design puts the emphasis on changes in data, not changes in data frame.” In short, a “small multiple” is really an animation-on-a-page. The trick which underlies animation is that when a sequence of discrete images is shown rapidly, the mind can be fooled into perceiving continuous motion. However, a necessary condition for this illusion is that the individual frames must differ by a small amount. A “small multiple” figure is a collection of miniature illustrations, arrayed as a single figure, which are designed to be perceived as one. Just like a true animation, the frames must differ by only a small amount from one another, or the illusion is spoiled and each frame is perceived as an individual rather than as part of the whole. This requires that each graph in such a multipanel figure must be the same size, same graph species, and same all other aspects of the design. Only the data itself, and perhaps the number which indicates the time or time-like parameter that orders the sequence, can differ from one miniature graph to the next. The necessity for small differences from one frame to the next so that the mind can combine a dozen graphs into a single mental filmstrip is the reason for Tufte’s modifier “small”. “Multiple” means multiple images of the same quantity for different times or parameter values, apparently. Still, “multiples of time and space” and “small multiples” seems remarkably sloppy terminology for a proponent of graphical precision. “Animation-on-a-page”, “flipbook-ona-page”, and “quantitative storyboard” are more descriptive. And yet these labels have problems, too. The difficulty is that terms like “animation”, “flipbook” or “storyboard” are all borrowed from the jargon of movies and television. A multi-panel figure has its own rules for good design, and these are different from those for The Simpsons or Star Wars. Fig. 2.20 shows a composite graph which is rather close to an animation: the frames are merely snapshots from the time evolution of a plasma. Even here, however, there are differences from the cinema. First, a movie film animates at a rate of twenty-four frames per second. To fit the graphs into a single figure, this “animation-on-a-page” shows only six different times. Second, to make it easier to understand the flow, each time is illustrated in two different ways: once as a mesh plot and the other as a contour graph. Steven Spielberg has used a split screen occasionally, no doubt, but this breaks the illusion of continuous motion; one has to consciously study both representations. Fig. 2.21 is a step further from cinema. First, there are only four frames. Second, the ordering parameter is not time, but rather the width of the hyperbolic secant function. There is still a sense of continuous variation from a narrow graph to a wide graph, and these four panels are meant to be perceived as a single, coherent message.
2.4. SMALL MULTIPLES OR ANIMATIONS-ON-A-PAGE
57
Figure 2.20: Plasma fields over time, beginning in the upper left. Each field is shown as both a three-dimensional mesh diagram and also, immediately to its right, as contour plot. From Ghizzo et al., Phys. Fluids, 31, 72-82 (1988).
sech(2 x) cos(x)
sech(x) cos(x)
1
1
0.5
0.5
0
0
-0.5
-0.5
-1
-5
0
5
-1
-5
sech(x/2) cos(x) 1
0.5
0.5
0
0
-0.5
-0.5 -5
0 x
5
sech(x/4) cos(x)
1
-1
0
5
-1
-5
0 x
5
Figure 2.21: An illustration of the principle of “small multiples”. Each of the four panels is identical except for changes in a single parameter: the width of the hyperbolic secant (“sech”) function.
58
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Figure 2.22: Saturn and its rings as viewed through telescope from various positions in its orbits. Christian Huygens, Systema Saturnium, (The Hague, 1659),pg. 55. Fig. 2.22 was drawn by Christian Huyghens centuries before there were movies. Nevertheless, one could easily imagine morphing the images into a Quicktime movie to follow the visual appearance of Saturn’s rings through one complete Saturnian year. However, Huyghens had a deeper purpose. Through a telescope, with the image jiggled continuously by small-scale turbulence in the atmosphere, Saturn was drawn differently by many different observers, depending both on individual interpretation and also when in the planet’s 29-year orbit it was seen by a particular astronomer. Huyghens’ small multiple figure shows that these different images can be explained by a single model: a planet with rings tilted at an angle to the earth. He wants the reader to linger over the individual frames, recognizing Galileo’s model and Brahe’s image, and then to gather the whole sequence into a single theory. The animation of the Saturnian system is only half the story, and a Quicktime movie of Huyghen’s frames would miss a major portion of his message.
2.4. SMALL MULTIPLES OR ANIMATIONS-ON-A-PAGE
59
Figure 2.23: Sequences illustrating the strokes in drawing capital letters. Gerardus Mercator, Literarum Latinarum, quas Italicas cursoriasque vocant, scribendarum ration [The Method of Writing the Latin Letters, Which are Called Italic and Cursive] (Louvain, 1540), chapter 6. Our final example would make a good storyboard for a training video on penmanship, although it was drawn by the famous mapmaker Mercator more than four centuries before Philo Farnsworth, Fig. 2.23. One critical point is that the figure illustrates the individual strokes for drawing a letter. Because each letter requires several strokes, the instruction for a given letter cannot be animated by flowing smoothly from one image to another. Instead, a real training video would likely stop-and-go: a burst of smooth video to illustrate the first stroke, then a few seconds in which the completed stroke is frozen on the screen while the narrator explains how the pen must be tilted for the next stroke, then an animation of the second stroke followed by a few seconds when the partially completed letter is again motionless, and so on. In addition, because the sequence for a given letter occupies only a small amount of space, the nine rows of the figure each illustrate a different letter. In this sense, Mercator’s figure is not an animation but rather nine separate brief animations. Any sequence of frames that are “multiple” with “small” variations from frame to frame can be animated. If there are too few frames to make a smooth movie by themselves, one can interpolate between the frames — in computer graphics, this interpolation is called “morphing” — until the animation is pleasing to the eye. In principle, all “animationon-a-page” or “small multiple” graphs can be converted into actual Quicktime or MPEG movies. However, the symbolic equation “small multiple” graph ↔ one animation with morping between frames
(2.3)
is quite inadequate to describe the diversity of multipanel figures with slow frame-to-frame variations. Because of this diversity, there isn’t really a good term for this class of graphs. Nevertheless, the ability to condense many small graphs into a single mental picture is as important in science as in cinema.
60
2.5
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
One Plus One Is Three
Josef Albers wrote a famous essay, much admired and quoted by Tufte, with the provocative title, “One Plus One Equals Three or More: Factual Facts and Actual Facts”. He illustrates his message that in graphics 1+1=3
(2.4)
What he means by this zen-like koan is that elements of a graph interact with one another. Because of this, a good graph is more than a simple addition of its various pieces. In designing a graph, the first question is: What to include? There is, however, a second phase, which is to ask: How does these parts interact? What should be emphasized with a thick line? What should be deemphasized with a thin line? Can the data curves be easily picked out from the frame, labels and other elements?
Figure 2.24: Taken from Albers’ book, Search Versus Re-Search (Hartford, 1969), pp. 17–18.
2.6. LAYERING, SEPARATION AND RUBRICATION
2.6
61
Layering, Separation and Rubrication
Cartoon animation is all about layers. Before 1920, a few pioneering cartoons were produced by laboriously drawing each figure from scratch. Then a new idea reduced reduced costs enormously. The background was painted in as before, but the characters were painted onto thin sheets of transparent celluloid. Each sheet or “cell” was laid in place over the background painting and photographed. To further reduce costs, later low budget animators used one cell for a character’s body and then overlaid additional cells with mouth, eyes and eyebrows and so on. Only the mouth cell is changed while the character speaks. A collection of stock cells showing a character’s mouth in various positions enables a clip of a few seconds to be filmed with only two drawings: one for the background and one for the body. Drawing programs such as Adobe Illustrator allow a figure to be separated into layers. The reason is that like cartoons, complex illustrations subdivide into groups which are closely related, but logically distinct from the other groups of the figure. It is just as convenient for the illustrator to be able to manipulate background, body, and face separately as it is for the animator. Similarly, most scientific and engineering figures are overlays of several layers that are logically distinct, even though they may appear as a single image in the final printed product. The frame and tick marks are one logical layer; the axis labels and title are a second, text layer; the data curves are a third layer. It is very advantageous to recognize that an illustration can be decomposed into layers because these layers are of varying degrees of importance. Much of Tufte’s philosophy can be summed up as: emphasize the data curve layer, and mute the other layers. (Parenthetically, note that this layering occurs in the computer representation of a graph in an object-oriented software system such as Matlab through the concept of curves, labels, and so on as “children” of a set of axes, which in turn are children of the figure.) Layering implies “separation” in the sense that different layers should be separated by space, linestyle, color, type font and other properties — insofar as practical — so that groups of elements which are logically distinct are also graphically distinct. This principle is easier to state than to do. For example, Fig. 2.25 shows two versions of a railway table with two different strategies for the “separation” of different rows. The top figure employs the not-very-good solution of using heavy grid lines, often called “rules” in graphic design, for “separation”. The difficulties with this were stated more than sixty years ago by a well-known graphics designer: “The setting of tables, often approached with gloom, may with careful thought be turned into work of great pleasure. First, try to do without rules altogether. They should be used only when they are absolutely necessary. Vertical rules are needed only when the space between columns is so narrow that mistakes will occur in reading without rules. Tables without vertical rules look better; thin rules are better than thick ones.” Jan Tschichold, Asymmetric Topography, Basel, 1935), pg. 62. The lower version of the table has dumped all the horizontal and vertical rules. Instead, groups of related trains are visually linked through grey-shading or the absence of same. The original table was badly ordered because the train number, used only by railroad employees, was assigned prominence-of-place by being the first row. It was moved to the bottom in the revised table. In addition, the little rows of dots in each blank cell have been replaced by long continuous lines of dots, which guide the eyes to the next number.
62
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Train No.
3701
3301
3801
3542
3765
New York
12:10
1:30
3:45
7:30
4:33
Newark, N. J.
1:43
10:30
5:21
8:50
11:45
North Elizabeth
....
......
......
.........
6:45
3:33
2:05
........
...........
7:05
6:40
........
7:20
8:50
Elizabeth Peekskill Ediison, N. J.
5:34 4:45
Princeton, N. J. 1:30
New York Newark, N. J. North Elizabeth Elizabeth Peekskill Ediison, N. J.
12:10 1:43
.....
1:30 10:30
4:40
2:10
11:05
........
3:30
7:30
3:45 5:21
7:30 8:50
.... ...................................................... 3:33 5:34 4:45
Princeton, N. J. 1:30 Train No.
5:20
3701
4:33 11:45 6:45
2:05
...........................
7:05
6:40
........
7:20
8:50
4:40
2:10
11:05
..........................
3:30
7:30
3542
3765
5:20
3301
3801
Figure 2.25: Two versions of a railway timetable with the “bad” version on top. Inspired by an example from pgs. 54-55 of Tufte(1990).
2.6. LAYERING, SEPARATION AND RUBRICATION
63
Another illustration from Tufte’s chapter on “Layer and Illustration” is imitated as Fig. 2.26. It is desirable to visually isolate the warning from the rest of the text, which is advertising puffery, copyright warnings and so on. A good graphic designer always emphasizes that which is likely to kill his readers! However, the black box in the top figure almost overwhelms the text. Tufte likes the much more muted frame in the lower figure. His philosophy is: “For background elements, grey is better.” (Better than black, that is.) But is it? Most smokers don’t read the text on the cigarette package. One could make a case that the black box is better because it is so striking that a veteran smoker is likely to notice the box and be reminded that the smoking is hazardous without reading the familiar text inside the box. There are other familiar examples where a strong background element is okay. At an intersection, the red octagon moves the foot from accelerator to brake even before the eyes have read the word “STOP” in the middle. For most scientific graphs, though, the data curve is unfamiliar, and a muted background is better. Color and greyscale are both powerful tools for separation. To a printer, “separation” actually refers to the generation of four separate images of a figure, one for each of the primary colors, which will then be used to make a separate photolithography plate. The page is printed four times, each time with a different plate and different color of ink, to receive the full-color illustration. This layering-by-color which happens in printing can also be reversed; one can conceptually layer the figure first and then assign separate colors to each layer. (The conceptual layers will then have a physical manifestation as the separate lithography plates.) The only disadvantage of separation-by-color is that it is expensive — four times as many photolithography plates, four times as many impressions and a very costly, multi-pass printing press. If one can afford it, though, separation-by-color is very valuable.
SURGEON GENERAL'S WARNING:SMOKING MAY SHORTEN YOUR LIFE EXPECTANCY
SURGEON GENERAL'S WARNING:SMOKING MAY SHORTEN YOUR LIFE EXPECTANCY Figure 2.26: Two versions of the mandatory warning label on cigarettes. The grey box allows the message to be read more easily while still setting the warning off from the rest of the text on the cigarette package (not shown). Imitation of Tufte (1990), pg. 62.
64
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
chronic antenna
chronic antenna crystal oscillator
year dial
micro-fusion reactor
Acme Time Machine Figure 2.27: A whimsical illustration of an imaginary technology; red is used to separate the labels from the parts themselves. Indeed, the principle of emphasis-and-logical-separation-by-color is so basic that it was in widespread use long before the invention of printing. During the Middle Ages, church missals, which contain the prayers recited during various services of the Christian Church, had the main text in black ink. The stage directions — “bishop turns and blesses the congregation”, “acolyte rings the bells three times ” — were written in red ink. This made it impossible, even in a smoky, candle-lit church, for a priest to confuse a prayer with a stagedirection. Red ink was also routinely used for emphasis in other illuminated manuscripts of all kinds. Indeed, the use of red was so ubiquitous that it added words to the language. The verb “rubricate” means “to add stage-directions or marginal comments”. (The word is derived from the Latin for “red”.) Churchmen became so familiar with seeing liturgical directions in red that these became known as “rubrics”, and are still so known in the modern Catholic Church. Multi-colored printing followed Gutenberg’s work rather early. The first two-colored book in English was printed by a man who is known to us only by his job description as “The Schoolmaster of St. Alban’s”. In this small, provincial town, this unknown teacher supervised the printing of a small volume for his students that had part of the text in red, part in black, to make it easier for his students to learn. Half a millenium later, separationby-color is still a valuable tool for learning and teaching both in texts and graphs. Tufte (1990) reprints a splendid modern example on his pg. 54: an exploded view of an IBM copier drawn by Gary E. Graham for the parts manual. The components are in black, the numerical labels and the lines from label to part are in muted red. The diagram is too detailed to scan and reprint here; the vast number of parts was why the “rubrication” of part numbers was so helpful to the reader, who was able to see all the parts, and their relationship to one another in the copier, in a single figure that simultaneously allowed him to look up the parts in the numerical key. Fig. 2.27 is a less cluttered example of a “rubricated” diagram. When color is not an option, greyscale shading may be satisfactory. However, the shading needs to be light so that it will not drown the text and data curves even if the grey prints darker than it appeared on the computer screen.
2.6. LAYERING, SEPARATION AND RUBRICATION
65
“Separation” may also be physical proximity. Fig. 2.28 shows good and bad ways to label a curve. The most fundamental mistake is to put the label so far from the curve that the reader becomes confused about what element the label is supposed to identify. The middle two boxes are mildly deprecated. It is more difficult and slower to read curve-following text than horizontal letters. We are all used to the convention that labels go above the thing which is labelled — note that the title of a graph always goes on top, for example — and we should follow this convention wherever possible. The middle two panels have been identified as only “semi-bad” because when a graph is crowded with labels, one may be forced to make the text follow the curve so that the text will be unamiguously associated with the curve; similarly, one sometimes must put the label below the curve because there is simply no room to fit it above. The rightmost option is best. The goal of a label is be as little separate as possible from the curve it identifies because label-and-curve are really a single, logical element.
o her n
Acheron
Ac
Acheron
Acheron
Bad
Semi-Bad Semi-Bad
Good
Figure 2.28: Good and bad line labels. The really bad example at far left is too far from the line it labels. The example that is second from the left is clear, but the curve-following type is harder to reader than a horizontal word. The label in the next box is below the line it labels; this is harder to read, and easier to misread, than a label which is above the curve. The rightmost example is good because it is close, horizontal, and above the curve it labels. Imitation of a figure by Eduard Imhof, reprinted in Tufte(1990), pg. 62.
66
2.7
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Word-Labels Are Better Than Letter-Labels
Another general theme emphasized by Tufte and others: make labels as clear and explicit on the graph itself. For very complicated figures, it may be necessary to use a legend box or to provide a verbal key to the lines (solid: gold, dashed: silver, dotted: brass, etc.) in the caption. However, as much as possible, one write out labels as whole words or numbers. Fig. 2.29 shows two versions of the same diagram. The left illustration is incomprehensible as it stands because the parts of the ear have been labelled with letters which are meaningless in the absence of a key or letter box. The figure on the right conveys much more meaning in the graph itself because the labels are the actual names of the parts. The left version of the graph forces “tennis spectator syndrome” on the reader, forcing the eyes to go back-and-forth, back-and-forth between caption and drawing.
Figure 2.29: Letter-labels (left), which can be only interpreted by turning from the graph to a key in the caption or a legend box, are inferior to word-labels (right), which can be understood without taking one’s eyes off the figure.
2.8. COLLAPSING A DIMENSION OR ESCAPING FLATLAND
2.8
67
Collapsing a Dimension or Escaping Flatland
In elementary particle physics, string theory asserts that the three-dimensionality of the universe is a mirage. Rather, there are at least ten dimensions, but the extra dimensions are “compactified”, that is, curled up on a microscopic scale so as to have no visible role. Sometimes a similar compactification or collapsing of dimensions is equally fundamental to good graphics on two-dimensional paper. Fig. 2.30 employs a convention popular in biological illustration: one coordinate, time, is overlaid on a spatial coordinate so that left-to-right in space also conveys a sense of time. The vertical lines, each labeled with a month, provide a minimal framing that makes this diagram a multipanel animation-on-a-page. However, the framing is so muted that the diagram is also perceived by the eye as a single figure rather than a composite. Taken this way, as a whole, this diagram of the life-cyle of the Japanese beetle is physically unrealizable as a portrait of an adult human talking to himself as a small child. And yet, because the passing months are clearly labeled at the top, this life-cycle diagram is not confusing. The conversion of time to space, graphically speaking, has made it possible to mute the frame to vertical dividing lines only.
Figure 2.30: The annual life cycle of the Japanese beetle. Original from L. Hugh Newman, Man and Insects, (London, 1965), pg. 104-105.
68
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Fig. 2.31 illustrates the motion of sunspots across the face of the sun. The horizontal coordinate is used in its usual role in the sense that the sunspots really do move, and the location of each icon of a sunspot depicts its actual spatial location on a given day. Because many such icons for many different days are superimposed on a single solar disk and also because each icon shows the time-varying shape of the sunspot, space is also serving as a proxy for time; following the images across the sun, one sees the life cycle of the sunspot. The vertical dividing lines of the Japanese beetle life cycle have disappeared; Scheiner’s sunspot diagram is a multipanel animation-on-a-page in which the framing of individual panels has completely disappeared. The odd-looking disks at top and bottom are symbols of Scheiner’s religious order and financial patron. Three centuries before television, it was still necessary to say, metaphorically, “and now a word from our sponsor”. The hunt for research funds took up much of a scientist’s time even in the Renaissance. Tufte, who reprints this figure, is rather scornful of the appearance of extraneous symbols on the graph. However, many federal agencies and industrial companies require that the agency or company logo appear on every slide or transparency of conference presentations. Fortunately, journal editors have usually been successful in banishing such unabashed advertising from their pages.
2.8. COLLAPSING A DIMENSION OR ESCAPING FLATLAND
69
Figure 2.31: From Christopher Scheiner, Rosa Ursina sive Sol (Bracciani, 1626-1630). The disk-shaped symbols at top and bottom are the emblems of Scheiner’s religious order and patron.
70
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Using space as a substitute for time is not the only strategy for “compactifying dimensions”. Another is to ignore irrelevant dimensions. Fig. 2.32 is a plot of sunspot activity as a function of latitude and time. Maunder simply ignored longitude to make a very powerful diagram. As the sun goes through an eleven year cycle, the band of latitude spanned by sunspots moves towards the equator. One could express this as an ordinary line graph by compactifying latitude, too, by plotting the centroid of sunspot positions. However, Maunder’s graph is superior because it presents an additional theme which would be lost in an average-latitude-versus-time plot: the number of sunspots abruptsly drops to almost nothing when the sunspots have moved closest to the equator. During a significant part of the cycle (a couple of years), there is almost no sunspot activity at all. Does this matter? Maunder’s major scientific achievement was to show that the period known as the “Little Ice Age” coincided with a major drought of sunspot activity now known as the “Maunder minimum”. How does one know that ignoring one dimension is okay, but compactifying a second dimension erases the most important part of the signal? Experience helps; Maunder spent much of his life studying sunspots. In research, though, experience can be misleading: in Werner von Braun’s amusing quote, “Research is what you do when you don’t know what you’re doing.” The reason message is: Experiment. Plot the data in several different forms, and publish an illuminating subset of the graphs. There is an old joke about prolific authors: “He was determined to never have an unpublished thought.” Some scientists, especially graduate students, approach visualization in the same spirit: Every graph of the previous five years is reproduced in the thesis.
2.8. COLLAPSING A DIMENSION OR ESCAPING FLATLAND
71
Figure 2.32: The vertical line segments denote the latitudinal extent of sunspots as observed versus time, which is the horizontal axis. Two space dimensions are collapsed into one by ignoring the longitudinal position and width of the sunspots. Note that Maunder has increased the “data-ink” ratio by restricting the latitudinal range to ±40o ; there is only negligible sunspot at higher latitudes, so expanding the vertical axis would have added nothing. From E. W. Maunder, “Notes on the Distribution of Sun-Spots in Heliographic Latitude, 1874-1902,” Royal Astronomical Society Monthly Notices, 64, 747-761 (1904).
72
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Fig. 2.33 is an improved modern version of Maunder’s diagram. One improvement is that it uses a timeline five times as long and a higher density of data. Another improvement is that a line graph has been added in parallel underneath the “butterfly” plot to show how an overall measure of sunspot activity — the area covered by sunspots — varies with time. The lower graph is important because it shows that there are considerable differences from one sunspot cycle to the next. And yet, the steady fluttering of the pattern of “butterfly wings” in the top diagram shows that great similarities from one cycle to the next also.
Figure 2.33: Updated version of Maunder’s “butterfly” diagram of sunspot activity, so-called because the plot of the latitudinal extent of sunspots versus time traces a shape reminiscent of the wings of butterfly over the course of the 11-year sunspot cycle. The lower graph shows the percentage of the solar surface covered by sunspots as a function of time. Diagram by David H. Hathaway, Marshall Space Flight Center, NASA.
2.9. SUPPLEMENTARY MATERIAL
2.9 2.9.1
73
Supplementary Material Small Multiples or Animations-on-a-Page
Fig. 2.34 is another example of a “small multiple”. The parameter which increases from one frame to the next is not time, but rather the number of terms retained in a truncated power series. The number of oscillations jumps by one by with increase in the truncation k, so it is not possible, even in principle, to smoothly animate this sequence. Nevertheless, Gibbs’ Phenonomen is mostly easily described by an animation-like sequence of graphs. One good feature of this graph is that the frames are all shown in a single row with identical format, making comparisons easy. Another good feature is that the important features, the horizontal and vertical position of the peak which is nearest to the discontinuity, are marked with arrows and numerical labels. It would normally be bad practice to use numerical labels that extend to six decimal places. However, this is necessary here to show that the location of the peak and its height are both converging to precise values, predicted by Gibbs’ analytical theory, as k → ∞. The six graphs are given very limited framing; a bottom line plus a horizontal line on the right which is split into two discontinuous segments with a lot of blank space between. One might dub this “3/8” framing. Tufte would approve!
74
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Figure 2.34: An illustration of Gibbs’ Phenomenon, which is the non-uniform convergence of a Fourier series to a function with a discontinuity. The integer k, which increases by powers of 2 from one frame to the next, rightward, is the number of terms in the truncation of the Fourier series, which is shown as the solid curve. The piecewise constant function which is being approximated by the Fourier series is shown as the dashed line. (It jumps from 1 to -1 at x = π.) Because the error is large only near the endpoint x = π where the discontinuity is located, the graph does not show the whole interval x ∈ [−π, π], but only one-quarter of this interval, x ∈ [π/2, π]. Similarly, although the range of the function is [−1, 1], only the vertical range above 0.5 is illustrated. The upper labels and arrow in each frame point to the maxima of the truncated series; the message is that it moves closer and closer to discontinuity, proportional to 1/k. The lower label and horizontal arrow indicate that the maxima of the series converges to an overshoot of 0.0895, as asserted through analytical arguments by Gibbs at the turn of the century. The only unsound aspect of the graph is that horizontal distances (top labels) are measured in fractions of grid width instead of the actual distances, which are π/2 larger, or fractions of the expansion interval, which would give numbers four times smaller. From Integral Transforms in Science and Engineering by Kurt Bernardo Wolf, Plenum Press, New York, pg. 167, (1979).
2.9. SUPPLEMENTARY MATERIAL
2.9.2
75
Separation: Inset Graphs
Fig. 2.35 shows a skillful use of inset graphs. Each of the two cases is shown in two ways. The larger graph illustrates the spatial structure u(x, t) at a particular time t. The inset graph shows the Fourier transform of u(x, t). These two cases could have been compared as a four-panel composite graph. However, the reader would have to look carefully to see which graph goes with what. Usually, the two graphs of a single case are shown side-by-side, but this convention is not always followed, and the reader has to examine the caption carefully to confirm that convention has been followed. Even when this has been done, the reader must figure out: are both graphs of the same function, or of different quantities for the same case? The use of the large graph/inset graph visual format ties the two graphs of a given case more closely together. The graphic proximity reflects the intellectual closeness: both graphs are different representations, one in physical space and the other in Fourier transform space, of the same function. The two cases are separated in space to reflect a greater distance in the mind.
76
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Figure 2.35: An exemplar of inset graphs. The upper pair of figures illustrate the solitary wave of the so-called “Benjamin-Davis-Ono” equation; the lower pair show the effects of radiative damping on these waves. The inset graphs show the Fourier transforms; the larger graphs show the waves in space. From Pereira and Redekopp(1980).
2.10. WIDE IS WONDERFUL: AESTHETICS OF ASPECT RATIO
2.10
77
Wide is Wonderful: Aesthetics of Aspect Ratio
Definition 5 (External Aspect Ratio of a Graph) The “external aspect ratio” of a graph is the ratio of its width to its height as it appears on the printed page: RE ≡ width on page/height on page
(2.5)
It is often impractical to control the external aspect ratio of a figure, either because of software limitations or to avoid geometric distortion. (A square, two-dimensional domain is best graphed as a square on the printed page, or the image will distort the true geometry.) When it is possible to design the aspect ratio, most designers include Tufte recommend RE ≈ 1.5 to 1.6
↔
width ≈ (3/2)height
(2.6)
There are several reasons why this is desirable. The first is the human visual system. Up-and-down was a lot less dangerous than leftand-right; few humans have been mugged by an earthworm. While the occasional very bold hawk may have dive-bombed homo africanus, lions and tigers and bears, oh, my! So, millions of years of evolution have created a human visual system that has broader vision to the sides than to the top and bottom. Movie makers recognized this a long time ago, which is why cinema screens are wider than they are tall. Because of the limitations of early technology, TV screens have been almost square. As a result, it is difficult to show movies on TV; some movie channels show the film in “letterbox” format in which strips at the top and bottom of the TV screen are blank while in the center, the image is shown in its original aspect ratio of about 1.5. High definition TV, which will be coming very soon, has adopted a movie-like aspect ratio. The new TVs will look very queer because of their wide screens, but they will be much more comfortable to watch, and not only because of higher pixel density. The second reason that wider-is-better is that Latex software, at least in the absence of non-standard style files, is unable to wrap text around illustrations. It does have the flexibility to choose the print width of a figure through an optional “width=” statement in the figure command. If one chooses to print a graph of square shape at a width of 3 inches in a text column that is 5.5 inches wide, then almost half the width of the column will be wasted white space. If one blows up the figure to fill the full width of the text, then it will necessarily be 5.5 inches high. Given that the page must also accomodate header, footer, page number, top and bottom margins and the figure caption, such a figure will necessarily appear on a page devoid or almost devoid of text. If, on the other hand, a graph is wider than tall, a figure 5.5 inches wide will be perhaps only 3 inches tall. It can then comfortably share the page with the text that describes it. Lastly, wide figures make it easier to provide full-word (or even full-sentence) horizontal labels for the data-curves. So, remember: whenever possible, try to be as smart as your (twenty-first century) TV set!
78
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Wasted Whitespace
Same aspect ratio as High Definition TV
Figure 2.34: Schematic depiction of the advantages of graphs that are wider than tall. The wavy lines represent the main text. A square figure leaves a lot of blank space on either side of itself; a wider-than-tall figure of the same height fills the entire column. The wider figure also matches better with the intrinsic aspect ratio of the human visual system. For this reason, wider-than-tall is standard in the movies and will become standard for TV in the twenty-first century.
2.11. COLOR OR WHY THE RAINBOW ISN’T GOLDEN
2.11
79
Color or Why the Rainbow Isn’t Golden
Color is one of the powerful tools in visualization. Unfortunately, it is also one of the easiest to misuse.
Figure 2.35: Terrible use of color; the coastal waters are a band of white so bright it seems to shimmer. The colors on land depict primary home heating fuel — the meaning of the colors is presumbably explained somewhere in the original text — in 1970. From a publication GE-70 of the U. S. Bureau of the Census. Reprinted in Tufte(1990), pg. 82 Fig. 2.35 illustrates one peril: color can easily emphasize the wrong elements through sheer inadvertence. The intellectual content of the graph is displayed as the little blobs of green, blue, tan and yellow on the land masses. However, the land is surrounded by a great ribbon of white which is so bright that it is far and away the most dramatic, eye-catching part of the graph. This would be good if the graph was supposed to illustrate U. S. territorial waters, whose width is roughly that of the ribbons. Unfortunately, the point of the graph is completely different. Fine art and interior decorating tend to use rather muted colors; cartoons, posters and crayons use very bright, solid colors. Computers tend to be rather poster-like; subtle colors are difficult to do well because the screen display is RGB, based on additive colors, whereas printers use the CMYK subtractive system, which makes it very challenging to print the screen image exactly. An even more fundamental reason is that the default set of colors in graphing software is limited to bright, primary colors. In Matlab, ‘r’ is for bright red, not a subtle lavender pink. The default palette is made of the same shades as a child’s box of crayons. Indeed,
80
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Figure 2.36: A map of the Sea of Japan that uses a “full box of crayons” as shown in the colorbar below (next figure). All the essential information is included, but the bright colors make the map hard to read. One must stare long and hard at the colorbar to recognize that bright yellow is a depth range only slightly smaller than light green. many color printers dissolve the dyes in wax, and thus are drawing in wax just like a crayon. With crayon colors, it is very easy for computer graphs to shriek “Look at me! Look at me!” Unfortunately, the loudest shriek is often for something completely irrelevant or even imaginary, like the “ivory moat” around the continents and islands in Fig. 2.35. In most aspects of graphics, it is desirable to use as many weapons as possible — as many marker shapes, as many linestyles, as many linewidths, as many colors. However, using the full range of bright crayon colors can be a mistake. In Fig. 2.36, a rainbow assortment of colors is unsatisfactory. The bright colors in the ocean make it difficult to distinguish the land from the sea. The depth of the ocean changes continuously, but the color leaps discontinuously from bright yellow to light green, then jumps again to dark green, then again to very dark green. One is forced to constantly to refer the legend because there is nothing natural to the colorcode: Is it em obvious that yellow is a depth of 1000 meters to 1250 meters?
Figure 2.37: Colorbar for the preceding map.
2.11. COLOR OR WHY THE RAINBOW ISN’T GOLDEN
81
Fig. 2.38 shows the same area, but with a palette which is restricted to shades of blue for the ocean and shades of brown for land. It is now easy to see what is land and what is ocean. There is a natural coding of ocean depth because the deepest sea is very dark blue and the near-surface waters are very pale blue. Even without checking the colorbar, one has an approximate idea of what depth is associated with a given color: middle blue is mid-depth. In addition, the pale tints of the most of the diagram make it much easier to read the labels — Yamato Basin, etc. This is important because a good map is a pattern of labels. It is much easier refer to high turbulence activity in the Yamato Basin than in a “patch of pale blue just to the west of the big brown mass”!
Figure 2.38: The same land-sea bathymetry map of the same region (Sea of Japan) as the previous map, but with a restricted range of colors. Leaving most crayon-colors in the box has created a much more readable map that employs only shades of blue and brown.
Figure 2.39: Colorbar for the previous figure.
82
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Similar considerations apply to other species of three-dimensional graphs. Hanselman and Littlefield, Mastering Matlab 5, assert that surface plots with exterior lighting — surfl in Matlab — “look better in a single color” (pg. 345). Fig. 2.40 illustrates what they mean. When a surface plot is displayed using a colormap with rapidly varying, multiple colors, the result is both ugly and confusing (Fig. 2.41).
surfl(peaks) with colormap "gray"
5 0 -5
2 2
0
0 -2
-2
Figure 2.40: A surface plot with lighting (Matlab surfl) of the Matlab “peaks” function. With colormap “gray”, which is only a single color, the lighting is effective.
2.11. COLOR OR WHY THE RAINBOW ISN’T GOLDEN
83
surfl(peaks) with colormap "prism"
5 0 -5
2 2
0
0 -2
-2
Figure 2.41: Same as previous figure but with colormap “prism”. Note that surfl has the odd feature that the colormapping is turned sideways to match the exterior lighting so that the “highlights” correspond to the colors at the top of the colormap rather than the highest elevations on the surface. The reason for this oddity is that effect of exterior level would be overwhelmed by the color scheme if the usual height=color coding was employed.
84
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
However, the stricture to leave most of the crayon-colors in the box must be interpreted to varying degrees for different species of graphs. Fig. 2.42 shows the same function as in the previous surface plots, but this graphed as pseudocolor image, which is the Matlab pcolor command. The multicolored map creates a confusing image (“prism” map). However, the two monochrome images at the top are rather bland and uninformative, too. The best image (lower right) uses the “jet” map, which uses only shades of two colors. This is the same color philosophy as the good map of the Sea of Japan. One color, in various shades, is used for heights above zero — brown in the bathymetric map, red in the pseudocolor plot with the “jet” colormap. The second color is used for negative heights — blue in both images. The two color schemes are effective in both examples because the color-coding seems natural and intuitive, even though it is artificial. In the topographic map, the association of brown with land and blue with water is obvious because much of the land is brown or tan and the water is blue. Similarly, the pseudocolor map is easier to absorb because we instinctively associate red with highs — highs of temperature as in the phrase “red-hot” — and blue with lows or with cool temperature. Even when the quantity which is plotted is not temperature, the mapping of red with high and blue with valleys seems very natural and therefore easily remembered. Furthermore, this red-high/blue-low mapping has been widely used in scientific pseudocolor maps. (Trust us on this!) When one has seen a dozen earlier plots that used the same convention, it becomes much easier to get past the colormap and into the data. A final comment: red-green color blindness affects 5% to 10% percent of the population. (Almost all victims are male). Therefore, a two-color scheme should avoid using red and green; red and blue are easier for the color-blind to distinguish. A rainbow palette of colors is almost certain to create problems for the color-blind.
2.11. COLOR OR WHY THE RAINBOW ISN’T GOLDEN
85
copper
gray
lines
jet
Figure 2.42: A pseudocolor map of the Matlab “peaks” function using four different Matlab colormaps. (Parenthetically, note that it is not possible to directly employ multiple colormaps in a single figure in Matlab. The workaround is to define a composite colormap which includes all four of the colormaps displayed: mycolormap = [jet(32);lines(32);gray(32);copper(32)];. One must then declare the color axis to have a range which is four times larger than the actual range of the “peaks” function: caxis([-32 32]);, and repeat this statement in each subplot. Finally, in each subplot, the “peaks” function with a shift was graphed: pcolor(X,Y,Z+24); and similarly with different shifts in the other subplots.)
86
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Unfortunately, monochrome and two-color schemes have a failing: there is some loss of precision as subtle shades blend into one another. A colormap that is punctuated by white bars like “prism” or “flag” shows the messiness of turbulent jet flows or other phenomena with a lot of small-scale structure more clearly than a two-color map. There is a trade-off between garishness and precision. One compromise is to superimpose contours on top of a pseudocolor map. When there are a lot of contours, the result is usually called a “filled contour plot”, and there is a command in Matlab, contourf, specifically to do this (Fig. 2.43).
Contourf 8
6
4
2
0
-2
-4
-6
-8
Figure 2.43: Note that in Matlab, interpolated shading (shading interp) is not allowed in filled contour plot; the space between each pair of contours is always filled with a single shade.
2.11. COLOR OR WHY THE RAINBOW ISN’T GOLDEN
87
Sometimes, one only needs a single explicit contour such as the zeroline. There is a good way and a bad way to add this contour. The bad way is to modify a standard colormap so as to change a single level to black or white. As shown in Fig. 2.44, the problem with this strategy is that wide regions where the peaks have decayed to near-zero values are turned into a sea of white. The rub is that each level of a standard colormap is a color assigned to a range of values equal to 1/64 of the range of values spanned by the colors. Visually, the pseudocolor map is dominated by the white seas where the function is boringly flat. Fig. 2.45 illustrates a better way, which is to superimpose a contour plot that has been instructed to graph just a single contour.
Colormap=jet+blackline-at-zero 8
6
4
2
0
-2
-4
-6
-8
Figure 2.44: Created by the Matlab commands blackline=jet(64); line(32,:)=[0.99 0.99 0.99]; colormap(blackline)
black-
88
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Colormap=jet; hold on; contour(X,Y,Z,[0 0],k) 8
6
4
2
0
-2
-4
-6
-8
Figure 2.45: Created in Matlab by first making a standard pseudocolor map using the builtin colormap “jet”. After the hold command, the statement contour(X,Y,Z,[0 0],’k’) will superimpose a single contour line where the plotted function is equal to zero.
2.12. PARALLELISM
2.12
89
Parallelism
When multiple images are combined in parallel, the message is easier to grasp because the axes, format and so on are constant and only the data varies. Parallelism is closely related to “small multiples” and “animations-on-a-page”. In the most favorable cases, the parallelism implicit in these concepts can be translated into explicit geometry. In the late 60’s, Stephen Dole of the Rand Corporation combined all that was then known of solar system formation into a computer model. It was thought then, and still believed now, that chance plays a fairly large role in the number and size of the planets as well as non-stochastic parameters such as the total mass of the parent star and the planetary nebula. Dole’s model therefore generated ensembles of solar systems. Fig. 2.46 illustrates a subset of his ensemble of imaginary solar systems compared with our own real system at the bottom. The size of the disks represents the mass of the planets, but the labels give the numerical values — good since it is hard for humans to accurately estimate area. Because each system is laid out on a single line, and the lines are all parallel, it is easy to visually compare different systems.
90
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
Figure 2.46: From Habitable Planets for Man by Stephen Dole, Elsevier, New York (1970).
2.12. PARALLELISM
91
Fig. 2.47 shows a similar vertical stack of plots which are different variables associated with a single model flow. Although the aspect ratio of such plots is greater than the value recommended earlier — each graph is perhaps three times as wide as tall — this does not seem bothersome when such elongated rectangles are arrayed one atop the other. Because the plots are wide, it is easy to label them with horizontally-written text. It is possible to stack plots that are very tall and narrow side-by-side, and sometimes this is useful to facilitate comparisons between the ordinates. However, it is harder to use a side-by-side orientation successfully because there is less room for horizontal labels. In either event, a good strategy for transmitting ideas that are conceptually parallel is through a plot which is parallel in layout, too.
Temperature
Density
Pressure
North-south Velocity
East-west Velocity
Figure 2.47: Five vertically-stacked plots for different variables of a single case study, all sharing a common horizontal axis.
92
CHAPTER 2. THE GOSPEL ACCORDING TO TUFTE
2.13
The Friendly Graphic Table 2.3: The Friendly Data Graphic, pg. 183 of Tufte(1983) Friendly words are spelled out, mysterious and elaborate encoding avoided
Unfriendly abbreviations abound, requiring the viewer to sort through text to decode abbreviations
words run from left to right, the usual direction for reading occidental languagues
words run vertically, particularly along the Y-axis; words run in several different directions
little messages help explain data
graphic is cryptic, requires repeated references to scattered text
elaborately encoded shadings, cross-hatching, and colors are avoided; instead, labels are placed on the graphic itself; no legend is required
obscure codings require going back and forth between legend and graphic
graphic attracts viewer, provokes curiosity
graphic is repellent, filled with chartjunk
colors, if used, are chosen so that the color-deficient and color-blind (5 to 10 percent of viewers) can make sense of the graphic (blue can be distinguished from other colors by most color-deficient people)
design insensitive to color-deficient viewers; red and green used for essential contrasts
type is clear, precise, modest; lettering may be done by hand
type is clotted, overbearing
type is upper-and-lower case, with serifs
type is all capitals, sans serif
Chapter 3
Axis Magic 3.1
Introduction
In a sense, the only function that the human mind really understands well is a straight line. One good strategy for making a graph easy to understand is to make it as linear as possible. If u(x), the function to be graphed, is thought to resemble a function µ(x), then graph µ−1 (u(x)). The graph of the inverse of µ of u will be approximately linear. This is a very general strategy because it can be applied with very general “model” functions µ. For example, if u resembles the exponential function, then plotting the inverse is then graphing log(u) instead of u. For this special case, most libraries offer the option of plotting u but on a logarithmic y − axis. This is mathematically equivalent to graphing log(u). However, a log-scale has the important practical advantage that the graphing software will automatically label the axis with numbers and tickmarks appropriate for u. If we plotted log(u) using a linear scale, then the tickmarks and numerical labels would be those for log(u) rather than u, and these are usually harder to interpret. It is usually not possible to make a curve exactly linear. Furthermore, if the model µ is a very complicated function, it may not be very insightful to make a plot of µ−1 (u) — the curve may be a straight line, but what does this mean if µ is a confluent hypergeometric function? However, it is very common for a function u to have a simple asymptotic shape for some range of x. A plot can then easily confirm and display this asymptotic behavior. For example, suppose u = sin(5x) exp(−x2 ) + exp(−x)
(3.1)
The graph of this function on x ∈ [0, 100] is rather wiggly because of the sine functions. However, the sinusoidal factor decays rapidly for large x so that u ∼ exp(−x),
x >> 1
(3.2)
If we plot u using a logarithmic scale for u, then u will asymptote to a linear function. It follows that the choice of a nonlinear scale has made at least part of the range in x easy to understand.
3.2
Squeezing the Axis
Another motive for using nonlinear axes is that it may be difficult to fit the desired range into the desired space. Two amusing examples are illustrated as Figs. 3.1 and 3.2. The tip 95
96
CHAPTER 3. AXIS MAGIC
of the curve in Playfair’s graph is repeated at the bottom of the graph as well as extending beyond the frame at the top. This eccentric procedure is distracting and requires some effort to decode. The advantage is that emphasizes the sharp rise in the plotted quantity; it has increased so much that it is difficult to show the peak on the same scale as earlier years.
1.7 Million
1.4
War
War
War
1.2 1 Million 0.8 0.6 0.4 0.2
Expense of Ordnance Figure 3.1: A time series of military expenditure versus year in the late eighteenth century. The short horizontal bars mark periods of war when (unsurprisingly!) military costs rose rapidly. Drawn by J. Boyd after an original by William Playfair, published in his Commercial and Political Atlas, (London, 1786), plate 14.
3.2. SQUEEZING THE AXIS
97
Similarly, in the second figure in which the river-length is depicted by horizontal length, the segments for two very long rivers are simply curled around like giant snakes. The disadvantage of this wrap-around is that it is almost impossible to accurately compare the lengths of the wrapped-around rivers with the others. And yet the graph is not a failure; the need to plot two rivers wierdly emphasizes that these rivers are very, very long compared to the rest. Graphing software is bad at this kind of creativity, which usually must be drawn rather than plotted. A logarithmic scale needs no drawing. However, a logarithmic scale, too, makes demands of the reader.
Figure 3.2: Rivers of North America and their lengths in meters. Instead of conventional bars, the wiggly lines attempt to depict the shape each river would have if replaced by a ribbon of rubber which was then straightened out. From Jean Buchon, Atlas Geographique, Statistique, Historique, et Chronologique des Deux Ameriques (Paris, 1825), no. LXIII.
98
CHAPTER 3. AXIS MAGIC
3.3
Log, Log-Log and All That
Definition 6 (Linear-Linear Scale) A plot is said to be a linear plot or have a linearlinear scale if it is a graph of u versus x. Definition 7 (Nonlinear Scale/Nonlinear Ordinate) A plot is said to have a nonlinear y-scale or nonlinear ordinate if it is a plot of µ(u) versus x where µ is a nonlinear function of its argument. Definition 8 (Log-Linear Plot) A plot is said to be a log-linear plot if it is a graph of log(u) versus x. Definition 9 (Log-Log Plot) A plot is said to be a log-log plot if it is a graph of log(u) versus log(x). A logarithmic scale has two advantages: • Much wider range for the plotted variable • Exponential growth or decay, geometric progression and power-law behavior can all be linearized, that is, rendered as a straight line, by using the appropriate type of log or log-log plot. Example One: Log-in-y/Linear-in-x for Chebyshev Coefficients Chebyshev spectral methods have the property that if the solution is smooth on the domain of integration, the coefficients of the Chebyshev series for the solution of a differential equation will decrease exponentially fast with degree. That is, if the coefficients of the spectral series are denoted by aj , then the coefficients should decrease like aj ∼ {} exp(−q j),
j → ∞
(3.3)
where the empty braces denotes factors that vary more slowly with j than the exponential, such as a power of j, and where q is a positive constant that depends on the specific problem. In using spectral algorithms to solve differential equations, it is sound practice to periodically check the coefficients to confirm the predicted behavior. (In aviation, the equivalent proverb is: “Even when flying on instruments, look out the window occasionally.”) Fig. 3.3 shows two graphs of the spectral coefficients, identical except that one employs a logarithmic scale and the other does not. The linear-linear plot is a disaster: most of the data is invisible! The log-log plot has two virtues. First, all the coefficients are plotted, even the very tiny ones. This is the advantage of a wide range noted earlier. Second, the coefficients asymptote to a straight line as the degree j increases. This is consistent with the predicted exponential behavior: exp(−qj) would plot as a straight line with a logarithmic scale.
3.3. LOG, LOG-LOG AND ALL THAT
99
LINEAR-linear
LOG-linear 1.4
0
Absolute value of spectral coefficients
10
1.2 -2
10
1 -4
10
0.8 0.6
-6
10
0.4 -8
10
0.2 -10
10
0
20 40 degree j
60
0 0
20 40 degree j
60
Figure 3.3: Both graphs illustrate aj for the rational Chebyshev series for the unstable mode of a hydrodynamic instability problem. The linear-linear plot (right) conveys little information; most of the spectral coefficients are so small as to be invisible. When the ordinate scale is logarithmic, (left panel), all the coefficients are visible. Furthermore, the coefficients are approximately linear for large degree which confirms the expected asymptotic exponential decay. [Boussinesq-Charney eigenproblem of meteorology for r = 1/2.]
100
CHAPTER 3. AXIS MAGIC
EXAMPLE TWO: Check of Asymptotic Series Many functions have asympotic series in negative powers of z which become increasingly accurate for a given number of terms as z increases. The accuracy of such series can be checked against accurate, independent numerical solutions by plotting the errors on a log-log graph. The absolute error in a k-th order asymptotic approximation should decrease as Ek ∼ q z −k
(3.4)
where q is a positive constant. Taking the logarithm of both sides of this asymptotic relation gives log {Ek } ∼ log(q) − log(z)
(3.5)
which is a straight line with a slope equal to negative k on a log-log plot. If several different orders of approximation are plotted on a single log-log graph, the errors should not only decrease with increasing z; the errors should asymptote to a straight line. In addition, the slopes should steadily increase with increasing order.
Errors in Asymptotic Series for Confluent U-function 0
Absolute value of Errors
10
-1
10
-2
First O rder
-3
2d O
10
rder
10
3rd
Ord
er
-4
10
4th
-5
10
0
Or
de r 1
10
10 z
Figure 3.4: The error in asymptotic approximations of first, second, 3rd and 4th orders versus z is plotted. [Confluent hypergeometric function U (1/2, 2, z). the errors are proportional to the first, second, third, and fourth powers of the reciprocal of |z|. ] On a log-log plot, the errors should therefore asymptote to a straight line whose slope steepens with increasing order. If this pattern is not found, then it screams “ERROR”!]
3.4. PROBABILITY, ARCTANH AND ARCSINH SCALES
3.4
101
Probability, Arctanh and Arcsinh Scales
Fig. 3.5 shows two representations of the same function. The nonlinear scale for the right graph is the “probability function” (more precisely, the “cumulative normal frequency curve”). The probability function itself itself is linearized by this nonlinear scale. The crucial point is that real-word statistical samples will also be approximately linearized if their distribution is “normal”. The deviation of the curve from from a straight line, when plotted with the “probability” scale, provides a visual test of statistical normality.
Figure 3.5: Two representations of the same curve (solid), the cumulative normal frequency curve. Left: this function graphed with the usual linear scales (labeled “arithmetic”). Right: same function plotted on “probability paper”, which converts this curve into a straight line. From Schmid(1954), A Handbook of Graphic Presentation.
102
CHAPTER 3. AXIS MAGIC
Figure 3.6: The raw data is S-shaped. By using a novel axis (inverse of the “cumulated normal probability curve” or “ogive”), the plotted points are almost linearized where the deviation from linearity illustrates the deviation from the standard probabilistic distribution. From Arkin and Colton(1936), who acknowledge W. A. Shewhart, “Economic Control of Quantity of Production”; the data is the depth of sapwood in a sample of 1370 telephone poles. Fig. 3.6 is an example. The near-linearity of the data curve shows that the depth of sapwood for this sample of telephone poles is, statistically speaking, close to normal. We plotted a curve, and instead obtained a theory! It would be much more difficult to see the closeness to normality if the data had been plotted on a linear ordinate scale.
3.4. PROBABILITY, ARCTANH AND ARCSINH SCALES
103
Other nonlinear scales are useful. The error function erf(x) is a “tanh-like” function in the sense that it is antisymmetric with respect to x = 0 and varies monotonically between -1 and 1. One way to see how closely these two functions resemble each other is to plot the error function using an arctanh scale. That is to say, we plot arctanh(erf)(x) rather than the error function itself. However, the vertical axis is labelled with the values of the error function rather than of its arctanh as illustrated in Fig. 3.7.
Erf function with arctanh axis 0.9999
0.9999
0.999
0.999
0.99
0.99
0.9 0.7 0.3 -0.3 -0.7 -0.9
0.9 0.7 0.3 -0.3 -0.7 -0.9
-0.99
-0.99
-0.999
-0.999
-0.9999
-0.9999 -3
-2
-1
0 x
1
2
3
Figure 3.7: A graph of the error function using an arctanh scale. That is, the graph is arctanh(erf)(x) versus x, but the labels give the values of erf, which range between -1 and 1, rather than those of its arctanh. The dotted line shows the graph of tanh(x) on the same scale for reference. To compute a function u which is growing exponentially for large |x|, the obvious choice is to use a logarithmic scale. However, if u < 0, then the logarithm is complex-valued unless we plot the negative of u. If u is of both signs, then a logarithmic scale will fail unless we plot the absolute value of u. However, this has two disadvantages. First, there is no simple way to show the sign of u on the plot. (One remedy: split the curve into segments where u is of one-signed and plot each separately,using solid line for segments where u > 0 and dashed lines for segments where u is negative.) Second, log(|u|) runs off to negative infinity at each zero of u.
104
CHAPTER 3. AXIS MAGIC
A more direct alternative is to plot the function using an arcsinh scale. This scale has no difficult with sign changes. In addition, the arcsinh of a very large number is a moderate number so that, like a logarithmic scale, the arcsinh scale can accomodate a huge range. An example is shown in Fig. 3.8.
Arcsinh axis 100 50 20 10 5 2 1 0 -1 -2 -5 -10 -20 -50 -100
100 50 20 10 5 2 1 0 -1 -2 -5 -10 -20 -50 -100 -6
-4
-2
0 x
2
4
6
Figure 3.8: A graph of a function f (x) on an arcsinh scale. The vertical location of each point is that of arcsinh(f)(xj ), but the labels are the values of f (xj ) itself. The function f was chosen arbitrarily to be f = {1 + 0.7 cos(x)} sinh(x) + 10erf(x).
3.5. MONETARY INFLATION
3.5
105
Monetary Inflation
Comparing costs and salaries for different years is difficult because of inflation, which is defined to be the change in the price of a fixed item, averaged over many categories of items. The Consumer Price Index (C. P. I.), which defined the inflation rates employed in Fig. 3.9, is a number published annually by the U. S. goverment to estimate inflation as felt by the average person. (The inflation rates for individual sectors of the economy, such as real estate or energy, may be considerably different from the C. P. I.) Thus, a salary that rises at 4% a year may not actually produce any increase in a person’s standard of living because the cost of housing, food, automobile, taxes and so on have risen at the same rate. Fig. 3.9, devised by Robert Sherman, employs unusual axes to compensate. The horizontal axes are slanted downward at a rate proportional to the C. P. I. A salary of $30,000 should be plotted on the slanting line beginning at “3” on the left axis; the horizontal location of the point is given by the year. One can then convert this into the dollars that would buy the same amount of goods in 1969 by drawing a horizontal line from the plotted point to the left axis. Another way to use this graph: a salary which rises just fast enough to keep up with inflation will be a horizontal line on the graph: the absolute amounts rise just fast enough to compensate for the downward slant of the axes. This artifice of slanted axis lines is different from the nonlinear axis scales used in earlier sections: for logarithmic and arctanh graphs, the axis lines are always horizontal. No standard software package includes a routine to create slanted axis graphs, but it is not hard to modify existing Matlab routines to do this. A much simpler solution, of course, is to simply plot salary divided by an inflation factor. Indeed, this is the most common tactic because one can simultaneously plot two curves, one showing salary in absolute terms and another showing salary in constant 1969 dollars. Nevertheless, the slanted axis graph is useful as a reminder. In economics, it is probably much more sensible to compare quantities in different years after adjusting for inflation than without such an adjustment. We can reiterate too often that one of the most important choices in graphics is: What quantity should be plotted? The obvious answer (dollar amounts) is often a misleading answer (because inflation-corrected dollars more accurately reflect the purchasing power of money).
106
CHAPTER 3. AXIS MAGIC
Figure 3.9: Constant-dollar graph paper. The bottom axis specifies the year (from 19691982) in a linear scale. The vertical axis is dollars on logarithmic scale. The horizontal axis lines are given a downward slope which is proportional to the yearly inflation rate at that time. The lowest axis line which runs the full width of the graph conveys the information that $1000 in 1969 is equivalent to $3000 in 1982. A salary which rises at a rate to just match inflation will plot as a horizontal line on the graph. Devised by Robert Sherman and reprinted in Wainer(1997), pg. 123.
3.6. NOMOGRAPHY AND GRAPHICAL CALCULATORS
3.6
107
Nomography and Graphical Calculators
In the pre-computer days, and continuing into the mainframe period when computers were still huge and unwieldy, “nomography”, that is, graphs that could be used to calculate quantities, was a major part of engineering. Often, linear axes failed miserably for such graphs because the answer would be a tiny, flat wiggle, almost impossible to accurately translate into numbers. Therefore, nomographs and graphical calculators made heavy use of very ingenious scales. Crowhurst (1965), who wrote one of the last books on this topic, has many wildly nonlinear scales in his short book. Two of the more ingenious are displayed in Fig. 3.10. Nomography has diminished in importance because of the wide availability of computers and hand-held calculators. However, it has not completely disappeared. Crowhurst’s short book is a very readable description of the art. How does one interpret these axes from Crowhurst? The answer can only be obtained by really studying the graph. This is a disadvantage of nonlinear scales: they require an investment of study-time by the reader. This investment increases rapidly as the nonlinear scale/s become more exotic.
108
CHAPTER 3. AXIS MAGIC
Figure 3.10: Two sets of axes for “graphical calculators” from Crowhurst(1965), pg. 56.
Chapter 4
Contour (Isoline) Plots 4.1
Contour Plot
Definition 10 (Contour Plot) A two-dimensional plot which shows the one-dimensional curves on which the plotted quantity q is a constant. These curves are defined by q(x, y) = qj ,
j = 1, 2, . . . , Nc
(4.1)
where Nc is the number of contours that are plotted. These curves of constant q are known as the “contours” of q or as the “isolines” of q or as the “level surfaces” of q. Alternative Names: ISOLINE PLOT, LEVEL SURFACE PLOT Competitors: 1. Pseudocolor plot pcolor Much clearer in color than grayscale, but color is expensive 2. Mesh plot, alias “fishnet”, alias “wireframe” mesh Good for visualizing broad features, but inferior to contour plot for precision. 3. Surface plot surf, surfl Best in color or with high-resolution grayscale. Good for visualizing broad features, but inferior to contour plot for precision. 4. Surface plot with contour plot surfc Has the advantages of both surface and contour plots, but contour plot must be depicted with a slant and can be obscured by the surface plot above. 5. Filled contour plot (superimposed pseudocolor and contour map) contourf Much clearer in color than grayscale, but color is expensive 6. Three-dimensional contour plot contour3 Visually interesting, but the rings (closed contours) usually overlap, making the image sometimes difficult to decode. 7. Three-dimensional bar plot bar3 Most useful when (x, y) is defined only for discrete values. 8. Three-dimensional stem plot stem3 Good for data which is defined only for discrete values of (x, y). Fig. 4.1 shows a comparison between a standard contour plot and these alternatives. 109
110
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
Contour
Pseudocolor
Mesh
Surf
Surfc
Filled-Contour
Contour3
Stem3
Bar3
Figure 4.1: A comparison of a standard contour plot with alternatives. Name of the plot is given just above the graph.
4.2. THE CENTRAL PROBLEM OF CONTOUR PLOTS: CODING THE ISOLINES111
4.2
The Central Problem of Contour Plots: Coding the Isolines
To summarize, the central problem of the contour plot is that if the contour lines are not somehow labelled with additional text, color, or linestyle, it is not very informative. Fig. 4.2 is such a label-free/color-free/style-free plot. Try to answer the following questions: • How many peaks are there? • How many local minima are there? • Where are the regions of maximum slope? [Caution: the values of the contour lines need not be evenly spaced.] The answer is that these questions are unanswerable from this plot. Without isoline-coding, one cannot even distinguish the local highs from the lows. This plot is really quite useless. In later sections, we shall describe a variety of strategies
Unlabeled, Uncoded Contour Plot 3 2
y
1 0 -1 -2 -3 -3
-2
-1
0 x
1
2
Figure 4.2: Unlabelled (and therefore useless ) contour plot.
3
112
4.3
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
Solid Positive-Valued/Dashed Negative-Valued Contour Plot
In meteorology, it is customary to plot positive valued-contours as solid lines and isolines where qj < 0 as dashed lines. This convention is very useful because one can distinguish the hills from the valleys at a glance, which is very difficult when all isolines are plotted as solid lines. In meteorology, it is conventional to plot the letter “H” at the maximum of a function and “L” at the minimum. NCAR Graphics, a FORTRAN library developed for atmospheric applications, offers this as an automatic option. The H/L labels can be added in Matlab by (i) calculating the maximum of the array of grid point values of the function which is being contoured, which can be done by Matlab’s built-in max function that optionally returns the indices of the value which is maximum and (ii) feeding the coordinates of the maximum to Matlab’s text statement, which will put a string of letters or numbers at the chosen point on the graph. The H/L labels provide only redundant information. The center of a set of solid contours is always a local maximum; the center of a set of dashed contours is always a local minimum. Therefore, the labels add no information that is not inherent in the solid/dashed contour convention.
Meteorological Convention: Negative Contours Dashed 3 2 H 1 L
0
H H
-1 L -2 -3 -3
-2
-1
0
1
2
3
Figure 4.3: Contour plots in the meteorological convention: dashed lines for contours where u(x, y) < 0, solid for positive-valued isolines. Peaks are marked with “H” and valleys with “L”. (Highs and Lows on a weather map.)
4.4. HACHURE LINES
4.4
113
Hachure Lines
Geological survey maps often add little tick marks on one side of each contour, pointing towards the low. These are commonly called “hachure lines”. The Surfer package from Golden Software for PCs offers this as a simple, automatic option. (Oil prospectors, who prompted the creation of this software, are enthusiastic hachure-users.) However, Matlab and most scientific packages do not offer hachure lines. It is fairly easy to add the ticks manually using a drawing program like Adobe Illustrator, however. Meteorologists use a different way of distinguishing peaks and valleys: the valleys (“lows”) are marked with the letter “L” and the peaks (“highs”) by the letter “H”. The hachure/H-L controversy emphasizes an important theme: different fields of science and engineering have developed different graphical conventions. If your field has a standard convention for marking peaks and valleys, it is best to follow it. (Your readers will thank you!) If your field doesn’t have a convention, then (i) do what is most convenient and (ii) clearly explain the convention in the caption. It is not necessary to explain the meaning of “H” and “L” on a contour plot in an article in the Bulletin of the American Meteorological Society, but it is important to explain this convention in a chemical engineering paper.
Figure 4.4: Right half is a standard contour plot; the left depicts a contour plot with hachure lines. The tick marks point to a valley. An equivalent indication is given in meteorology by marking valleys and peaks with the letters “L” and “H”, respectively.
114
4.5
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
Filled Contour Plot
This is a contour plot in which the gaps between each pair of neighboring contour lines is filled with a color. This can make it easier to identify the important features at a glance. In Matlab, this is done through contourf.m. The space between two contour lines is always filled with a single color or grayscale shade, even when interpolated shading is specified. This makes it easy to identify the isolines. The filled contour plot has the disadvantage, shared with pseudocolor images, that the color scheme can inadvertently emphasize or deemphasize various features. Furthermore, color plots are expensive to publish. Grayscale plots may not reproduce very well in the sense that the publisher’s typesetting equipment may do a rather poor job of reproducing the shades of gray. (Submitting electronic Postscript files to the publisher can largely alleviate this problem because the intermediate step of scanning a laserprinted image is eliminated.)
Filled Contour Plot: colormap(gray) 3 6
2 4
1 2
0
0
-1
-2
-2
-4
-6
-3 -3
-2
-1
0
1
2
3
Figure 4.5: Filled contour plot of the Matlab “peaks” function.
4.5. FILLED CONTOUR PLOT
115
In the lower image, we employed a Matlab option to define a new colormap which enhances the contrast. The “contrast” command assigns color or gray shades to various intervals so that each interval spans roughly the same number of grid point values of the function which is plotted. For the “peaks” function illustrated in Fig. 4.6, the improvement is marginal, but enhanced contrast can be quite useful for some images. A filled contour plot has the minor disadvantage that it is less natural-looking than either a unfilled contour plot or a pseudocolor graph. Because contour plots are widely used in black-and-white graphics, most scientists are used to them. Pseudocolor plots with interpolated shading also seem familiar since the colors vary smoothly from point to point as in natural objects. A more serious disadvantage is that filled-contour maps look best in color, and color publication is expensive. Even so, the filled contour plot has most of the advantages of both contour and pseudocolor images.
Filled Contour Plot: Enhanced Contrast 3
cmap=contrast(Z); colormap(cmap) 6
2 4
1 2
0
0
-1
-2
-2
-4
-6
-3 -3
-2
-1
0
1
2
3
Figure 4.6: Same as previous figure, but with a different, contrast-enhancing grayscale “colormap”.
116
4.6
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
Scalloping
The New Century Dictionary defines the verb “scallop” as meaning to “to mark or cut the border into scallops; to ornament with scallops” where the noun “scallop” is a generic term for seashells, or more formally bivalve mollusks. A common form of garden decoration, at least in coastal regions, is to mark the border between grass and flowerbed with a line of side-by-side seashells. Adding such decoration was said to be “scalloping” the garden. In graphics, it is convenient to extend these general uses of the term as follows: Definition 11 (Scalloping) Rapid oscillations in isolines in a contour plot, especially if caused or exaggerated by poor visualization. Of course, one could equally well describe such small-scale oscillations in contour lines as “noise”. Computational hydrodynamicists, who often see such small oscillations appear whose wavelength is twice the grid-spacing h, call such wiggles “2 − h” waves; this is said with a shudder because it is usually a sign that nonlinear aliasing or other numerical instability is corrupting the computation. It is convenient to have a special, graphical term because sometimes the reason that isolines wiggle like the outline of an ornamental border of seashells is because of defects in graphing or graphing software, rather than a computational instability that is amplifying 2 − h waves. Fig. 4.7 shows scalloping in all four corners of the contour plot. The function which is graphed is q(x, y) = exp −(x2 + y 2 ) + 0.01rand (4.2)
where rand is a random number, varying from point to point, between -1 and 1. The noise fluctuations are real, but small: why does noise dominate the plot when it has an amplitude only 1% of the height of the peak? The answer is that in the corners, the Gaussian has decayed to a negligible amplitude, so the noise dominates those regions. This would not matter except that the zero isoline is one of the specified contours. The random perturbations of this very flat part of the function turn the zero contour into a confused mass of little islands and straits. The remedy is to simply omit the zero contour. Fig. 4.8 shows the same figure except that the zero contour is not graphed. Now, only the Gaussian is visible, and the small-scale noise has (visually!) disappeared.
4.6. SCALLOPING
117
Scalloping: Gaussian Plus 1% Noise 3 2 1 0 -1 -2 -3 -3
-2
-1
0
1
2
3
Figure 4.7: Contour plot of a Gaussian function plus a small perturbation which is a random function of location. The plotted contour lines are those where the function q is equal to 0, 0.2, 0.4, 0.6, or 0.8.
Zero Contour Omitted: Gaussian Plus 1% Noise 3 2 1 0 -1 -2 -3 -3
-2
-1
0
1
2
3
Figure 4.8: Same as previous graph, but only the isolines where q = 0.2, 0.4, 0.6, 0.8 are graphed.
118
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
4.7
Choosing the Number of Contour Lines
One user-choosable option is the number of different levels Nc of the function q(x, y) which will be plotted. Fig. 4.9 illustrates the significance of the choice. When Nc is small, the shapes of the function are rather coarsely resolved even if the underlying grid is very fine. When Nc is large, some of the contours may be so close that they blend into solid blotches of not-very-informative color. Further, there may be no room to insert numerical labels for the contours. The Matlab contour command allows to choose the number of contour lines Nc . First, make no choice, and Matlab will set Nc = 10, the default. Second, one may explicitly specify Nc by adding an optional fourth argument: [clabelhandle,lineorpatchhandles]=contour(X,Y,Z,Nc) Third, one may replace the fourth argument by a vector V of levels qj to be plotted; Nc = length(V ).
Five Contours
Ten Contours
2
2
0
0
-2
-2 -2 0 2 Twenty Contours
2
2
0
0
-2
-2 -2
0
2
-2
0 2 Forty Contours
-2
0
2
Figure 4.9: Same function as depicted using four different numbers of contour lines.
4.8. WHAT TO CONTOUR: VARIABLE ISOLINE-SPACING AND ISOLINES OF LOGARITHMS119
4.8
What to Contour: Variable Isoline-Spacing and Isolines of Logarithms
The default option is to plot isolines qj such these values are equally spaced in q. This default simplifies the visual interpretation of the graph (good!). However, regions of small slope will be regions almost devoid of contours, making it very difficult to observe what the function is doing in such nearly-flat regions. Fortunately, almost all contouring software allows one to specify an explicit vector of qj . For example, in Matlab, one can issue the command: [contourhandle, hhh, levels]=contourBoyd(X,Y,Z’,[-5 -3 -1 -0.5 -0.25 0 0.25 0.5 1 3 5]); When the contour levels are unevenly spaced, it is very important to explicitly label the contours on the graph itself. Since the on-graph labels are usually hard to read, it is sound practice to also state the contour levels in the figure caption. Another reason for explicitly specifying the contours is not to space them unevenly, but simply to choice nice numbers such as qj = integer. Most contouring software will pick its own levels, scaled to say ten levels between the maximum and minimum of q, but some levels may be odd numbers like q5 = 3.172487. Such numbers require long labels that clutter up the graph with digits, assuming that they can be read at all. Sometimes a better strategy is not change the level spacing by hand, but instead to simple choose a different quantity to plot. In a study of two-dimensional turbulence, for example, Jim McWilliams and collaborators plotted the logarithm of the vorticity. The contours of the vorticity itself show only that the end state of the turbulent cascade is that most of the vorticity is concentrated in a few large, nearly axisymmetric vortices with great voids of emptiness. The plot of the logarithm of vorticity shows that the voids are filled with long, stringy filaments of weak vorticity. In spite of their small magnitude, however, these filaments are important because it is in them, with their narrow length scales in the cross-filament direction, that most of the viscous dissipation of vorticity occurs. A second example is the Rosenbrock “banana” function, which is defined by 2 qBanana (x, y) ≡ 100 y − x2 + (1 − x)2
(4.3)
It is widely used as a test for optimization routines because the global minimum at x = y = 1 where qBanana = 0 lies at the bottom of a long, curving thin valley. It is possible in principle to locate the minimum of a two-dimensional function merely by plotting its contours. However, the derivatives of a function are zero at a local minimum or maximum, and therefore is very flat. When the contoured values qj are evenly spaced in q, the contour nearest the local extrema will be rather far away from it in general. Fig. 4.10 (left panel) shows that plotting the contours of the banana function is indeed rather uninformative. If the contours of the logarithm of q are plotted, however, then the minimum of zero is transformed into a minimum of negative infinity. The dashed contours where log(q) < 0 ↔ q < 1 clearly delineate the valley where the banana function is small, and the densest contours are packed around the minima itself. Of course, it is possible to identify the minima without the aid of the graph by using the minimum function built in to most compilers. The standard Matlab function min returns the minimum of a vector along with the positive integer which is the index of the element which has the smallest value: [smallestvalue, index]=min(y). Oddly, there is no twodimensional function which performs this operation for two-dimensional arrays, but it is easy enough to write one:
120
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
Rosenbrock Banana
Log(Abs(Banana))
2
2
1.5
1.5
1
1
0.5
0.5
0 0
1
2
0 0
⋅ 1
2
Figure 4.10: Two contour plots of the Rosenbrock “banana” function. The left panel is a plot of the (evenly spaced) isolines. Right panel is the same except that the logarithms of the absolute value of the “banana” are plotted. The black dot marks the global minimum as found by the “min2” function described in the text. function [smallestvalue,indexi,indexj]=min2(Z); [vector of minima,vector of row indices]=min(Z); [smallestvalue,indexj]=min(vector of minima); indexi=vector of row indices(indexj). We can mark the minima of the gridded values with a disk by executing the following: [conthandle,ccc,levela]=contourBoyd(Xb,Yb,log(abs(Banana))’,20); [globalmin,indexi,indexj]=min2(log(abs(Banana))); texthandle=text(X(indexi,indexj),Y(indexi,indexj),’cdot’,’FontSize’,72); set(texthandle,’HorizontalAlignment’,’center’,’VerticalAlignment’,’cap’) (Note that the “cdot” should have a backslash in front of it, but there is no simple way to explicitly display this in Latex.)
4.9. CONTOURING IN IRREGULAR REGIONS
4.9
121
Contouring in Irregular Regions
When the geometry is complicated, most contouring software is useless because it is restricted to contours over rectangular domains. There are some exceptions, however. In Matlab, one simple workaround is to define a rectangular array which is sufficiently large to enclose the actual, irregular domain. The array of values of q is then filled with the real values of q within the domain and the Matlab NaN at all points outside the domain. Matlab will then ignore the NaN’s so that the plot will show only the contours within the domain. There are some caveats. First, one must necessarily waste some storage on lots and lots of NaN’s. Second, one must use a fine grid, or otherwise the boundary will appear jagged, approximated by Matlab as a union of line segments which are vertical or horizontal only even at a curving boundary. Third, it is usually desirable to show the boundary explicitly. The boundary can be marked in Matlab by executing a hold command and plotting the boundary through the usual linegraph command, plot. If these limitations are accepted, then Fig. 4.11 shows that the results can be quite satisfactory. The code to generate this plot is very brief: [cout,hand,levela]=contourBoyd(X100,Y100,Zbip,10); axis([-3 3 -1.5 1.5]) set(gca,’FontSize’,18); ’Contour Within Two Disks’) hold on; theta=linspace(0,2*pi,100); xdisk1=-1.5 + 1.5*cos(theta); ydisk1=1.5*sin(theta); xdisk2=1.5 + 1.5*cos(theta); ydisk2=1.5*sin(theta); plot(xdisk1,ydisk1,’k-’,xdisk2,ydisk2,’k-’); % Plot boundary disks axis([-3 3 -1.5 1.5]) set(gca,’PlotBoxAspectRatio’,[2 1 0.01]); % For convenience & geometric fidelity, make twice as wide as tall
Contour Within Two Disks 1.5 1 0.5 0 -0.5 -1 -1.5 -3
-2
-1
0
1
2
3
Figure 4.11: Contour plots of the Matlab “peaks” function on a domain restricted to the union of two disks. The plot was accomplished by contouring the function over a square domain where all values of q(x, y) outside the disks was set equal to NaN, the Matlab “Nota-Number”. The boundary circles were then added through a hold command followed by a plot command.
122
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
4.10
Label Troubles
It can be very difficult to effectively label contours of a function q with the qj , the values associated with each line. Fig. 4.12 shows a plot with illegible labels (upper left) and three strategies for coping: integer labels, manual placement of labels, and in-line labels. Other helpful tactics will be described later in this section. Why is labelling hard? The short answer is: a contour plot is crowded with the contour lines themselves. Worse still, the plot is almost useless unless the levels associated with each curve are coded in some way. To label a contour plot is to crowd many digits into a space already occupied by many lines. However, the value of a contour can be coded in ways other than by writing out the digits of its value. We can therefore divide isoline-coding strategies into broad groups: explicit alphanumeric labels and implicit, label-by-color-or-style schemes.
Many-Digit Labels
Integer Labels 0
2 0
2
2.74 -1.24 -3.9 -2.57
0.08626.72 5.39 4.07 1.41 1.41 2.74 -1.24 2.74 -2.57 0
-5.22
-2
-4 -6 -2
2
0
0
6 4
2 0 -2
-2 -2 0 2 Inline Labels: clabel(c,h)
-2 0 2 clabel(c,h,'manual')
0.08621 2
2
1. 4
13
4
2
41
06 2.74
12 62 08 0.
-5.2225 2.7
406
1.4134 0.086212
2
-2
-2 -2
0
2
-2
1
21
6
22
0
0.0
86
40
-
6.7
0
2.7
2 1.
0
2
Figure 4.12: Four contour plots of the “peaks” function, each panel with different labelling strategy. Upper left: default labelling (Matlab chooses the levels to contour and automatically places the labels). Upper right: one strategy for better labels: integer labels. Lower left: when the Matlab labelling command is called with two arguments, it automatically generates “in-line” labels that erase part of the contour, and insert themselves in the space so created. Lower right: if called with an optional third argument, ‘manual’, the labels will be placed only where the user clicks on the screen.
4.10. LABEL TROUBLES
123
Color-coding has the defect that subtle differences in hue, such as between dark blue and very dark blue, are most easily perceived when the colors are patches or areas. In an ordinary contour plot, the colored elements are lines separated by gaps of white. The gaps between the lines makes it much difficult to successfully compare them. If we inspect an example of a color-coded contour plot, such as Fig. 4.13, we find that the colors are indeed useful. The tallest peak is marked with red contours, the two smaller peaks with yellow, and the valleys are blue. However, in black-and-white graphics, the positivelines-are-solid-and-negative-lines-are-dashed convention conveys the same information (at much less cost to the publisher): which rings of contours are peaks and which are depressions. Other colormaps are possible. However, using a rainbow spectrum revives the problem that, in Tufte’s term, the sequence red-green-yellow-purple-blue (or whatever) is not easily mind-mapped to the contour values; one has to study the colorbar with almost religious intensity to learn the key. It is far better to just add numerical labels, and then the colorbar (and colors) are redundant.
Color-coded Isolines: colormap(jet) 3 6
2 4
1 y
2
0 0
-1 -2
-2 -3 -3
-4
-2
-1
0 x
1
2
3
Figure 4.13: Contour plot with isoline-values coded only by color.
124
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
An alternative implicit coding strategy is to code by line width instead. Fig. 4.14 is an example. Unfortunately, it is not completely successful. It is not easy to precisely compare small relative differences in line widths when there are gaps of white between the curves being compared. Furthermore, the very thick lines have merged into solid blobs of indecipherable black. One could perhaps obtain some improvement by playing around with the line widths, but line width-coding is clearly limited.
Width of Line = |Contour Value|+0.5 3
-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
2 1 0 -1 -2 -3
-2
0
2
Figure 4.14: Contour plot with isoline-values coded only by linewidth. This is not a standard Matlab option, so glitches occurred. The legend box claims that qj = 1 is represented by a thin dashed line when it is actually graphed as a thin solid line. Such glitches are a common price for hacking one’s way to non-standard visual representations.
4.10. LABEL TROUBLES
125
Isoline values can also be labelled by the type of marker symbol as in Fig. 4.15. This strategy has two advantages. First, color is unnecessary since the triangles, squares, pentagrams, etc., are quite distinct even in black-and-white if the marker sizes are not excessively small. Second, marker symbols are precise: lines with pentagrams have q = 6; one need not make qualitative judgments about whether the line is dark blue or very dark blue or is a five-point-wide line versus a six-point-wide line. The disadvantage is that there is no natural or obvious association between particular marker symbols and high or low values. The choice that the highest q value in Fig 4.15 is labelled with the pentagram is completely arbitrary. The reader is therefore forced to shift back and forth between the legend and the isolines, a strain of both eyes and mind. However, a compromise is possible: labelling a small subset of the contour lines with either symbols or with different widths may be useful in organizing the visual impression. In a bathymetric map, for example, distinguishing the zero contour with marker disks to thus delineate the coastline might be useful. A strategy of marker-labelling of all contours does not seem too promising.
Symbol Markers for Isolines 3 2
-6 -4 -2 -2 0 0 0 2 2 4 6
1 0 -1 -2 -3
-2
0
2
Figure 4.15: Contour plot with isoline-values coded by marker symbols.
126
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
4.10.1
Numerical Labels
Because of the difficulties of fitting both a lot of numerical labels and a large number of contour lines together, one must employ various combinations of strategies to make it all fit. Some of these strategies violate earlier recommendations for text-in-graphs, but one may have no option. These strategies include: • Integer labels
a. Manual specification of isolines to be contoured b. Scaling of q by a constant before plotting c. Modifying the label format to round to the nearest digit
• In-line labels • Manual placement of labels • Shifting to smaller font size • Reducing Nc , the number of isolines plotted • Partial labelling (some isolines unlabelled) The first three of these strategies have already been illustrated in Fig. 4.12. Most contouring routines (including Matlab’s) will choose a default number Nc of contours and a set of default values, qj , j = 1, 2, . . . , Nc , which evenly fill the range between the minima and maxima of the array of values of q. Although these defaults are very useful for exploratory graphics — the computer does the work of graphing, and the user only has to think about science — these defaults often result in isolines with strange q-values like 2.138943 and 7.0472. These non-integral, multi-digit values are not only hard to remember, but all those digits take up space on the graph that may not be available. If the isoline values are integers, then the plot will not drown in digits even if there are a lot of isolines on the graph. There are at least three ways to simplify the labels. If, by dumb luck, the range of q on the domain of the plot is limited to single digits, then manual specification of the plotted isolines to be the integers may be fine. In Matlab, this is accomplished by adding an optional fourth argument such as [-4 -3 -2 -1 0 1 2 3 4]. If the data range is unkind, then one may first need to modify the plotted quantity to q˜ ≡
q S
(4.4)
where S is a constant scaling factor that is chosen so that the range of q˜ will be (approximately) q˜ ∈ [−9, 9]. This has the disadvantage that what is plotted is different, by the scaling factor, from what is meant, and this puts extra cognitive work on the reader. Further, one must be careful to clear specify S in the caption and, if possible, in the title,too, as, for example, “A Contour Plot of Vorticity Divided by Twenty”. It is best to choose S so that it is a nice, round number; S = 8 is better than S = 7.2. Some contouring routines allow one to specify the number of digits in the label. However, many do not. In any event, labelling the isoline q = 0.4 with the label “0” is probably a bad idea. It is usually best to label all data curves with horizontal text just above the curve. However, desperate times call for desperate remedies, and a contour plot is almost by definition a visualization battle zone. “In-line” labels are plotted by erasing part of the isoline, and insert the label, rotated to parallel the contour, in its place. Because the in-label is literally surrounded by the curve it labels, it is difficult to become confused about which set of digits
4.10. LABEL TROUBLES
127
is associated with a given isoline. Furthermore, because one no longer needs whitespace between the lines for labels, one can crowd a higher density of contours with in-line labels. There are two disadvantages to in-line labels. First, many contouring routines do not allow such labels. (Matlab does, however, merely by supplying two arguments to the clabel command.) Second, the rotated text is harder to read than horizontal labels. Contouring routines do a reasonable job of automatically finding places for the labels. However, one can usually improve upon automation by manually placing the labels. (Matlab allows this by specifying the optional keyword ‘manual’ in the argument of the clabel command.) Automatic placement often leaves the labels scattered all over the place — q = 5 labelled at the far left of the plot, q = 6 at the right, q = 7 in the middle. It can be rather confusing to trace a winding isoline from one end of the graph to its label at the other. It is usually a bad idea to reduce font size because a figure will often be reduced by the publisher, or its resolution enormously degraded when distributed through a Web site. However, for contour plots, one must sometimes sigh deeply and use a small font size. In Matlab, the font size of the labels is changed by calling the labelling routine in the form htext=clabel(ccc). The left-hand side of the call to clabel will be returned as a vector of handles to the text objects which are the line labels. The command set(htext,’FontSize’,18) will then specify 18-point type. (One can choose any size that one wishes.) Other properties can be changed the same way: set(htext,’FontName’,’Palatino’) will change the font to Palatino. Fig. 4.16 illustrates two of the difficulties described earlier: multi-digit labels and labels in too large a font size.
Drowning in Digits: 24-point Labels 3
1. 0 0.4974 02 21
1.7926 35.8781 .9637
y
-3 -3
817
-2
8 -0.694 92 7 1.7.09 1
-1
3 73 4.5 74 9 1.0
0
26 79 1 1.022 0.4
1
0.40221 1.09714 .79 10.4022 8 9 2 9 26 .097 1 -0.2 0.9 3. 8 4 18 78 -337881 8.1 4 3 . 3 3 2 . 77 7 1 85 -3.0 689 .0974 6 5.2 1. 09 74 37 -3.07817 1 0.2.34.818 8 2 -0.2 9 8 2 . 40 783.7926 92-9 0 08 9 4 0.92 34 221 1 2 8 . .6 -0 -1 -0.29298 0.4 ---25.15 0-21..367 93 02.128835 9249 8
2
-2
-1
0 x
1
2
3
Figure 4.16: A doubly-awful contour plot. First, the labels have many digits. Specify isoline values with one or two digits instead! Second, the labels are in very large, 24-point type. When the contours will not be labelled, one can choose a large number Nc of contours to be plotted. Large Nc brings out even small features of q(x, y). However, when the isolines will be labelled, clarity can be greatly improved by reducing Nc . “Fewer-is-better” for a
128
CHAPTER 4. CONTOUR (ISOLINE) PLOTS Partial Labelling: clabel(cout,[-7 -5 -3 -1 1 3 5 7]) 3 2 3 3
1 -5
7
0
3 -3
5
1
-1
1
-1
-3 -1
-2 -3 -3
-2
-1
0
1
2
3
Figure 4.17: A contour plot in which only half the isolines are labelled, permitting a less crowded diagram. The labels have been printed in an almost illegible font size to illustrate the perils of using a font size that is too small relative to the final printed size of the graph. crowded graph. Another strategy is to label only some of the contours. If the isolines are evenly spaced in q, the values of unlabelled contours can be inferred from its neighbors. This might be dubbed the “what comes between two and four strategy”. In Matlab, partial labelling can be implemented by simply calling clabel with a rightmost argument that is a vector of numbers. The command clabel(ccc,[-5 -3 -1 1]) will label only those contours for which q= -5 or -3 or -1 or 1 as illustrated in Fig. 4.17. Cleveland (1993) prefers to combine this strategy with differential line widths: the labelled contours are thicker than unlabelled contours. This artificially deemphasizes the unlabelled isolines (bad!) but it does make it easier to associate labels with the correct contour, especially when the labels are above-the-curve rather than in-line. His style of partial-labelling-with-variable-line-width is illustrated in Fig. 4.18. Partial Labelling: Thicker Labelled Contours 3 1
2
1
1
-1
1
3
-3
3
7
1 3
-1
1
-1
5
0 -1
1
-2 -3 -3
-1
-2
-1
0
1
2
3
Figure 4.18: Same as the previous figure except that the labelled contours are thicker than the unlabelled isolines, a device favored by Cleveland(1993).
4.11. JAGGIES OR PIECEWISE LINEAR PLOTS OF CONTOURS
4.11
129
Jaggies or Piecewise Linear Plots of Contours
Contouring software usually approximates the isolines by piecewise linear functions. If the points of the rectangular grid are connected by lines, then the contours are continuous across these grid lines, but the slopes are usually discontinuous. (In mathematical jargon, the isolines are graphed as functions with C 0 but not C 1 continuity.) On a coarse grid, the slope discontinuities are very evident. A plot with obvious discontinuities is said to “have the jaggies”. (Fig. 4.19). The easiest remedy for the jaggies is to a fine grid. What is one to do if the data is available only on a grid of unsatisfactorily low resolution? The answer is to first interpolate from the coarse grid to a finer grid, and then supply the interpolated values to the contouring software. Most software libraries have good routines for two-dimensional interpolation, so this preprocessing step does not require writing a lot of code. In Matlab, the procedure takes just a few lines. Let X, Y, Q denote the coarse grid, such as might be produced by a statement like [X,Y,Z]=peaks(ncoarse). Let the onedimensional arrays of points on the high-resolution grid be denoted by xf, yf . Matlab has a built-in command for forming a two-dimensional tensor grid from such vectors meshgrid: xf=linspace(xmin,xmax,nfinex); yf=linspace(ymin,ymax,nfiney); % vectors [Xfine, Yfine]=meshgrid(xf,yf ); % Xfine is an (nfiney x nfinex) matrix with each of its nfiney rows containing xf % Yfine is an (nfiney x nfinex) matrix with each of its nfinex columns containing yf The values of q(x, y) on the fine grid are generated by Qfine=interp2(X,Y,Q,Xfine,Yfine,’cubic’) where the optional last argument specifies bivariate cubic interpolation. The function can now be contoured on the fine grid through [ccc,hhh,levela]=contour(Xfine,Yfine,Qfine,Nc) The high resolution plot on the right in Fig. 4.19 was computed through this sort of twodimensional interpolation from the 8 x 8 grid.
Jaggies: 8 x 8 Grid
Jaggie-Free: 40 x 40 Grid
Figure 4.19: Two contour plots of the Matlab “peaks” function, identical except for the grid. The plot on the low resolution 8 x 8 grid shows noticeable discontinuities in the slope of the isolines (“jaggies”). The higher resolution plot has very smooth contour lines.
130
4.12
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
Contouring Algorithms
An isoline of a function q(x, y) is by definition the solution of the algebraic equation q(x, y) = Q
(4.5)
where Q is the desired value of q on the contour line. The isoline computation is challenging because Eq. (4.5) is a nonlinear equation for all but the most trivial case. It follows that it may have multiple solutions, that is, the isoline may be a set of multiple, non-connected curves. The usual rememdy is to compute a local, linear approximation to q(x, y) by interpolation. The isolines of the approximation will then be straight lines in the x − y plane. Only that portion of the contour which lies within the domain of validity of the local, linear approximation is accepted and graphed; the rest is discarded. By computing many local approximations, and drawing many line segments, the contours of q over the entire region of interest can be graphed. The usual input to a contouring subroutine is a rectangular array of the values of q at a set of points (“grid points”) in the (x, y) plane: qij = q(xi , yj ), i = 1, 2, . . . , M ;
j = 1, 2, . . . , N
(4.6)
For simplicity, we assume in the formula that the two-dimensional array of grid points is the tensor product of two one-dimensional grids. If we draw parallel and vertical lines connecting the grid points, the diagram will resemble a checkerboard, divided into rectangular “grid boxes”, each with a grid point at its four corners. Some subroutines require that the grid boxes be rectangular. However, this is only to simplify programming. The underlying algorithm is based on subdividing the grid boxes into triangles. It therefore causes no complications if the grid boxes are general quadrilaterals, as shown in our schematic diagram, or even more complicated shapes. The first step in contouring is to identify a particular quadrilateral. The second step is to subdivide the box into triangles as shown in Fig. 4.20. The simpler subdivision is to
;y
Step One: Choose a quadrilateral
Step Two: Divide Into Triangles
or
Figure 4.20: First two steps in contouring an array of values of q on a set of quadrilaterals. The solid disk on the right denotes a triangle vertex where q(x, y) must be obtained by interpolation before processing the triangles.
4.12. CONTOURING ALGORITHMS
131
split the quadrilateral into two by a single diagonal line. The more complicated but more accurate procedure is to subdivide into four triangles using two diagonals. In order that q is known at all vertices of the triangles, it is necessary to compute a value for q by interpolation at the point where the diagonals intersect (solid disk), which is a common vertex for all four triangles. The rest of the algorithm is to plot the contours for a single triangle. Repeating this procedure over all triangles within a quadrilateral, and then over all quadrilaterals in the array, completes the contour plot. The fundamental geometrical unit of the algorithm is a triangle. The reason that the triangle is fundamental is that there is a unique linear polynomial which interpolates q(x, y) at the three vertices of the triangle: q = a + bx + cy
(4.7)
where, defining q1 ≡ q(x1 , y1 ),
q2 ≡ q(x2 , y2 ),
q3 ≡ q(x3 , y3 )
(4.8)
the coefficients are ∆
=
a = b
=
c =
−x3 y2 + y3 x2 − x1 y3 + x1 y2 + y1 x3 − y1 x2
((y3 x2 − x3 y2 )q1 + (y1 x3 − x1 y3 )q2 + (y2 x1 − x2 y1 )q3 )/∆ ((y2 − y3 )q1 + (y3 − y1 )q2 + (y1 − y2 )q3 )/∆
((x3 − x2 )q1 + (x1 − x3 )q2 + (x2 − x1 )q3 )/∆
(4.9) (4.10) (4.11) (4.12)
In the language of geometry, a polynomial which is linear in x and y defines a plane in the x − y − q space. The interpolating polynomial is an analytic expression of the geometric assertion that a plane in three-dimensional space is uniquely determined by specifying any three non-collinear points on the plane. The contours of q(x, y) as given by the bilinear polynomial approximation are all straight lines, all parallel to each other with slope dy/dx = −b/c (Fig. 4.21). The isolines of all more complicated functions are curved. However, if the triangles are sufficiently small, or to put it another way, if the grid points are sufficiently dense, then the linear approximation to the contour lines will be accurate within the triangle as shown schematically in Fig. 4.22. It is straightforward to compute the intersection of a given contour line with q = Q with each of the three lines which bound the triangle. One can then draw those portions of the contour which lie within the triangle. It is a very bad idea to extend the plotted lines beyond the triangle because the true lines will curve increasingly far from the approximating straight lines as one moves farther from the triangle. We will approximate the contours in neighboring triangles by using different bilinear approximations, a different polynomial for each different triangle. To show the simplicity of the necessary mathematics, the intersection of the line connecting the first and second vertices with a contour where q = Q is given by defining µ ≡ b(x2 − x1 ) + c(y2 − y1 )
(4.13)
x = {(a − Q)(x1 − x2 ) + c(x1 y2 − x2 y1 )} /µ
(4.14)
y
= {(a − Q)(y1 − y2 ) + b(x2 y1 − x1 y2 )} /µ
(4.15)
The formula for the other two sides can be obtained by permuting the indices. In other words, the intersections along the side between vertices two and three are obtained by the
132
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
Exact q
Plane Approximation
1
1
0.5
0.5
0
0
-0.5
-0.5
-1 0
-1 0
0.5
0.5
x1 0
0.5 y
1
x1 0
0.5 y
1
Figure 4.21: Left panel: the true surface q(x, y). The curved isolines of q are shown on the plane q = −1. Right: the plane which interpolates the surface of q at three vertices of the triangle which is marked in black on the q = 0 horizontal plane. The contours of the interpolating polynomial, shown below, are straight, parallel lines. substitutions x2 → x3 , x1 → x2 , y2 → y3 , y1 → y2 . Similarly, the third side is obtained by replacing 3 → 1, 2 → 3 in all subscripts. Each solution must be checked to see if it lies within the side of the triangle. In general, only two of the three intersections will lie on the boundaries of the triangle; a straight line is plotted between these intersections to approximate the isoline. If none of the intersections lies with a side of the triangle, then the contour q = Q lies outside the triangle and should not be plotted while processing this triangle. (We may find true pieces of the isoline q = Q while processing other triangles.) One worry might be that line segments plotted in adjacent triangles might not match up so that the algorithm would plot contour lines that zig-zagged at the boundaries of each triangle. Fortunately, this fear is groundless. A theorem, proved in Young and Gregory(1972) and many other numerical analysis texts, shows that interpolation by piecewise linear polynomials in continguous (that is, touching but non-overlapping) triangles, is always continuous across the common boundaries between triangles). (The first derivatives of q, however, are generally discontinuous across the triangle walls). Therefore, the isolines as plotted triangle-by-triangle will be continuous, too, although the slopes will not be continuous. Several articles and books describe contouring algorithms. Three examples are the fol-
4.12. CONTOURING ALGORITHMS
133
lowing. • Simons(1983) Each rectangular grid box is split by many fine lines, some parallel to one pair of sides, others parallel to the other pair of sides. Bilinear interpolation on these segments results in the plotting of a dot wherever a contour crosses one of these auxiliary line segments. When the network of auxiliary lines is sufficiently fine, the pattern of dots will blur into continuous isolines. • Bourke(1987) Each rectangle is subdivided into four triangles through a pair of diagonal lines running from each corner to the opposite corner of the rectangle. Bilinear interpolation supplies a value for q at the center of the box where the diagonals intersect and the four triangles have a common vertex. Bilinear interpolation within each triangle then supplies line segments that approximate the contours within each triangle. (This is the algorithm described above.) • Cleveland(1993) Bilinear interpolation within each quadrilateral is combined with Gross’ rules for resolving ambiguity in contour orientation within a quadrilateral.
Figure 4.22: The thin, parallel lines are the contours of q as given by a bilinear polynomial approximation which interpolates q at the three vertices of the indicated triangle in the x−y plane. The last step in the contouring algorithm is to identify which contours intersect the walls of the triangle and then draw these lines on the interior of the triangle only (heavy solid line segments connecting two sides). The straight lines are good approximations to the true contours (dashed curves) within the triangle, but increasingly poor approximations to the isolines away from the triangle.
134
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
These brief summaries show that there are some variations in contouring strategies. Nevertheless, the basic unit of analysis is always a grid box or triangle; the fundamental tool is to approximate q(x, y) by a bilinear polynomial in a given subdomain, and draw the contours within that rectangle or triangle as given by the polynomial. Because of the piecewise linear character of contouring algorithms, the “jaggies” are almost inevitable unless the function is contoured using a dense grid of points. There are a few contouring routines that decrease the jaggies. If the line segments that are approximate a given isoline are identified by searching through the list of plotted segments to find pairs that share a common endpoint, one can then apply splines or other higher order approximations to smooth the contours. The NCAR Graphics package, for example, has offered such options for more than a quarter of century. Matlab graphics, alas, does not.
4.13. CONTOURING IN NON-RECTANGULAR DOMAINS, II
4.13
135
Contouring in Non-Rectangular Domains, II
Because the contouring is performed one grid box or grid triangle at a time, it is not necessary that the input array Q(i, j) represent the values of q(x, y) at the points of a rectangular grid in the x − y plane. Instead, for many subroutines including Matlab’s, it is sufficient that the input array be logically rectangular. What is meant by this is the matrix Q must have a rectangular array of indices, i. e., Q(i, j) such that i = 1, 2, . . . , M and j = 1, 2, . . . , N where i and j vary independently. The corresponding values of x and y such that Q(i, j) ≡ q(X(i, j), Y (i, j))
(4.16)
can be almost arbitrary. An example will make this clearer. Define an evenly spaced grid in polar coordinates (r, θ) through ri ≡ (i − 1)/(M − 1);
θj ≡ 2 π (j − 1),
i = 1, 2, . . . , M
j = 1, 2, . . . , N (4.17)
In Cartesian coordinates (x, y), the grid points are X(i, j) ≡ ri cos(θj );
Y (i, j) ≡ ri sin(θj ),
i = 1, 2, . . . , M ; j = 1, 2, . . . , N
(4.18)
Let q(x, y) be the function as expressed in terms of Cartesian coordinates. Define array Q by substituting x → X(i, j), y → Y (i, j) as in Eq. 4.16. The Matlab command contourBoyd(X,Y,Q) will then work just fine as illustrated in Fig. 4.23. For the special case of polar coordinates, one can exploit special routines, not necessarily associated with contour plots per se. In Matlab, linehandle=polar([0 2*pi],[0 1]); delete(linehandle); hold on will plot a polar axis and then delete the dummy line which had to be plotted and erased in order to put the polar command to a non-standard use. contour will graph the isolines as in Fig. 4.23. |q| on Circular Domain 90 1 60
120 0.8
0.9
1 1.
1
0.6
30
150
0.2
1
1
1
Imaginary
0.4
180
0
1
1 1
1
1
210
330
1.1 240
300 270
Real Figure 4.23: Contour plot in polar coordinates. f (x, y) ≡ (z 4 − 1)1/4 where z ≡ x + iy.
136
CHAPTER 4. CONTOUR (ISOLINE) PLOTS To plot a contour in elliptical coordinates, one can use the following:
[th,mu]=meshgrid((0:0.02:2)*pi,0:0.01:0.5); % 2D arrays, % equi-spaced in elliptical coordinates. X=cos(th).*cosh(mu); Y=sin(th).*sinh(mu); % Convert to Cartesian (X,Y) Q = cos(3*th).*cosh(3*mu) + i*sin(3*th) .* sinh(3*mu); [labelhandles,linehandles]=contour(X,Y,abs(Q),[0.2:0.2:2.2]); axis equal; % forces the elliptical domain to look elliptical instead of square. % To plot the boundary ellipse, add the next two lines: Xb=cos((0:0.02:2)*pi)*cosh(max(max(mu)); Yb=sin((0:0.02:2)*pi)*sinh(mas(max(mu)); hold on; plot(Xb,Yb,’g-’)
Fig. 4.24 shows the result. Note that numerical labels have been added using the standard clabel command without difficulty.
Contours on Elliptical Domain 0.5
1.8
1.6
1.4
2
1.8 2
1.2
1.6
1.6
1.4
0.
8
1
1.4 1.2 1
1.2
1
1.4
1.6 2
0.6
1.
2 1.
1
1.8
2
-1
-0.5
2
1.4 1.6
1.4
1.6
-0.5
0.8
1.6 2
1
1
0.6
1
2
0.6
1.6
1
0
1.2 1.4 1.8.2 2
Imaginary
1.8
2
2 1.
1.8
2
1.8
0 Real
0.5
1
Figure 4.24: A contour plot in elliptical coordinates. q(x, y) ≡ T3 (x + iy) where T3 is the Chebyshev polynomial of degree three.
4.13. CONTOURING IN NON-RECTANGULAR DOMAINS, II
137
An even more exotic example is to use bipolar coordinates to contour a function on the exterior of a domain with two disks. Because the quasi-radial coefficient ranges from ξ ∈ [0, π/4] in the right half-plane and ξ ∈ [0, −pi/4], it is necessary to define arrays for the right and left-half planes separately and then combine them into a single logicallyrectangular array. Even so, the Matlab code is very simple and quite similar to the example for elliptical coordinates above: [th,xi]=meshgrid((0.01:0.02:1.99)*pi,(5*0.0025:0.0025:0.25)*pi); X=sinh(xi) ./ ( cosh(xi) + cos(th)); Y= sin(th) ./ ( cosh(xi) + cos(th)); q = X .* Y; [thn,xin]=meshgrid((0.01:0.02:1.99)*pi,(5*0.0025:0.0025:0.25)*(-pi)); Xn=sinh(xin) ./ ( cosh(xin) + cos(thn)); Yn= sin(thn) ./ (cosh(xin)+cos(thn)); qn=Xn .* Yn; [m,n]=size(q); Xboth=zeros(2*m,n); Yboth=zeros(2*m,n); qboth=zeros(2*m,n); for ii=1:m, for j=1:n, Xboth(m+1-ii,j) = Xneg(ii,j); Xboth(ii+m,j) = X(ii,j); Yboth(m+1-ii,j) = Yn(ii,j); Yboth(ii+m,j) = Y(ii,j); qboth(m+1-ii,j)=qn(ii,j); qboth(ii+m,j)=q(ii,j); end, end vect=[-13 -11 -9 -7 -5 -3 -1 1 3 5 7 9 11 13]; [labelhandles,linehandles,levela]=contourBoyd(Xboth,Yboth,qboth,vect); axis equal; axis([-6 6 -3 3]); hold on; xi0=max(max(xi)); thb= pi*linspace(0,2,100); Xb=ones(1,length(thb))*sinh(xi0) ./(ones(1,length(thb))*cosh(xi0)+cos(thb)); Yb=sin(thb) ./ (ones(1,length(thb))*cosh(xi0)+cos(thb)); xi0=-max(max(xi)); thb= pi*linspace(0,2,100); Xbn=ones(1,length(thb))*sinh(xi0) ./(ones(1,length(thb))*cosh(xi0)+cos(thb)); Ybn=sin(thb) ./ (ones(1,length(thb))*cosh(xi0)+cos(thb)); plot(Xb,Yb,’k-’,Xbn,Ybn,’k-’);
Bipolar Domain 3 13
3 -1
2
5
-5
1 y
9
-9
0 -1
-1
1
1
-1
5
-2
-5
9
-9
13
-3 -6
3 -1
-4
-2
0 x
2
4
6
Figure 4.25: A contour plot on the exterior of two disks (bipolar coordinates). In Cartesian coordinates, the function contoured is q(x, y) ≡ xy.
138
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
4.14
Summary
Merits: 1. Pseudocolor plots are very expensive to reproduce in journals and therefore must be used sparingly. 2. Mesh plots hide some low-lying, remote features behind nearer peaks. Even without such obstructed views, mesh plots are less precise than contour plots in the sense that the visual system has more trouble identifying small features and their shapes on a mesh plot than on a contour plot. Problems: 1. Difficulty in distinguishing hills from valleys. The best remedy is to graph the positive contours as solid, the negative-valued contours as dashed. 2. Illegible labels. There is no simple remedy, but playing around with the font size and label positioning can help. Reducing Nc , the number of contours on the graph, gives more room to each label. Another trick is to control the qj . If these are integers, then each label is only one digit (plus perhaps a sign). In contrast, a label like 3.143873945 will take a lot of space. 3. Contours all clustered in one small region of the domain. Remedy: plot contours of the logarithm of q. 4. “Scalloping”. This denotes a pattern of zig-zag contours that fill a wide area where q ≈ 0. Tiny numerical errors can cause sign fluctuations between, say, -0.0001 and 0.0001, causing the zero contour to appear in the shape of a maze with many zigzags. One remedy is to the zero contour if the software allows this. Another remedy is to apply small-scale smoothing to filter the noise before plotting the function. A third remedy is to add a small constant to q so that even with the noise, the function q(x, y) is always one-signed. 5. “Jaggies”: isolines that should be smooth and continuous look like line segments with discontinuous slopes. Remedies: (i) use higher resolution for making the contour plot or (ii) smooth the contour lines, which is an option in some library contouring routines. It may be necessary to use high order interpolation to create areas for plotting that are denser than those of the original calculation. The reason is that most contouring algorithms take each box defined by four gridpoints and apply piecewise linear interpolation within each rectangle. Thus, the contouring algorithm is usually less accurate than the underlying calculation.
4.14. SUMMARY
139
Appendix: Quick and Dirty Contour Manipulation in Matlab The next appendix describes a modified contouring routine that, with a single function call, provides access to the handles of individual contour lines so that these can be manipulated any way one wishes. Although the function contourBoyd is not very long, it is possible to manipulate contours in an even simpler way at the expense of many function calls instead of one. The key ideas embodied in this simpler approach are: (i) contour can plot a single isoline, q = qj and (ii) multiple contour plots can be superimposed using the hold command. The simpler strategy is illustrated by the loop. The usual contouring routine contour is called Nc times where Nc is the number of contour levels. The fifth argument ’k’ is a dummy that forces the contours to be drawn as “line objects” rather than as “patch objects”. At each call, the properties of the isoline can be altered through the set(linehandles, ...) where the ellipsis stands for any line property, such as width, linestyle or color. qj=[-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7]; Nc=length(qj); for ii=1:Nc [clabelstuff,linehandles]=contour(X,Y,Z’,[qj(ii) qj(ii)],’k’); set(linehandles,’Color’,[abs(qj(ii))/7 (1-abs(qj(ii)/7)) 0]); if ii==1, hold on; end % if end % ii A disadvantage of both the one-call and many-call methods for changing the plotted characteristics of the isoline is that there is no simple way to provide an analogue of the color or legend. A second difficulty is that is difficult to encode the contour labels as linestyle or markertype only; a label-less plot with many linestyles, marker types or colors will be slow reading.
140
CHAPTER 4. CONTOUR (ISOLINE) PLOTS
Appendix: Matlab function contourBoyd function [cout,hand,levela]=contourBoyd(varargin) %function OK=contourBoyd(x,y,z,nc) % The twist from the standard procedure is that contours % of negative values of z are dotted. %CONTOUR Contour plot. % CONTOUR(Z) is a contour plot of matrix Z treating the values in Z % as heights above a plane. A contour plot are the level curves % of Z for some values V. The values V are chosen automatically. % CONTOUR(X,Y,Z) X and Y specify the (x,y) coordinates of the % surface as for SURF. % CONTOUR(Z,N) and CONTOUR(X,Y,Z,N) draw N contour lines, % overriding the automatic value. % CONTOUR(Z,V) and CONTOUR(X,Y,Z,V) draw LENGTH(V) contour lines % at the values specified in vector V. Use CONTOUR(Z,[v v]) or % CONTOUR(X qmax) ); indextoosmall=find( (Q < qmax)); Q(indextoobig)=qmax; Q(indextoosmall)=qmin; The Matlab find function returns a vector of indices into the matrix Q which satisfies the logical condition specified in the argument of find. Thus, the statement indextoobig=find( (Q > qmax) ); finds all elements of the array Q(ii, j) which are larger than qmax, which the user can specify arbitrarily, and then indextoobig contains the indices of all these toolarge elements. The statement Q(indextoobig)=qmax modifies all these elements to set them equal to the upper truncation qmax while leaving all the other elements — all those Q(ii, j) such that Q(ii, j) < qmax unchanged. The ability of Matlab matrices to be called with an argument which is a vector of indices, and have vector operations performed only on elements with those indices and no others, is one of the most powerful features of the language.
5.6. CUTAWAY MESH PLOTS
5.6
153
Cutaway Mesh Plots
Another important strategy is to delete part of the domain in the x − y plane, which in the absence of such deletions is always a rectangle. Fig. 5.8 shows two different mesh plots, one standard and one cutaway, of a function that mimics the waves of the two-dimensional wave equation spreading away from the origin. To use geographical language, the function has a ring-shaped ridge at large radius from the origin and a shallower, ring-shaped valley at smaller radius. The valley is completely invisible in the standard mesh plot because our view of this depression is blocked by the tall ridge in front of it. Rotating a plot will sometimes solve such obstructed-view difficulties, but this function is radially symmetric, so it is invariant under rotations in the horizontal plane. With a very high or low viewing angle, we would glimpse a bit of the depression, at least enough to know that there was a depression, but it is difficult to accurately estimate the size and extent of such features from extreme viewing angles. When one quadrant of the horizontal domain is chopped away, however, all becomes clearer. We can see into the region enclosed by the ring-ridge to see the depression.
Trough Invisible
Cutaway Mesh
Figure 5.8: The function plotted is radially symmetric with a maximum of one at r = 2 and a minimum of -0.35 at r = 1 where r is distance from the origin in the x − y plane. In a standard mesh plot, the minimum is invisible. When a quarter of the mesh is cut away, both the ridge and the trough are clearly visible. Inspired by Fig. 7.11 in Morse and Feshbach (1954).
154CHAPTER 5. MESH PLOTSSCIENTIFIC VISUALIZATION & INFORMATION ARCHITECTURE
5.7
Variable Grid Spacing to Code Positive and Negative Heights
It is highly desirable to distinguish positive-valued regions from negative-valued regions through some additional visual cue beyond the spatial shapes of the meshlines themselves. Fig. 5.9 shows an interesting and effective device for doing this in black-and-white graphics. Parts of the surface above the plane z = 0 are shown with a fine mesh; the valleys are show with a coarse mesh. Unfortunately, most mesh routines do not offer this as a standard option. However, work-arounds are possible. In Matlab, for example, one can plot the mesh twice. Negative values are replaced by Nan (“Not-a-Number”), and are therefore not shown in the first plot, which uses a fine mesh. The NaN’s are reversed, and replaced positive values, for the second plot, which uses a coarse mesh. When the two plots are superimposed using the hold command, the result will imitate this graph from Wolf.
Figure 5.9: A mesh plot in which positive-value parts of the surface are depicted with a fine mesh whereas a coarse mesh is used for parts of the surface below the plane z = 0. From Integral Transforms in Science and Engineering by Kurt Bernardo Wolf, Plenum Press, New York, pg. 427, (1979).
5.8. COMPROMISE IN GRID DENSITY
5.8
155
Compromise in Grid Density
One tricky issue with mesh plots is that if the grid is coarse, important but small-scale features will be invisible and visible cues for depth perception will be so limited that the eye struggles to perceive the three-dimensionality of the plot (Fig. 5.10). However, if the lines are too dense, the graph will become an unreadable mess of black. A dense plot is especially tricky when the plot is reduced for publishing, either for the Web or by a commercial printer. The full-size original may look okay, but the published miniaturized version has the lines so close together as to be unrecognizable.
Too Dense
Medium Grid: OK!
5
5
0
0
-5 -2
0
-2 2 Too Coarse
0
2
-5 -2
0
2
-2
0
2
5 0 -5 -2
0
2
-2
0
2
Figure 5.10: The 100 x 100 grid (upper left) is too black when printed; the 6 x 6 (lower left) is so coarse that the mesh curves are jagged with large slope discontinuities and minor features are invisible. The 25 x 25 grid (upper right) is a reasonable compromise.
156CHAPTER 5. MESH PLOTSSCIENTIFIC VISUALIZATION & INFORMATION ARCHITECTURE
5.9
Importance of Viewpoint
A mesh plot is not completely specified until the viewing angle has been chosen: two angles that specify the observer’s point of view in a spherical coordinate system system centered on the origin in the x − y − q space. The default angles are often satisfactory, but more often than not, different viewpoint provides a clearer perception of the peaks and valleys of a given figure. In Matlab, one can vary the viewing angle by view(horizontal angle, vertical angle) where the angles are specified in degrees. Fig. 5.11 compares four different views of the Matlab “peaks” function. It is necessary to specify q(x, y) because the optimum viewing angle is generally different for each different function. The first argument of view spins the mesh about the vertical axis. It is important to clearly label the x and y axis so that the reader understands the orientation of the surface. The second argument of view specifies the vertical angle; a choice of ninety is to look down on the surface of q(x, y) from directly above. When the vertical angle is small, valleys and low hills are easily obscured or even completely hidden by taller features in the foreground. (Therefore, one usually should choose the horizontal angle so that the taller features are in the background, that is, farthest from the viewer’s eye.) When the vertical angle is tall, the effects of vertical relief are muted so that it becomes much harder to judge heights and depths than when looking from the side. It is necessary to experiment and choose a suitable compromise for each plotted function.
view(30,15)
view(30,30)
5
5
0
0
-5
-5 -2
0
-2
2 x
0 y
2
2 -2
0
0 x
view(150,30)
2
-2
y
view(30,60)
5 0
5 0 -5
-5 -2 0 2 y
2
0 x
-2
2 -2
0 0 x
2
-2 y
Figure 5.11: The same figure as viewed from 4 different viewing angles; the titles give the arguments of the Matlab view command.
5.10. SPINNING THE MESH PLOT OR THREE-DIMENSIONALITY THROUGH ANIMATION157
5.10
Spinning the Mesh Plot or Three-Dimensionality Through Animation
The Matlab lines below allow animate the rotation of the mesh diagram with an option to convert the movie to a Quicktime video. This may be helpful in experimenting with the choice of horizontal and vertical viewing angles. (Horizontal only in the code fragment, but it is trivial to spin the mesh in the vertical if one wishes.) The greatest usefulness of video-of-spinning-mesh is that sometimes there is no single viewpoint that is optimum for viewing all features. One option is to make a composite graph which shows the same surface from two or more viewing angles. In a static medium like print, this may be the best that one can do. On the computer screen, however, or at a conference with a suitable projection system, one may be able to do much better by using the animation as the endproduct. Our visual systems are very good at using motion cues. Indeed, psychologists have shown that for some lower lifeforms such as forms, a food source which is static may be invisible to the animal, even when right in front of the creature’s eyes. Only when the flies are moving are they recognized as food-insects by the frog’s cognitive system. Human beings have much better capabilities for unmoving visual fields; still, the greatest threats to humans and our primate ancestors were threats that moved. When we view a rotating image, we may notice features or details that were missed when looking at a set of stills from the same sequence. Animations-of-rotating-mesh-figures do have a couple of disadvantages. First, it is a lot more trouble to present them at conferences, or in an electronic journal, that it is to make a transparency of a non-rotating mesh diagram. Second, an animation requires study; a quick glance at a printed mesh diagram may suffice to identify the major mountains and valleys, but a rotating image requires some careful attention. It may be very difficult to achieve such study and attention in the confusion of a conference presentation or seminar where the session chair is frowning at his watch, and half the audience is fidgeting about hours and hours of listening to earlier presentations. The result is that rotating-mesh-animations are probably most useful for exploratory graphics. The interesting details that are noticed at leisure can then be condensed into a handful of static mesh plots.
Matlab Code to Change Views and Make a Quicktime Movie [X,Y,Z] = peaks(30); mesh(X,Y,Z); axis([-3 3 -3 3 -10 10]) % fix axes so scaling does not change axis off % erase axes because they jump around shading interp; colormap(copper); % SPIN and ANIMATE nframes=30; MovieMatrix=moviein(nframes); for ii=1:nframes view(-37.5+(360/nframes)*(ii-1),30) MovieMatrix(:,ii)=getframe; end movie(MovieMatrix) % play themovie qtwrite(MovieMatrix,colormap,’SpinPeaksDemo30.qt’)
158CHAPTER 5. MESH PLOTSSCIENTIFIC VISUALIZATION & INFORMATION ARCHITECTURE
5.11
Mesh Plots on Non-Rectangular Domains
Just as for contour plots, it is usually possible to make a mesh plot for a non-rectangular domain using standard software so long as the grid is logically rectangular. By this we mean that the function q(x, y) is represented by a matrix Q(i, j) whose indices fill a rectangle in the i − j plane. The corresponding grid point values in Cartesian coordinates, X(i, j) and Y (i, j) need not specify a rectangle in the x − y plane. Figs. 5.12 and 5.13 are examples. Both illustrate a frequent artifice with complicated geometries: a second mesh surface, flattened by replacing the array Q(i, j) by a constant independent of (i, j), has been placed under the surface to illustrate the underlying grid. With a contour plot, the same effect is best achieved by using the hold command and superposing a linegraph that shows the boundary.
Mesh on Elliptical Domain; Elliptical Coordinates Below
1
abs(f)
0.8 0.6 0.4 0.2 0 -1
0.5
-0.5 0
0 0.5 1 Real
-0.5
Imaginary
Figure 5.12: Mesh plot on an elliptical domain, obtained through Matlab’s standard command mesh(X,Y,Q). The arrays X, Y which store the grid point locations in the Cartesian coordinates x and y are the images of a rectangular grid in the elliptic coordinates (µ, θ) under the usual mapping from the elliptic to Cartesian coordinates: X(i, j) = cosh(µi ) cos(θj ), Y (i, j) = sinh(µi ) sin(θj ).
5.11. MESH PLOTS ON NON-RECTANGULAR DOMAINS
159
4 3 2 z
1 0 -1 -2 -3 -4 -2
2
0 2 x
0
y
Figure 5.13: Mesh plot on a grid taken from the listing for Fig. 2.27 of Numerical Analysis and Graphic Visualization with Matlab by Shoichiro Nakamura, Prentice-Hall (1996). The lower mesh plot, made by multiplying replacing the heights by a constant, shows the grid. The upper mesh is of q ≡ x2 y, which is different from Nakamura’s example on the same grid.
160CHAPTER 5. MESH PLOTSSCIENTIFIC VISUALIZATION & INFORMATION ARCHITECTURE For very irregular geometries, Matlab 5.x provides a function (delaunay) to compute a Delauny triangulation of an irregular set of points. Matlab also supplies subroutines trimesh and trisurf for computing mesh and surface plots on the triangular grid created by delaunay. Fig. 5.14 illustrates the Delaunay triangulation of a complicated region, followed by application of the Matlab program trimesh. Unfortunately, there is no Matlab routine for contouring on triangles. Nakamura(1996) provides a contour plot routine for an irregular triangular mesh. His routines are available as freeware on the Mathworks, Inc., Web site as user-contributed software.
Trimesh of Delaunay Triangularization of Octagon
q=cos(π x/2) exp(y*y)
3 2 1 0 -1 -2 -1
1 -0.5
0 0
0.5
1
-1
y
x Figure 5.14: Surface of the function q(x, y) = cos(πx/2)exp(y 2 ) on a triangular mesh
5.11. MESH PLOTS ON NON-RECTANGULAR DOMAINS
Appendix: Non-Standard meshc function h=meshc(x,y,z,c,zpos) %MESHC Combination mesh/contour plot. % MESHC(...) is the same as MESH(...) except that a contour plot % is drawn beneath the mesh. % % Because CONTOUR does not handle irregularly spaced data, this % routine only works for surfaces defined on a rectangular grid. % The matrices or vectors X and Y define the axis limits only. % % See also MESH. % %
input: c is the colormap zpos is the vertical position of the contour plot.
error(nargchk(1,5,nargin)); if nargin==1, % Generate x,y matrices for surface z. z = x; [m,n] = size(z); [x,y] = meshgrid(1:n,1:m); elseif nargin==2, z = x; c = y; [m,n] = size(z); [x,y] = meshgrid(1:n,1:m); end if min(size(z))==1, error(’The surface Z must contain more than one row or column.’); end % Determine state of system cax = newplot; next = lower(get(cax,’NextPlot’)); hold_state = ishold; % Plot mesh. if nargin==2 | nargin==4, hm=mesh(x,y,z,c); else hm=mesh(x,y,z); end hold on; a = get(gca,’zlim’); if nargin ~= 5
161
162CHAPTER 5. MESH PLOTSSCIENTIFIC VISUALIZATION & INFORMATION ARCHITECTURE zpos = a(1); % Always put contour below the plot. end % if % Get D contour data [cc,hh] = contour3(x,y,z); %%% size zpos to match the data for ii = 1:length(hh) zz = get(hh(ii),’Zdata’); if zz(1) < 0 set(hh(ii),’LineStyle’,’--’,’LineWidth’,1); else set(hh(ii),’LineWidth’,2) end % if set(hh(ii),’Zdata’,zpos*ones(size(zz))); end if ~hold_state, set(cax,’NextPlot’,next); end if nargout > 0 h = [hm; hh(:)]; end
Appendix: Matlab code for Three-Dimensional, TwoLayer Contour Plot function h=contour_twolayer(x,y,zbottom,ztop,zpos,labelflagtop,labelflagbottom) % two layer plot ... the five arguments are mandatory % input: c is the colormap % Use colormap([0 0 0]); cmap = colormap; % to get black contour lines % zpos is the vertical separation in % between the two 3D contour plots % both the sixth and seventh arguments must be both used or % both omitted. labelflagtop=1 turns on inline contour labels. % and similarly labelflagbottom=1 labels the lower layer. % Convention: negative-valued contours are dashed and thinner than solid isolines. error(nargchk(5,7,nargin)); if nargin==5,labelflagtop=0; labelflagbottom=0;
end % if
if min(size(zbottom))==1, error(’The surface Z must contain more than one row or column.’); end % Determine state of system cax = newplot; next = lower(get(cax,’NextPlot’)); hold_state = ishold;
5.11. MESH PLOTS ON NON-RECTANGULAR DOMAINS
163
[ccbottom,hhbottom] = contour3(x,y,zbottom); for ii=1:length(hhbottom) zz = get(hhbottom(ii),’Zdata’); % all elements in zz equal zz(1) if zz(1) < 0, % Set negative-value contours to dashed set(hhbottom(ii),’LineStyle’,’--’,’LineWidth’,1); else set(hhbottom(ii),’LineWidth’,2), % Thicken positive-valued isolines end % if set(hhbottom(ii),’Zdata’,0*ones(size(zz))); % Flatten 3D contours to z=0 end % ii if labelflagbottom==1, textlabelhandles=clabel(ccbottom,hhbottom); set(textlabelhandles,’FontSize’,12); end % if hold on; [cc,hh] = contour3(x,y,ztop); if labelflagtop==1, textlabelhandles=clabel(cc,hh); set(textlabelhandles,’FontSize’,12); end % if for ii = 1:length(hh) zz = get(hh(ii),’Zdata’); if zz(1) < 0 set(hh(ii),’LineStyle’,’--’,’LineWidth’,1); else set(hh(ii),’LineWidth’,2) end % if set(hh(ii),’Zdata’,zpos*ones(size(zz))); % Flatten 3D contours to z=zpos end xmin=min(min(x)); xmax=max(max(x)); ymin=min(min(y)); ymax=max(max(y)); axis([xmin xmax ymin ymax 0 zpos]); % put rectangular horizontal frame around each contour plot xframe=[xmin xmax xmax xmin xmin ]; yframe=[ymin ymin ymax ymax ymin]; plot3(xframe,yframe,[0 0 0 0 0],’k’,xframe,yframe,[zpos zpos zpos zpos zpos],’k’) set(gca,’ZTick’,[]); % Remove ticks from z axis, which have no meaning here if ~hold_state, set(cax,’NextPlot’,next); end if nargout > 0, h = [hhbottom; hh(:)]; end
164CHAPTER 5. MESH PLOTSSCIENTIFIC VISUALIZATION & INFORMATION ARCHITECTURE
Chapter 6
Arrow/Vector Plots 6.1
Quiver/Arrow/Vector Plots/Porcupine Plot
To plot vectors, it is useful to draw arrows such that the direction in which the arrow points is the direction of the vector and the length of the arrow is its magnitude. Such plots are very popular in fluid mechanics, for example, where the flow velocity in a twodimensional plane is often illustrated this way. This strategy can be applied in either two or three space dimensions, but is rarer in three dimensions because software is not as readily available and because the arrows in the foreground tend to obscure arrows farther from the viewer. Unfortunately, there is no standard name for this type of plot: “arrow”, “quiver” and “vector” are all in common usage, and “porcupine” is used occasionally. Fig. 6.1 is an example. Advantages: 1. Easy, intuitive representation of vectors. Disadvantages: 1. Small magnitude vectors are depicted as dots. At these points, direction information is lost. 2. High velocity vectors may overlap adjacent gridpoints so that the arrows dissolve into a sea of confusing line segments 3. Because of the difficulties with both large and small magnitude vectors, it is difficult to represent a wide range of magnitudes in an arrow plot. 4. When superimposed on pseudocolor plots, a common option, the vectors may be hard to see against the bright colors.
6.2
Vector Plots Superimposed on Other Graphs
It is very common to superimpose vector plots on other graphs such as quiver plots. In black-and-white, the most common “combo” is vector-plot-on-contour-plot as exemplified by Fig. 6.2. In fluid mechanics, the contours are a scalar quantity such as pressure or temperature; the vectors are horizontal velocity. When color is available, the contour plot is often replaced by pseudocolor graph or by a filled contour plot, which is the superposition of a contour plot and a pseudocolor graph of the same variable as in Fig. 6.3. 165
166
CHAPTER 6. ARROW/VECTOR PLOTS
But what if one wants two scalar variables plus a vector? A good triple combo is to combine a pseudocolor plot of one with a contour plot of the second scalar plus a vector plot. The great pitfall of “combo” plots is that the pseudocolor graph tends to visually overwhelm the vector field. Only a well-motivated reader who studies the graph for a few seconds will identify the patterns in the vectors. Furthermore, because the colors of the pseudocolor image are varying, some vectors which are superimposed on dull hues may be rather difficult to see. Indeed, it was necessary to reduce the number of points in the grid to 21 x 21 so that the vectors would be readily visible in Fig. 6.3. The only vector arrows which are easily seen against the background of bold reds, yellows, and blues are big arrows. In black-and-white graphs, it is difficult to use the convention of showing negative-valued contours as dashed lines because the dashes are too faint to be easily distinguished from the vectors.
Vector alias Arrow alias Quiver alias Porcupine 1
y
0.5
0
-0.5
-1 -1
-0.5
0 x
0.5
1
Figure 6.1: A schematic two-dimensional vector field, plotting by drawing arrows who direction is that of that of the vector and whose length is proportional to the magnitude of the vector at that point in the (x, y) plane. The center of the field illustrates a generic defect of arrow plots: where the magnitude of the vector is small, the arrows are so short that it is difficult to percieve either their direction or relative magnitude.
6.2. VECTOR PLOTS SUPERIMPOSED ON OTHER GRAPHS
167
Superimposed Contour & Quiver Plots 3 2
y
1 0 -1 -2 -3 -3
-2
-1
0 x
1
2
Figure 6.2: Quiver (vector) plot superimposed on a contour plot of a different field. The vectors show the horizontal velocity with the length of the vector equal to the magnitude of the vector. The contours of the pressure or height field. (Equatorial Rossby wave, plotted versus longitude (x) and latitude (y).)
3
168
CHAPTER 6. ARROW/VECTOR PLOTS
superimposed vector & pseudocolor plots 3 0.7
y
2
0.6
1
0.5
0
0.4
0.3
-1
0.2
-2 0.1
-3 -3
-2
-1
0 x
1
2
3
Figure 6.3: Same as the previous figure except that the contour plot is replaced by a pseudocolor graph of the pressure. The density of the grid for the vectors had to be reduced only 21 x 21 so that the vectors would be sufficiently large to be visible when superimposed on the pseudocolor graph.
6.3. VECTORS DERIVED FROM SCALARS: GRADIENTS AND HAMILTONIAN-FIELD/STREAMFUNCTION FLOW
6.3
Vectors Derived from Scalars: Gradients and HamiltonianField/Streamfunction Flow
Arrow plots are used not only to plot quantities that are vectors in and of themselves, but these species of graph can be applied to analyze scalars by plotting vector fields derived from the scalar-valued quantity. In electrostatics, for example, the gradient of the potential is the electric field; in fluid mechanics, the gradient of the velocity potential gives the irrotational flow associated with the potential. The components of the gradient are (
∂f ∂f , ) ∂x ∂y
(6.1)
Similarly, in physics, one can define a “Hamiltonian gradient” which is a sort of skewed gradient. In fluids, the components of a nondivergent velocity field in two dimensions are related to the streamfunction ψ, which is a scalar, by u= −
∂ψ , ∂y
v=
∂ψ ∂x
(6.2)
The derived vector fields are sufficiently important that Mathematica has one-line plot commands to generate an arrow plot of the derived vector from an input of an array of values of the scalar: PlotGradientField and PlotHamiltonianField. Matlab does not, but does contain a built-in function [fx,fy]=gradient(f ), which will compute the gradient through finite differences. This makes it possible to compute either the gradient or “Hamiltonian gradient” in two lines.
170
CHAPTER 6. ARROW/VECTOR PLOTS
Contours of ψ 1 0.5 0 -0.5 -1 -1
0 Gradient
1
1
Hamiltonian/Flow from ψ 1
0.5
0.5
0
0
-0.5
-0.5
-1 -1
0
1
-1 -1
0
Figure 6.4: Upper left: contours of ψ = sin(πx) cos(πy). Lower left: vector plot of the gradient of ψ, (ψx , ψy ). Lower right: the vector field (−ψy , ψx ). This is called a “Hamiltonian gradient” by physicists and a “two-dimensional incompressible flow derived from the streamfunction ψ” by fluid dynamicists.
1
6.4. AREA QUIVER PLOTS
6.4
171
Area Quiver Plots
In this variant, the thickness and length of the arrows are both varied so that the magnitude of the vector is proportional to the area of the arrow rather than its length. A schematic example is shown in Fig. 6.5. Advantages: 1. One can represent a wider range of magnitudes without having the arrows shrink to dots or overlap one another. 2. strong currents are marked by thick arrows versus the thin arrows seen elsewhere, which makes the jets easier to identify. Disadvantages: Areas are more difficult for the eye to judge than lengths.
Figure 6.5: A variant of the vector or quiver plot in which the area of the vectors denotes the magnitude of the vector. (Note that this variant is rare; it is much more common to denote magnitude by the length of the vectors only.)
172
6.5
CHAPTER 6. ARROW/VECTOR PLOTS
Three-Dimensional Arrow/Vector/Quiver Plots
Matlab has command quiver3 to compute three-dimensional vector plots. Its syntax is linehandles=quiver3(x,y,z,u,v,w); where x, y, z are vectors of points that specify a point in space as (x(i), y(i), z(i)) and where u, v, w are arrays that specify the components of the three-dimensional vector field at these points. (Because early versions of Matlab could not handle three-dimensional vectors, the quiver3 function assumes that all its arguments are vectors; if the points lie on a rectangular array with nx points in x, ny points in y, and nz points in z, then each of the six input vectors is of length nxnynz.) The function returns an array of linehandles which can be used to manipulate the plot. The great disadvantage of three-dimensional quiver plots is that the projection of the three-dimensional array of arrows onto a two-dimensional flat screen or paper gives a very busy graph with limited depth cues so that is often impossible for the eye to make sense of it. Fig. 6.6, which shows the initial velocity for a celebrated fluid mechanics flow called the Taylor-Green flow, is an illustration. The Taylor-Green flow is an array of vortices, but one can derive only the vaguest sense of the vortices from the plot. Another drawback is to have any hope of making sense of the vectors, the grid of arrows must be rather coarse. The Taylor-Green plot on a denser grid is even more incompressible, but the 11 x 11 x 5 grid illustrated is very coarse, and obviously makes many of the finer features of the vector field invisible even in principle. (In practice, it is often difficult to perceive even the coarsest features of the field.) Because of these disadvantages, it is likely that widespread use of three-dimensional arrow plots will have to wait until either three-dimensional holographic computer displays or stereo computer monitor glasses are available. Still, one can fiddle with three-dimensional quiver plots to improve visualizability. Fig. ?? shows the same plot as in the previous figure except that changes have been made to make the diagram easier to comprehend: 1. Grid is reduced to 6 x 6 x 3. 2. Different vertical levels are color-coded: red at the top, black in the middle, and blue at z = 0. 3. Only 1/8 of the period box is illustrated. The reduction of the volume which is illustrated by a factor of two in each dimension is possible because the Taylor-Green flow is the product of trigonometric functions of period two. It follows that knowledge of the flow in the box [0, 1]x[0, 1]x[0, 1] is sufficient to depict the flow in the remaining seven cubes of the period box.
6.5. THREE-DIMENSIONAL ARROW/VECTOR/QUIVER PLOTS
173
Initial velocity: Taylor-Green vortex
1
z
0.5 0 1
-0.5 0.5
-1 -1
0
-0.5 0
-0.5 0.5
1 -1
y
x Figure 6.6: A three-dimensional vector field, the initial velocity for the Taylor-Green flow of incompressible, homogeneous turbulence theory. The components are u = sin(πx) cos(πy) cos(πz), v = − cos(πx) sin(πy) cos(πz), w = 23 cos(πx) cos(πy) sin(πz).
174
CHAPTER 6. ARROW/VECTOR PLOTS
Taylor-Green vortex: 1/8 of period box
1 0.8
z
0.6 0.4 1
0.2 0.5 0 0
0.2
0.4
0.6
0.8
1
0
x Figure 6.7: A three-dimensional vector field, the initial velocity for the Taylor-Green flow of incompressible, homogeneous turbulence theory. The components are u = sin(πx) cos(πy) cos(πz), v = − cos(πx) sin(πy) cos(πz), w = 23 cos(πx) cos(πy) sin(πz).
y
Chapter 7
Drawing 7.1
Why Draw?
Artists draw, architects draw, graphic designers draw, cartoonists draw, but scientists and engineers mostly plot. There are several circumstances in which scientists are forced to draw, too, including: • To make schematic diagrams. • To annotate or elaborate the graphs plotted by Matlab or other plotting software. • To trace part or all of a scanned image.
Many articles contain schematic diagrams: the layout or design of experimental apparatus, a computer program flow chart, a graph of boxes and arrows to indicate the relationships between concepts. The sine function can be graphed in Matlab because it is described by a mathematical formula, but what algorithm describes the structure of a mass spectrometer? The crucial reason that drawing is needed is that: Mathematics can be plotted but concepts must be drawn. Plotting software has shown a steady increase in the range of options for annotating a graph. Matlab, for example, has only recently added the capability to interpret strings as Latex code, thereby making it easy to add Greek letters, subscripts and complete mathematical expressions to graphs. Nevertheless, in the continuing “arms race” between technology and the aspirations and inventiveness of scientists and engineers, it still seems to be a common occurrence to want more than the plotting software is presently able to provide. Drawing programs like Adobe Illustrator, since their whole purpose is to create dazzling curves, text and shapes, always offer bells-and-whistles far beyond those of plotting software. A good strategy is to plot the graph as elaborately as possible within Matlab (or other plotting software) and then append additional labels, legends and shapes within a drawing program. A crucial technical point is that many graphical formats which Matlab supports as output-to-a-file are also supported as import-from-a-file by illustration software. An equally crucial conceptual point is that many of the options available within a graph library are really drawing rather than plotting capabilities. Scanners are a great boon to technical graphics because many journal papers contain one or more figures borrowed from previous work. These “history” graphs provide a context for the new work to come. Unfortunately, “as-is” reproduction is often unsatisfactory. The original source may have used different notation and different scales 179
180
CHAPTER 7. DRAWING
and have displayed five variables where only one is needed for the introduction of the current work. The pre-scanner strategy for altering a previously-published figure was to have a xerox traced and redrawn by a professional draftsman. Unfortunately, such artists have become an endangered species. Furthermore, the scientist is still responsible for making the technical decisions: what to plot, where to plot it, what and how to label. The modern strategy is “scan-and-draw”. A scanner is a xerox machine that uses the laser trace of the document placed on its glass plate to write a computer file instead of to attach a spot of ink to paper. The scanned image can be reprinted “as-is”. If it needs modification, these must be performed using a drawing program. The scanning software that controls the image capture always incorporates a limited suite of drawing tools. The scanned image must be cropped, usually rotated a little to compensate for twisting of the original, and stray marks erased. If notation needs to be changed or the labels altered, then this demands a second stage of processing through a program like Adobe Illustrator.
7.2
Illustrating with TeX and Postscript
The book by Goosens, Rahtz and Mittelbach(1997) describes several wyas to create illustrations directly in Latex. One strategy is to use Postscript commands. This is satisfactory for drawing simple polygons, arcs, and schematics. A second strategy is to use a special-purpose package. TeX and LaTeX afficionados have developed sets of macro commands which are catalogued in Goosens et al.(1997). Specialized packages include: • Feynman diagrams (particle physics) [FeynMF] • chemical [XYMTEX] • music [MusiXTEX, abc2mtex, MPP, midi2tex] • chess [chess] • other games including Go, Xiangqi (Chinese chess), backgammon, bridge and
crosswords The package Xy-pic is particularly powerful. It can be used to create complicated diagrams with arrows, matrix-like structures connected by arrows, finite-state diagrams, directed graphs and flow charts, circuit diagrams, two-cell diagrams, arcs, circles and ellipses. The special purpose packages may be the best option for specialized applications. However, they are much more limited than general purpose drawing packages. As we shall explain in the rest of the chapter, it is fairly easy to generate a standard Feynman bubble diagram or wavy line either in a drawing program or as the output of a Matlab, Maple or Mathematica function. This standard element is easily resized, rotated and translated either in drawing software or scientific software. One can easily build up a rather complex diagram out of a handful of standard elements.
7.3. DRAWING IN MATLAB
7.3
181
Drawing in Matlab
7.3.1 Introduction Matlab, although not designed to be a drawing program per se, is nevertheless capable of creating very complicated images. The disadvantage of drawing in Matlab is that it lacks the convenient, mouse-driven drawing tools of a program like Adobe Illustrator. The strength of Matlab is the power to draw-by-algorithm. If one needs to create an image with a complicated shape but knows a mathematical formulation for computing the points of the shape, then Matlab may be greatly superior to an illustration program. Fig. 7.1 is a sampler of drawings created entirely in Matlab. Each insect and each child was drawn by repeatedly calling a single function with arguments that specified the position and size of each figure. The functions were borrowed from Nakamura (1996) and no doubt required a good deal of debugging and fiddling to get the shapes just right. It is almost always faster to draw a single insect or stick-person with an illustrator program than with Matlab. However, for “volume production”, Matlab is just as fast or faster. One can duplicate and move copies of a subfigure in an illustration program, but it is just as quick to invoke a function with a translated argument in Matlab. One could draw an assortment of circles of random diameters at random locations using the circle-drawing tool of an illustration program, but each circle would then have to be drawn individually. When the copies are not identical, manually rescaling and moving them in an illustration program becomes quite tedious.Furthermore, Matlab’s rand function ensures that the random sizes and positions are really random — or at least really pseudo-random. In a similar spirit, the plane was created using a standard wing shape defined by a mathematical algorithm. The same wing section was employed, with rescaling and translation, for both halves of the main wing, both tailplanes, and the rudder.
182
CHAPTER 7. DRAWING
Children Running Home Commuter Airplane
5 0
-5 5 0 -5
-2
0
2
Figure 7.1: A potpourri of drawings in Matlab, taken from the book by Nakamura(1996) .
4
6
8
7.3. DRAWING IN MATLAB
183
7.3.2 Importing Images Into Matlab Matlab can import a variety of graphic formats and display them using its image family of commands. After invoking hold on, one can then modify these pictures by overlaying additional graphs and text. Finally, the modified picture can be printed or saved to a file. The most important limitation on import is that although Matlab can save figures as Encapsulated Postscript (EPS) and, on the Macintosh, PICT files, it unfortunately cannot import either of these formats. However, Matlab can directly import other popular formats such as TIFF and JPEG. Adobe Illustrator can import EPS files and save them as TIFF or JPEG; specialized graphic converters such as the shareware GraphicConverter (on the Macintosh) will also do the necessary file conversion. Once one has a file in an importable format, the statements [Simage Smap]=imread(’SailingShiponReef’,’tiff’); xa=linspace(-1,1,30); ya=linspace(-1,1,40); imagehandle=image(xa,ya,Simage); will read and display an image. The first argument of imread is the file name (with the termination .fmt omitted) and the second argument is the file format. The linespace commands (not part of the image family) are used to create vectors to define the horizontal and vertical axes. The image command actually uses only the first and last elements of the vectors so that imagehandle=image([-1 1],[-1 1],Simage); would actually produce the same image with the same axis scales and tick marks.
7.3.3 Tracing an Image in Matlab The command ginput puts a cross-hair cursor on the screen, and then stores the x and y values of the location of the mouse each time it is clicked until the function is terminated by hitting the Return key. The syntax is [x,y]=ginput This command is very powerful because it allows one to easily trace parts of images. The arrays x and y can then be transferred by a copy-and-paste operator to a function subprogram which will then be able to reproduce the traced curve every time that it is called.
7.3.4 Translating, Rescaling and Rotating To exploit a function that draws an image effectively, we need to be able to translate, rescale (or “dilate”) and rotate the image. This is rather easy to do. We can build the necessary properties into a standard image-drawing template. We can then retitle the template and pop in vectors that define the image for some standard size and orientation, and away we go! For example, a two-dimensional template is given by
184
CHAPTER 7. DRAWING
function linehandles = Drawtemplate2D(x0,y0,dilation,rotation hold on % Part I: Define arrays x, y which contain the points for % the figure with center at x=0,y=0, % dilation=1 and rotation angle=0 % Translate, dilate and rotate arrays x,y xxxx=x0*ones(1,length(x)) + dilation*(x*cos(rotation) - y*sin(rotation)); yyyy=y0*ones(1,length(x)) + dilation*(x*sin(rotation) + y*cos(rotation)); handle1=plot(xxxx,yyyy,’k-’); hold off linehandles=handle1;
% plot arrays xxx, yyy
The first step in the function is to generate an array of points for the figure in canonical form: a certain standard position, orientation and size. For example, to generate a square with sides normalized to a length of two and sides parallel to the x and y axes:
x=[-1 1 1 -1 -1]; y=[-1 -1 1 1 -1]; The second step is to translate, dilate and rotate the arrays of points. The rotation is performed by multiplying each (x, y) pair of points by a two-by-two rotation matrix whose elements are cosines and sines of the rotation angle:
xx=x*cos(rotation) - y*sin(rotation); yy= x*sin(rotation) + y*cos(rotation); “Dilation” means resizing the figure in all its dimensions by multiplying by a constant dilation:
xxx= dilation*xx; yyy= dilation*yy; The transformation which translates the figure from a center at (0, 0) to a figure whose center is at (x0 , y0 ) is
xx = x + x0,
yy = y + y0
The last line of the template ensures that the function returns a handle to lines graphed by the plot command. One can then further manipulate the object in the main program (called a “script”) in Matlab or directly from the command line. The syntax is
7.3. DRAWING IN MATLAB
185
set(linehandle,’Color’,’g’,’LineWidth’,2,’LineStyle’,’:’) to change the color of all lines in the function’s figure to green, alter the width to 2 pts (where one point = (1/72) of an inch) and change the lines from solid to dotted. As an example of two-dimensional figure drawing, the complete code to compute an ellipse of arbitrary size, position and orientation and arbitrary semimajor and semiminor axes is given in Matlab by
function thandle= ellipB(x0,y0,dilation,rotation,rx,ry) % x0, y0: coordinates of center point % rx, ry: radii in x and y directions % Part I: Compute ellipse with axes parallel to % x and y axes and center at (0, 0) delt = 2*pi/30; t = 0:delt:2*pi; x=rx*cos(t); y = ry*sin(t); % Translate, dilate and rotate the ellipse xxxx =x0 + dilation*(cos(rotation)*x - sin(rotation)*y); yyyy =y0 + dilation*(sin(rotation)*x + cos(rotation)*y); thandle=plot(xxxx,yyyy,’k-’); The ellipse routine takes two extra arguments, omitted from the template, to specify the radii of the ellipse, which are equal to half the axes. It will often be necessary to add extra arguments that are specific to a particular species of figure. However, the translation, dilation and rotation lines are exactly as in the template. Fig. 7.2 illustrates the result. The color, line width, and linestyle was changed by using the set command in the calling script. The filled ellipse was produced by creating a new function, ellipBfill, which added fill(xxxx,yyyy,colorstring) just after the plot statement, and appended one new argument, the colorstring. One could have combined these two functions into a single function with a variable number of arguments, but it seemed less confusing to have two different functions.
186
CHAPTER 7. DRAWING
Figure 7.2: An assortment of ellipses of various rotation angles and sizes (dilations). The colors and linestyles were altered in the calling script using the set command, applied to the line handle returned by the ellipse-drawing function, ellipB.
7.3. DRAWING IN MATLAB
187
A three-dimensional template is
function h=Drawtemplate3D(x0,y0,z0,dilation,rotx,roty,rotz) % (x0,y0,z0) is center of the figure (Cartesian coordinates) % dilation = size, relative to the default size % rotx = rotation angle about x-axis % roty = rotation angle about y-axis % rotz = rotation (radians) about z-axis hold on % FIRST BLOCK: define the points of the figure % as the arrays x,y,z in Cartesian coordinates. FUNCTION-SPECIFIC STUFF GOES HERE % Create the rotation matrices xcos=cos(rotx); xsin=sin(rotx); ycos=cos(roty); ysin=sin(roty); zcos=cos(rotz); zsin=sin(rotz); % rotation around the x-axis xx=x; yy=xcos*y - xsin*z; zz=xsin*y + xcos*z; % rotation around the y-axis yyy=yy; xxx=ycos*xx + ysin*zz; zzz=-ysin*xx + ycos*zz; % rotation around the z-axis xxxx=zcos*xxx-zsin*yyy; yyyy=zsin*xxx+zcos*yyy; zzzz=zzz; % Dilation xxxx=dilation*xxxx; yyyy=dilation*yyyy; zzzz=dilation*zzzz; % Translation xxxx = xxxx + x0*ones(size(xxxx)); yyyy = yyyy + y0*ones(size(xxxx)); zzzz = zzzz + z0*ones(size(xxxx)); h=plot3(xxxx,yyyy,zzzz,’k-’); hold off There are seven parameters: three to specify the location of the center of the figure (x0, y0, z0), plus the size parameter dilation plus the three rotation angles. The dilation parameter specifies the size of the figure on the screen relative to the figure of standard size which is defined by the first block in the subroutine (where the arrays x, y, z must be computed). For example, if x, y, z specify a cube with unit sides, then dilation = 3 will graph a figure whose sides are all equal to three. Just as for the two-dimensional template, rotations are in radians in a counterclockwise direction. The next listing shows an instance of this three-dimensional template, a routine for computing a cube. The canonical figure, computed by the first block of lines, is a cube
188
CHAPTER 7. DRAWING
with unit sides. The centroid of the canonical figure is at the origin so that the vertices are at x = ±1/2, y = ±1/2, z = ±1/2. The line segments that define the sides are oriented so as to be parallel to the coordinate axes. The unit cube is by plotting each face as a square and then plotting four line segments to connect the two faces, vertexto-vertex. Each face is specified by five points, even though a square face has only four vertices, because one vertex must be duplicated so that the plotted line segments will form a closed curve. It is easy to generalize this listing to compute three-dimensional parallelpipeds, prisms and so on. However, when the sides are not all equal, one must add additional arguments to the seven parameters of the template to describe the shape of the canonical figure. The listing could also be generalized by adding parameters to specify the color of the figure, linestyle, linetype and so on. Matlab’s vargin allows one to call the function with a variable number of arguments so that optional parameters, such as color and linestyle, can be left out of the calling statement unless one wishes to change the defaults. For simplicity, the listing eschews such refinements, implicitly assuming that the color, linestyle and thickness will be changed by a set statement in the calling program. Fig. 7.3 is a sample of the cubes produced by the listing. The circle of cubes was drawn by embedding the function in a for ... end loop such that the rotational angle about one axis varied through 2π and the translation (x0, y0) was moved in a circle (with z0 = 0).
7.3. DRAWING IN MATLAB
189
function handles=cube3B(x0,y0,z0,dilation,rotx,roty,rotz) % (x0,y0,z0) is center of the figure (Cartesian coordinates) % dilation = length of sides of the cube. % rotx = rotation about x-axis roty = rotation, y-axis % rotz = rotation (radians) about z-axis, hold on % FIRST PART: Cube with UNIT SIDE and CENTER at x=0,y=0,z=0 x=[0 1 1 0 0] - 0.5*ones(1,5); % Five points define one face y=[0 0 1 1 0] - 0.5*ones(1,5); z=[0.5 0.5 0.5 0.5 0.5]; x=[x x]; y=[y y]; z=[z -z]; % Second face % Four parallel line segments to connect the faces x=[x -0.5 -0.5 0.5 0.5 0.5 0.5 -0.5 -0.5]; y=[y -0.5 -0.5 -0.5 -0.5 0.5 0.5 0.5 0.5]; z=[z -0.5 0.5 -0.5 0.5 -0.5 0.5 -0.5 0.5]; % Create the rotation matrices xcos=cos(rotx); xsin=sin(rotx); ycos=cos(roty); ysin=sin(roty); zcos=cos(rotz); zsin=sin(rotz); % rotation around the x-axis xx=x; yy=xcos*y - xsin*z; zz=xsin*y + xcos*z; % rotation around the y-axis yyy=yy; xxx=ycos*xx + ysin*zz; zzz=-ysin*xx + ycos*zz; % rotation around the z-axis xxxx=zcos*xxx-zsin*yyy; yyyy=zsin*xxx+zcos*yyy; zzzz=zzz; % Dilation xxxx=dilation*xxxx; yyyy=dilation*yyyy; zzzz=dilation*zzzz; % Translation xxxx = xxxx + x0*ones(1,18); yyyy = yyyy + y0*ones(1,18); zzzz = zzzz + z0*ones(1,18); handles=plot3(xxxx(1:5),yyyy(1:5),zzzz(1:5),’k-’,... xxxx(6:10),yyyy(6:10),zzzz(6:10),’k-’,... xxxx(11:12),yyyy(11:12),zzzz(11:12),’k-’,... xxxx(13:14),yyyy(13:14),zzzz(13:14),’k-’,... xxxx(15:16),yyyy(15:16),zzzz(15:16),’k-’,... xxxx(17:18),yyyy(17:18),zzzz(17:18),’k-’); hold off
190
7.4
CHAPTER 7. DRAWING
Affine Transformations
The transformations illustrated in the Matlab code in the previous sections are special cases of so-called “affine transformations”. For simplicity, the codes were restricted to translation, dilation, and rotation. It is easy to add the full range of affine transformations, however. Definition 13 (Affine Transformation) An affine transformation from old coordinates (x, y) to new coordinates (x , y ) is one that can be expressed as a matrix multiplication plus addition of a vector (translation): x a b x x0 + (7.1) = c d y y0 y and similarly in three dimensions. A number of special cases of affine transformations are worth noting: 1. Pure translation by (x0 , y0 ): Matrix is zero; all points are translated by (x0 , y0 ) 2. Plane Rotation through angle θ about the origin: (x0 = 0, y0 = 0) and the matrix is cos(θ) − sin(θ) Rθ ≡ sin(θ) cos(θ)
(7.2)
3. Plane Rotation through angle θ about a point (xc , yc ): Denote the point (x, y) by the vector p and similarly (xc , yc ) ≡ pc . Then p = Rθ (p − pc ) + p
(7.3)
where the rotation matrix is the same as defined in the previous item. In words, one translates from pc to the origin, performs the rotation, and then translates back to the point pc . 4. Uniformation dilation: diagonal matrix with all diagonal elements equal to the scaling factor λ: λ 0 (7.4) Dλ ≡ 0 λ 5. Nonuniform Dilation or Scaling: diagonal matrix with diagonal elements equal to the two different scaling factors λ, µ, respectively: λ 0 Dλ,µ ≡ (7.5) 0 µ 6. Inversion with Respect to the Original: diagonal matrix with diagonal elements equal to -1 (x = −x, y = −y): −1 0 I≡ (7.6) 0 −1 Inversion preserves the orientation (“handedness”) of a figure.
7.4. AFFINE TRANSFORMATIONS
191
7. Reflection with Respect to the x-axis: diagonal matrix with diagonal elements equal to one and minus one (x = x, y = −y): 1 0 (x) (7.7) ≡ Re 0 −1 Reflection always reverses orientation. 8. Reflection with Respect to the y-axis: diagonal matrix with diagonal elements equal to minus one and one (x = −x, y = y): −1 0 (x) Re ≡ (7.8) 0 1 9. Shear: x direction (x) Sλ
1 ≡ 0
λ 1
(7.9)
In fluid mechanics, advection in the x-direction by a flow that varies only with y produces an x-shear. y = y, so the “flow” does not alter the y coordinate. However, the x-coordinate is translated in the x-direction by an amount that depends on how far the point is from the origin, that is, by how large y is. 10. Shear: y direction (y) Sλ
1 ≡ λ
0 1
(7.10)
11. Strain: x direction. Diagonal matrix with the top diagonal element equal to λ and the lower diagonal element equal to one. λ 0 (x) Tλ ≡ (7.11) 0 1 This is a special case of a non-uniform dilation; shapes are distorted or “strained” because only the x-coordinate is stretched or compressed. 12. Strain: y direction. Diagonal matrix with the top diagonal element equal to one and the lower diagonal element equal to λ. 1 0 (y) (7.12) Tλ ≡ 0 λ This is a special case of a non-uniform dilation; shapes are distorted or “strained” because only the y-coordinate is stretched or compressed. y), the affine transform If a figure or object is defined by a discrete set of points (x, may be applied one-pair-of-points-at-a-time to transform the entire object. The general affine transformation can be decomposed into the product (i. e., successive application) of elementary affine transformations in the list above. Definition 14 (Isometry) This is an affine transformation which is a “rigid-body” motion of a figure. Distances between all points of the object are preserved under an isometry. Any combination of translation, rotation and reflection is is an isometry; dilations, shears and strains are not isometries.
192
CHAPTER 7. DRAWING
Theorem 1 (Isometry) There are four isometries in the plane: 1. translation 2. rotation 3. reflection 4. glide reflection The determinant of the 2 × 2 transformation matrix is equal to ±1 where orientation is preserved for the (+) case and reversed when the determinant is −1. Definition 15 (Glide Reflection) A “glide reflection” is a combination of translation with reflection with respect to a fixed line. Theorem 2 (Affine Transformation of Objects) Under an affine transformation, • Straight lines transform into straight lines. • Conic sections transform into conic sections • A curve of degree n, that is, a curve specified implicitly as the zero curve (algebraic
variety) of a polynomial in x and y of degree n, is transformed into a curve of degree n. Circles, ellipses, parabolas and hyperbolas are all curves of degree 2, i. e., conic sections. Under an affine transformation, an ellipse can be transformed into a circle or vice-versa. However, a curve that opens to infinity such as a hyperbola cannot be transformed into a closed curve like an ellipse. Geometry (and computer graphics) make heavy use of so-called “projective” transformations. Although we shall not explicitly discuss them here, the new coordinates (x , y ) are rational functions of the old coordinates. Projective transformations can be easily incorporated into algorithmic drawing routines also. Indeed, invisible to the user, Matlab is performing projective transformations whenever the viewing angle is changed by the Matlab view command.
7.4. AFFINE TRANSFORMATIONS
193
Figure 7.3: An assortment of three-dimensional cubes of various rotation angles and sizes (dilations) as computed by cube3B. The spheres at the vertices of the central cube were created by using set(linehandles,’Marker’,’.’,’MarkerSize’,30) where “linehandles” is returned by the function cube3B.
194
7.5
CHAPTER 7. DRAWING
Fractals: When the Algorithm is Mightier Than the Brush
Fractals, which are objects of complicated, self-similar structure with non-integral “capacity dimension”, occur in many branches of science and engineering and art. To draw a tree or bush is very labor-intensive because a realistic image requires a large number of individual brush strokes or pencil lines. In 1968, A. Lindenmayer introduced a family of algorithms, now known as “Lsystems”, to model the growth of living organisms, especially the branching of plants and trees. P. Prusinkiewicz later refined L-systems to a high art and published a book showing the great success of himself and others in generating very life-like plants and trees through L-systems rather than freehand drawing. Fig. 7.4 is an example.
Figure 7.4: A bush-by-algorithm: Prusinkiewicz L-system.
a realistic-appearing bush generated by a
7.5. FRACTALS: WHEN THE ALGORITHM IS MIGHTIER THAN THE BRUSH
195
Other objects of great complexity can be generated by very simple algorithms. The famous von Koch snowflake is constructed through an iteration in which the middle of each line segment is erased and replaced by two segments at an angle as illustrated in Fig. 7.5. The length of the curve increases without bound with each iteration, but the entire, infinitely long curve can always be enclosed within a rectangle of finite area. Although artists have drawn beautiful trees for centuries without benefit of either mathematics or computers, it is hard to argue that for such complicated objects, the algorithm is the faster way. Drawing in Matlab is particularly appropriate for fractals. For other kinds of graphical elements, it may be much faster to draw the object with a mouse or pen in an illustration program than in Matlab. With a pen, one can extend the curves to just the right length before clicking to fix the endpoint. In Matlab, the curves are specified as collections of points, and one may have to fiddle and fume for a long time before the points are just right. Matlab is good for dodecahedrons and trees; Matlab is not good for faces.
Figure 7.5: Six stages in the construction of the von Koch Snowflake. This curve, in the limit of an infinite number of stages, has an infinite length but encloses a bounded area.
196
7.6
CHAPTER 7. DRAWING
Splines
In drafting, a “spline” is a thin strip of wood which is used to draw curves. Polynomial spline interpolation was developed by I. J. Schoenberg, an expatriate mathematician who spent the war years in a government laboratory where he saw draftsmen translating his calculations into graphs. In those pre-computer days, each graph was drawn from a very small number of plotted points: How were the gaps filled? To Schoenberg’s amazement, the answer might be dubbed: Good Math from Carpentry. The draftsmen put pins into the paper at each of the calculated points, then snaked a thin strip of wood between the pins. The wood resisted bending: it spontaneously assumed the flattest shape consistent with the constraints of the pins. The draftsmen then interpolated between the computed points (pins) by tracing the shape of the spline. A simpler procedure would be to connect each pair of points by a straight line. Such a piecewise linear graph would be quite unsatisfactory because, with only a small number of points, the graph would have very noticeable first derivative discontinuities. In contrast, the shape of the spline was continuous in all its derivatives. A smooth appearance isn’t enough, however; the curves need to be accurate. However, the springiness of the spline ensured that it curved only as much as necessary to interpolate (that is, go through) all the computed points. A little research and some conversations with engineers convinced Schoenberg that the spline minimized its curvature, subject to the interpolation constraints: it was the curve of smallest second derivative that intersected all the points. Schoenberg was moved to pose a mathematical problem: Suppose one approximated a function f (x) by a piecewise cubic polynomial, different for each interval between two interpolation points. The interpolation conditions at each endpoint of the interval give two conditions, but a cubic polynomial has four. Schoenberg demanded that the approximation minimize the curvature of the cubic polynomial. He showed that this condition was equivalent to the statement that both the first and second derivative of the piecewise cubic polynomial had to be continuous at the interpolation points even though different polynomials were used on either side of a given point. This gave enough conditions to uniquely determine the cubic polynomials for each interval of the entire domain. Schoenberg’s cubic-spline, often shortened to “c-spline” today, was a rousing success. It is a built-in option for Matlab’s interpolation routines, and is included in every major library of numerical software. Unfortunately, splines have a drawback: the continuity conditions at the interpolation points imply that all the coefficients of the cubic polynomials must be found simultaneously; if even one point is altered, then the whole curve must be recomputed. Splines are very powerful for “algorithmic drawing”, as in Matlab. Many engineering design programs make heavy use of splines. However, drawing programs like Illustrator make use of a related but alternative strategy for drawing smooth curves between a limited number of fixed points.
7.7
Bezier Curves
7.7.1 Bernstein and Bezier: History Around 1870, Karl Weierstrass proved an amazing theorem: any function f (x), even if it was not continuous, could be approximated to arbitrarily high accuracy on an interval by a polynomial of sufficiently high degree. His proof was nonconstructive,
7.7. BEZIER CURVES
197
alas. Polynomial interpolation was known, but around the turn of the century, Karl Runge discovered that interpolation with evenly spaced points could diverge even for a function that was analytic and smooth everywhere on the target interval. In 1912, Bernstein resolved the paradox by devising a noninterpolating polynomial approximation which was guaranteed to converge to any function for which Wierstrass theorem applies. Hurrah! Well, not quite. Unfortunately, Bernstein’s approximation converges so slowly that the error at each point where f is continuous is asymptotically C(x)/N where C is a function only of x and N is the degree of the approximating polynomial (Voronovsky’s Theorem). Approximation theorists have been intrigued by Bernstein’s polynomial ever since; among their amazing properties is that the Bernstein approximant of a convex function is always convex, and the approximant of a monotonic function is always monotonic. However, numerical analysts and engineers washed their hands of Bernstein’s intriguing polynomials because of their very slow rate of convergence. The situation changed in 1959 when the French car company Citro¨ en hired a mathematician named Paul de Fajet de Casteljau to make a link because two-dimensional blueprints, then the standard result of engineering design, and Citro¨ en’s computer-
Piecewise Line: Slope Discontinuous
Splines: Continuous & Curvature-Minimizing
Figure 7.6: Top: piecewise linear approximation (dashed) of a function (solid). Bottom: spline interpolation where the dashed brown line is the wooden spline, and the curve traced around it, and the red disks are the interpolation points where pins are placed to constrain the spline.
198
CHAPTER 7. DRAWING
controlled milling machines. He invented what are now called “B´ ezier curves”. These are really just Bernstein approximants in a parameter t, t ∈ [0, 1], that parameterizes the curve. His crucial conceptual breakthrough was to realize that high numerical accuracy was not important because the car designers had traced curves on the blueprints using rather inaccurate methods — artistic insight and curving sheets of plastic called “French curves”. It was far important to feed a curve to the milling machine that was very smooth — that was what the engineers were trying to trace on the blueprints anyway. A wiggly curve would drive the milling machine nuts, increase cost, spoil aerodynamics, increase the difficulty of painting the car body, and generally be a VERY BAD THING. Because the Bernstein approximants are convex when the underlying curve is convex, and monotonic when monotonic, the Bernstein approximants never add spurious wiggles, but instead do a good job of smoothing the imperfections of curves traced on blueprints using mechanical drawing instruments. Citro¨ en tried to keep de Faget de Casteljau’s discovery top-secret-crypto, which is why he never received full recognition. In time, though, a mechanical engineer at rival R´ enault, Pierre B´ ezier learned enough about Citro¨ en’s system to recreate it. In contrast to Citro¨ en, R´ enault allowed B´ ezier to publicize his work widely. B´ ezier curves have dominated Computer-Aided Graphic Design (CAGD) for the last forty years. In 1972, Gordon and Riesenfeld showed that B´ ezier curves were just a special case of B-splines, which allowed a unification among computer systems for CAGD. The B´ ezier curves have continued to dominate drawing programs although B-splines are more widely used for approximation when the function to be approximated is known accurately.
7.7.2 Bernstein Polynomials “The Bernstein approximation of a continuous function lies between the extreme values of the function itself. . . . Monotonic and convex functions yield monotonic and convex approximants. In a word, . . . , the Bernstein approximants mimic the behavior of the function to a remarkable degree.” “[The convergence rate] is far slower than what can be achieved by other means. If f is bounded, then at a point where d2 f /dx 2 exists and does not vanish, BN (f ; x) converges to f (x) precisely like C/n. . . . This fact seems to have precluded any numerical application of Bernstein polynomials from having been made. Perhaps they will find application when the properties of the approximant in the large are more important that the closeness of the approximation.” P. J. Davis(1975)[?], pg. 116 of his book. As de Faget de Casteljau and B´ ezier recognized, engineering design and drawing are not problems in approximation of a function that is already completely and precisely defined. Rather, the goal is to create new smooth curves. The convexity and monotonicity properties of the Bernstein polynomials ensure that B´ ezier curves have very good “properties of the approximant in the large”. Definition 16 (Bernstein Polynomials) The N-th Bernstein polynomial that approximates a function f (x) is BN (f ; x) ≡
N j =0
f (j/N)
N j
x j (1 − x)N −j
(7.13)
´ZIER CURVES 7.8. BE
199
or equivalently BN (f ; x) ≡
N
fj
j =0
B (x; N)
(7.14)
j
where fj are the values of f (x), the function being approximated, at a set of evenly spaced grid points on the interval x ∈ [0, 1] and where the j (x; N) are the Bernstein basis functions. The binomial coefficient is N N! = (7.15) j (N − j)! j!
B
[function binomial(N,j) in Matlab, my program.] Definition 17 (Bernstein Basis Functions) N x j (1 − x)N −j j (x; N) ≡ j
B
7.8
(7.16)
B´ ezier Curves
Notation: let bi denote a set of control points in either two or three dimensions: xi xi (7.17) bi ≡= or bi ≡= yi yi zi Then the explicit form of the Bezier curve is b=
N j =0
bj
B (t; N)
(7.18)
j
Bernstein-basis functions; tenth degree 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0
0.2
0.4
0.6
0.8
1
x
Figure 7.7: The Bernstein basis functions,
B , j = 0, . . . 10 of degree N. j
200
CHAPTER 7. DRAWING
where t ∈ [0, 1] is the continuous variable that parameterizes the curve. In words, each of the functions (x[t], y[t], z[t]) is approximated by a Bernstein approximation of the same degree. The Bezier curve (and therefore the Bernstein polynomials) can also be evaluated recursively by the “de Casteljau” algorithm (Farin, 2001) brj = (1 − t)bjr −1 + tbjr+−11 , r = 1, 2, . . . N, j = 0, . . . , N − r
(7.19)
b = b0j
(7.20)
Then
Definition 18 (Control Points and Polygon) The points bj are called the “control points” of the B´ ezier curve; note that the curve interpolates only the two endpoints. The polygon formed by connecting the control points by straight lines in order is called the “control polygon”. Theorem 3 (B´ ezier Curve Properties) passes exactly through b0 and bN .
1. Endpoint interpolation: the curve always
2. Invariance under affine maps, which is any transformation that can be expressed as a matrix connecting (x, y, z) with (x , y , z ) plus a translation. 3. Convex hull property: b lies in the convex hull of the control polynomial. 4. Linear precision: if the control points are evenly spaced on a straight line, then the B´ ezier curve is the linear interpolant between b0 and bN and in fact interpolates all control points. 5. Variation diminution: no straight line (in two dimensions) or plane (in tree dimensions) intersects the curve more often than the control polygon. This property accounts for the shape preservation property of B´ ezier curves. Unproperty: B´ ezier curves are NOT invariant under projective maps although socalled “rational B´ ezier” curves can be constructed which do have this property. The derivative of a B´ ezier curve is a B´ ezier curve: N −1 db(t) =N ∆bj dt j =0
B (x; N − 1) j
(7.21)
where ∆ denotes the forward differences, i. e., ∆bj = bj +1 − bj
(7.22)
Drawing programs normally use cubic B´ ezier curves and create the curves by specifying the control points as explained in the next subsection. In industry, however, B´ ezier curves are also used to approximate curves that have been measured experimentally or from a clay model. To smooth out measuring errors, the usual strategy is a least-squares fit of a B´ ezier curve of modest degree, such as a quintic polynomial, to a much larger number of measured points (such as seventy points).
´ZIER CURVES 7.8. BE
201
7.8.1 Corner Points and Smooth Points Drawing programs such as Adobe Illustrator typically represent complicated shapes as composite B´ ezier curves of third degree. The overall shape is composed of a number of separate but connected pieces, each of which is a different cubic polynomial in a parameter t. Each piece consists of two endpoints, which are actually on the curve, plus two additional control points which are near but not on the cubic curve. If the right endpoint of one segment is the same as the left endpoint of the adjoining segment, then the composite B´ ezier curve will automatically be continuous. The slopes may or may not be continuous. At a “corner point”, in Illustrator parlance, the slopes of two adjoining segments are different. At a “smooth point”, however, the slopes must match so that the composite curve is continuous. It is proved in many CAGD books such as Mortenson(1999, pg. 266) that the slope of a cubic B´ ezier curve at an endpoint is equal to that of the straight line connecting that endpoint with the nearest control point. This implies that one can create a “smooth point” at the endpoint which is common to cubic B´ ezier curves by constraining the two control points nearest the endpoint to be collinear, that is, to lie on the same straight line. In Illustrator, when one clicks on an endpoint where two neighboring curves join, one sees two little dots — the nearest interior control points — connected by straight lines to the endpoint. One can edit the shape of the curve by dragging on either of the control points; the curve will change shape even though the endpoint is fixed (unless it is the endpoint, rather than the interior control points connected to it, that is dragged.) When the joining point as been flagged as a “smooth point”, the two interior control points are forced to lie on the same straight line so that when one is dragged, the other control point rotates so as to remain on the line formed by the other, dragged control point and the smooth point (Fig. ??). At a “corner point”, the two adjacent interior control points are completely independent. When the left interior control point is dragged, the shape of the left segment changes, but the curve to the right of the corner point is completely unaltered. In contrast, when a curve in the vicinity of a “smooth point” is edited, either by dragging the point itself or the two neighboring control points, then both segments which meet at that smooth point are altered simultaneously. In any even, no more than two segments of a composite B´ ezier are moved by dragging a control point. One could represent a complicated curve by a B´ ezier shape of high polynomial degree, which might seem simpler than using a composite of cubic shapes. However, it is easy with composite cubics to change a point on the curve from “smooth” to “corner” or vice versa merely by removing or adding the constraint that the other interior point must stay collinear with the one which is dragged. Furthermore, when a composite curve is edited, only one or two parts of it are altered. If a single high degree curve were edited, moving one control point would change the shape everywhere. It would require vast amounts of fiddling to get the shape just right because parts that were already acceptable would be distorted by adjustments made to fix the shape elsewhere.
202
CHAPTER 7. DRAWING
Smooth Point
Corner Point
Figure 7.8: Composite B´ ezier curves in which two cubics are joined by a smooth point (left) or corner point (right). The control points which are common to two segments are marked by hexagons; the other endpoints are filled circles. The interior control points are hollow circles. For the smooth point, a dashed line connects the two control points that are constrained to lie on the same line so that the slope is continuous where the segments join.
7.9. TEXTURE MAPPING
7.9
203
Texture Mapping
Every colored surface is a pattern of patches. Each patch must have its own color. If the input to a surface-making subroutine contains only three matrix arguments X, Y, Z specifying the Cartesian coordinates of the points of the surface, the routine must create a fourth matrix CData to store the color data associated with each patch. In a function like Matlab surf, the color values are initially slaved to the values of Z so that the largest positive values of z are coded dark red, and the points of most negative z are dark blue. However, the colordata array can be overwritten to associate an arbitrary color image with the surface. Such overwriting of the colordata of a surface is called “texture-mapping”. Although we shall illustrate the method using Matlab, texture-mapping is a very easy trick — simply overwriting a matrix that the surface-maker had to generate anyway — that is widely employed in computer graphics. The listing below describes a Matlab example. The “texture” is the colordata of a pseudocolor plot (Fig. 7.6) which is generated in the first five lines. The sixth line, cmap=get(surfacehandle,’CData’);, extracts the colordata matrix that was generated by the pseudocolor plot and stuffs into a matrix called cmap. The next three lines plot the surface of sphere in three-dimensional space using Matlab’s built-in sphere command. The final line is the other essential component of texture-mapping: set(spherehandle,’FaceColor’,’texturemap’,’CData’,cmap); modifies the colordata (‘CData’) of the sphere plot by replacing it with the colordata of the pseudocolor image. The ‘FaceColor’,‘texturemap’ informs the plot that its colordata matrix has been altered. It also triggers a useful feature of Matlab texture-mapping: if the new CData matrix is different in size from that originally generated by the surface plot, Matlab automatically performs the necessary interpolation. This is in fact true of our example where the plot of the sphere used only 625 patches whereas the pseudocolor plot had more than 20,000. Unfortunately, most Matlab routines do not generate surface objects. It is possible to texture-map line graphs, but these must be saved as Encapsulated Postscript (EPS) files, then converted to TIFF or JPEG formats using Adobe Illustrator or Graphic Converter, and loaded back into Matlab through the imread command. Complicated surfaces like a sphere are most readily perceived if a surface mesh is included, but this makes it hard to identify the data curves. If the grid lines are converted to grey dotted lines, however, then line graphs on a sphere or other complicated surface can be effective.
hlong=2*pi/200; hlat=pi/100; % Part 1: PCOLOR [longitude,latitude]=meshgrid(-pi:hlong:pi, ... -(pi/2):hlat:(pi/2)); dipole=latitude .* sech( 4*longitude.ˆ2 + 4* latitude.ˆ2); surfacehandle=pcolor(longitude,latitude,dipole); cmap=get(surfacehandle,’CData’); % Part 2: Get ColorData \[Xsphere,Ysphere,Zsphere\]=sphere(25); % Part 3: SPHERE spherehandle=surf(Xsphere,Ysphere,Zsphere); axis equal; axis off; % Part 4: TEXTUREMAP
204
CHAPTER 7. DRAWING
set(spherehandle,’FaceColor’,’texturemap’,’CData’,cmap);
7.9. TEXTURE MAPPING
205
Latitude
1.5
0.3
1
0.2
0.5
0.1
0
0
-0.5
-0.1
-1
-0.2
-0.3
-1.5 -3
-2
-1
0 1 Longitude
2
3
Figure 7.9: A pseudocolor plot in the usual flat, two-dimensional representation as a function of latitude and longitude. The next figure shows the same image texturemapped to the surface of a sphere.
Pseudocolor plot on the surface of a sphere
Figure 7.10: A sample of a pseudocolor plot of a function of latitude and longitude which was texture-mapped onto the the surface of a sphere.
206
7.10
CHAPTER 7. DRAWING
Line Graphs on Surfaces
It is possible to graph ordinary functions of one coordinate versus another on a surface by texture-mapping, but this is awkward and inefficient. In Matlab, the line graph must be saved as an EPS file, converted to a TIFF or JPEG file, read in as a Matlab image, and then texture-mapped. The syntax is different in other graphics libraries, but it is always inefficient to convert a line graph, which is simply a pair of vectors, into an image, which is a two-dimensional array. A better procedure is plot the line graph directly on the surface. In order to plot the surface, one must have a formula that converts a two-dimensional array (representing a grid of points on the surface) into three two-dimensional matrices which give the Cartesian coordinates of each of these points on the surface. For example, use latitude and longitude to parameterize the surface of a sphere:
i−1 j−1 π λj = −π 1 + 2 1+2 , i = 1, . . . , M, , j = 1, . . . , N, θi = − 2 M −1 N (7.23) The surface of the sphere is defined by connecting the points xij
=
ρ cos(θi ) cos(λj )
(7.24)
yij
=
ρ cos(θi ) sin(λj )
(7.25)
zij
=
ρ sin(θi )
(7.26)
where ρ is the diameter of the sphere. The three-dimensional curve of a function θ(λ) is obtained by applying the same transformation formulas which define the sphere itself: xxj
=
ρ cos(θ(λj )) cos(λj )
(7.27)
yyj
=
ρ cos(θ(λj )) sin(λj )
(7.28)
zzj
=
ρ sin(θ(λj )),
j = 1, 2, . . . , P
(7.29)
In Matlab, plot the sphere with surf(x,y,z), keep this with hold on, and add linehandle=plot3(xx, yy, zz) to plot the data curve. Fig. 7.8 is a sample.1 To plot any other sort of surface, we must have an algorithm . That same transformation can then generate the points of a data curve in three-dimensional space which will hug the surface. Texture-mapping is unnecessary for curves; we need only to map surface-to-surface.
1 In Matlab, it is helpful to use a radius for the data curve which is slightly larger than for the sphere so the surface does not obscure parts of the line graph.
7.10. LINE GRAPHS ON SURFACES
207
Figure 7.11: Functions of latitude as a function of longitude are shown on the surface of a sphere as a red solid line with disks and a cyan dashed line. The equator is the heavy solid black line.
208
7.11
CHAPTER 7. DRAWING
Drawing versus Painting or Bitmap versus Vector
There are two fundamental approaches to graphics: bitmap and vector. Bitmapped graphics represent an image as a two-dimensional array: one element for each screen pixel. The disadvantage of bitmap graphics is that it requires a large file: with a 1000 x 1000 pixel screen, one must specify a million numbers just for a single black-and-white image. Color requires 8 bits to 24 bits per pixel. Individually picking each pixel would take a lifetime; bitmap graphics are natural for photographs and complicated textures that can be generated by algorithm. Bitmapped graphics are also natural for painting by computer. In a paint program, the movement of the mouse or graphic pen represents an imaginary paintbrush of a certain width. As the mouse moves, all pixels within the width of the brush are altered to the color of the brush. Thus, a single stroke may alter the colors of thousands or ten of thousands of pixels. The program allows the user to change the width and color of the brush and often to add special effects such as leaving uncolored spots within the paint-swath so as to lay down a texture rather than a solid band of color. Vector graphics represent an image as a set of instructions, such as “draw a line from (1,0) to (0,1) of 0.5 points thickness in the color red”. Vector graphics has two advantages over bitmaps. First, when the figure consists of only a few line segments, the instructions to draw them can be stored in a miniscule fraction of the number of bytes needed for a bitmap. Second, vector graphics are hardware-independent. A diagonal line of 2-point width in green is an unambiguous instruction whether the output device is a screen with 72 dpi resolution or a printer with 300 dpi resolution. The disadvantage of vector graphics is that as the image becomes more complicated, both storage and display/print time will increase until both exceed the cost of a bitmap: a million on/off commands in a bitmap array are much cheaper than a million vector instructions, each of which describes beginning point, endpoint, type of element, color, width and so on. Both types of graphic representation have flourished for many years because neither is superior to the other for all situations. The dichotomy was reflected in the early days of the Macintosh by the existence of two competing illustration programs: MacPaint, which was all bitmaps and brushes, and MacDraw, which was all vector graphics, lines and polygons. In recent years, as programs have become more sophisticated, these two poles of bitmap/vector, MacPaint/MacDraw, have cautiously drawn closer, rather like the warring parties in Northern Ireland. However, it is very hard, technically, to combine such disparate elements. Most programs are firmly in one camp or the other, and show only halting and limited support for the other metaphor. Matlab and most scientific software is vector-based. A linegraph is not a twodimensional array of pixels but rather a one-dimensional vector of points connected by line segments. Matlab does support an image datatype which is a sort of resolution-independent bitmap. An image might be imported as a 200 x 200 array. On a million pixel screen, Matlab will display the image by using the same element for a square of twenty-five pixels, assigning a color to the pixel by using the number in the image array as an index into whatever colormap is in effect. However, images are not terribly well integrated into the rest of Matlab. For example, if the image is in the low-storage form, a one-byte integer for each element, then no arithmetic operations on array elements is allowed. If the image is stored in Matlab’s default double precision form, one may easily run out of memory unless the image arrays are small and few. Texture-mapping is a “paint” operation, but compared to a real painting program, Matlab is a dog of few tricks. Adobe Illustrator is a vector-graphics program. It also supports textured fills of
7.12. DRAWING PROGRAMS: TOOLS
209
polygons and even a paintbrush tool, but the action of the paintbrush is converted to a curve enclosing the swath of a brush. Adobe Photoshop, in contrast, is focused on bitmap graphics. The vector/bitmap duality has put Adobe in competition with itself! KidPix Studio is a paint program, much beloved of children. Its pictures are always drawn at the 72 dpi screen resolution of Macintosh computers. However, it does have tools for drawing lines, circles, and polygons just like a vector-based drawing program. Scientific graphics is mostly vector graphics; the exception is image-processing, such as the output of a CAT scanner or an astronomical camera. In the rest of this chapter, we shall concentrate primarily on vector graphics. However, we must keep the draw/paint dichotomy in mind because these two functions can never be entirely separated.
7.12 7.12.1
Drawing Programs: Tools Selecting Objects
Fig. 7.10 illustrates the basic toolbox palette for a representative drawing program, Adobe Illustrator, which is available for both Macintosh and Windows PC. Illustrator is primarily a vector-graphic drawing program; the paint/draw-bitmap/vector duality is reflected in Adobe’s other major program, Photoshop, which is primarily for bitmap images. Illustrator has a few paint-like tools, however, which reflects the partial convergence of painting and drawing. In a drawing program, a figure is a collection of elements: line segments, continuous curves, polygons, rectangles and text boxes. To move or modify an element, one must first select it. The top two tools on the left palette are both selection tools (arrows).
7.12.2
Outline View and Preview View
Illustrator allows two different ways or “views” for displaying an illustration on the screen. In “preview” mode, what-you-see-is-what-you-get. Unfortunately, in preview mode, it can be very difficult to properly select and edit objects when the screen is full of many ellipses, rectangles and other elements. In outline view, objects are seen as skeletons, and the selection tools work a little differently than in preview mode to make it easier to select just the object you wish to edit. The solid black arrow is the “selection tool”; it might also be dubbed the “selectto-move-the-whole-thing”. When the black arrow has been clicked, and the cursor is moved by the mouse, a little black square will appear next to the cursor arrow when the cursor is sufficiently close to an object to select it. The definition of “sufficiently close” is different between “preview mode” and “outline mode”. In preview mode, if you move the cursor onto either the side or the interior of an ellipse (or whatever), the black square will appear. In outline view, most of the interior of the object is neutral, and one can select an object only by moving the cursor very close to (i) one of its sides or (ii) the little “x” that marks the centroid of the figure in outline view only. (The centroid “x” is invisible in preview mode except when the object has already been selected, and the object is not filled with a color.) In either mode, clicking the mouse when the black square is visible will select the object. In either preview or outline mode, selecting an object means moving the cursor close to it until the black square appears next to the cursor arrow and then When the rectangle (or whatever) is selected, a rectangle circumscribing the object will appear in blue, and there will be blue squares at the corners and the midpoints of this rectangle.
210
CHAPTER 7. DRAWING
If the cursor is close to the centroid of a selected object — the centroid is marked by a tiny “x” in the middle of the object like the pirate gold on the map in Treasure Island — then the arrow changes to a guitar pick. If the mouse is then dragged, the whole object moves. Thus, to move an entire object: 1. Select the object (black arrow) 2. Move cursor arror to the “x” until the cursor becomes a wedge or guitar pick. 3. Drag the mouse If one of the hollow rectangles is dragged, then only that side, or that diagonal (if one of the corner points) will move. Thus, the arrow tool can both move a shape, and also deform that shape. One has to be careful to move objects by dragging the little “x” in the middle only. When a rectangle is selected by clicking the selection tool and then clicking when the mouse cursor is over the rectangle, then dragging with the mouse will move the figure to a new location. One must be careful, however. When a rectangle is selected, for example, one will see hollow boxes in the middle of each side. When the cursor is over one of these, it will changes to a two-sided arrow. One can then drag to move that side of the figure. It is difficult to move the mouse with the ultrahigh precision that is sometimes needed for drawing. Illustration and its cousins allow the artist to constrain the mouse in a couple of different ways when needed. First, holding down the shift key will force the figure to move in a purely vertical or horizontal direction, whichever is closest to the actual direction of the mouse motion. (Some programs allow the shift key to constrain to moving along that angle which is the multiple of 45 degrees that is closest to the mouse motion). Second, one can use a pull-down menu to temporarily impose one-pixel-at-a-time motion for very fine control. Most graphic objects also consist of multiple “anchor” points; for a rectangle, these are just the four corners. One often needs to move one of these anchor points to change the shape of a curve or figure. The “direct selection tool” (hollow arrow) might be called the “anchor point selection tool”. By clicking this tool and then near one corner of the rectangle, one can move just the selected anchor point, distorting the rectangle into a general quadrilateral. However, one can also click with the white arrow in the middle of a line segment. One can then drag with the white arrow to move the segment, both endpoints moving in parallel. So the “white arrow” is the “anchor or endpoint selection tool”.
7.12. DRAWING PROGRAMS: TOOLS
211
Figure 7.12: Basic tool palette in Adobe Illustrator, version 6. The tools at the left are always visible; one activates a tool with a mouse-click. The “hidden” tools become visible when the mouse is held down and dragged, beginning over a default tool. The special tool palette on the right may be either visible or invisible at the user’s option, but the tools themselves are always available. This palette and a wide variety of other options, setting and tools can be brought to the screen and applied by activating dropdown menus from the menu bar at the top of the screen.
212
CHAPTER 7. DRAWING
The “direct selection tool” has its rather bland and general name because it can be used to do more than select a single anchor point. If one clicks on a line segment connecting a pair of anchor points, then the entire segment is selected. This makes it possible to “move a wall” by dragging such as to stretch a square into rectangle without the need to individually move a pair of corners. The hollow arrow with a small cross, available by dragging the direct-selection tool, is the “group selection tool”. The reason that this is needed is that illustration programs allow one to freely group (and ungroup) graphical elements. For example, suppose one has drawn a flower using separate curves for the stem, petals, stamen and pistil and markings on the petals. If one needs to rearrange the figure by moving the flower, one could of course move each element individually, but this would be torture. After each part had been moved to the general location, one must tweak each element into proper location with respect to the others, perhaps only to realize that the flower is not quite aligned with other parts of the figure, and the whole assembly needs to be moved again. A far better way is to join the elements as a group, which can then be moved as a single entity. The procedure is simple: hold down the shift key and click on the elements of the group, one by one, until each is highlighted. Then, pressing the Apple key and “g” simultaneously will unite the elements in a group. The group can then be moved with a single click-and-drag. After the move, the elements can be ungrouped with a single keyboard command so that individual elements can be edited. Yet another way to select graphical elements is by using a “selection marquee”. If one drags after selecting one of the selecting tools, a dotted box will appear. When the box is released, all the elements in the box are selected (Fig. 7.11.)
Figure 7.13: Using a selection marquee: the dotted grey box is drawn by dragging with an arrow-shaped cursor after clicking one of the selection tools.
7.13. LAYERS
7.12.3
213
Views and Layers: Selecting in a Crowd
Selection of an object sounds simple, but there are some complications. One is that when the drawing has many elements, they may overlap so much that it becomes very hard to select an individual line segment or polygon. Drawing programs provide a couple of strategies that help. First, Illustrator offers a “preview” mode which shows the elements in a skeletonized-form with all color fills and textures fills omitted. It is much easier to select objects in preview mode than in the “artwork” view, which shows the objects as they will appear when printed. Second, Illustrator and other programs allows the figure to be organized into layers. If overlapping elements are created in different layers, then one can select the element easily after first choosing the proper layer: the selection tools ignore all elements that lie in different layers. It is trivial to toggle between artwork and previews views and between one layer and another because the program was designed thus: switching views and layers is very valuable to the artist, even though it has nothing directly to do with how any of the elements actually look. Layers can be named. In the layers menu, one can click on the layer titled “hexagon” to easily select and edit a six-sided figure. If the hexagon is on a layer by itself, one does not have to worry about accidentally selecting other objects, or inadvertently modifying other objects when the solid border of the hexagon is changed to dashed lines, for example.
7.13
Layers
In the early days of animation, each frame was drawn from scratch by hand. Since one minute of animation requires 1440 frames at 24 frames/second, all-in-one animation was incredibly slow and expensive. By the mid-1920’s, a better way had been developed. Elaborate backgrounds were painted onto paper, but only once per scene. The characters and moving objects were painted onto sheets of transparent celluloid. Animation costs were reduced by an order of magnitude because only a small fraction of each scene was redrawn for each frame. If multiple objects were moving in a given scene, each was drawn on a separate transparent sheet. If a character was motionless, watching a bouncing ball, then it might not be necessary to do any new drawing to create several seconds of animation. The “cel” with the ball would simply be shifted slightly by the camerman between each click of his camera, filming the composite of background-plus-multiple-cels on frame at a time. In this process of layering was extended still further. In the Space Angel cartoons of the 1960s, the mouths were drawn on cels separate from the bodies. A character could speak by merely moving his mouth while the body cel remained unchanged. Once a small library of cels showing the mouth in different positions had been drawn, the cameraman could film a dialogue scene without requiring any additional drawings. Layering isn’t heavily used in other forms of non-computer media, although it is common for artists to lay down a layer of tape to protect parts of the drawing before airbrushing the background, for example. However, computer illustration and imageprocessing programs such as Adobe Illustrator and Adobe Photoshop use layers as heavily as animated cartoons. Why layer? Some answers follow: 1. Easy selection and editing of objects in a crowded drawing. 2. Toggling layers “visible” and “invisible” allows one to temporarily blank out groups of objects so that the others can be seen more easily.
214
CHAPTER 7. DRAWING
3. Scan-and-trace: put the scanned image and separate layer and then delete the layer when the trace is down. 4. Isometric drawing and drawing with grids or guides: put the grid on one layer and the rest of the drawing on other layers, and then delete the grid/guide layer at the end. A pop-up layer submenu allows one to do the following: 1. Assign a name to each layer (the defaults are “one”, “two”, etc.) 2. Mark the layer as modifiable or frozen 3. Mark the layer as visible or invisible Each layer has a different selection color; this helps to avoid accidentally modifying an object on layer three when one really intended to edit an element on layer two. Freezing all layers except the one you want to work on is a big help, too. The layers palette menu, which is accessed by dragging the little triangle in the upper right corner of the layers menu, allows one to create, destroy or reorder layers. Layers are valuable when tracing imported images. The import can be stored on layer one; the trace can be performed on layer two. The superposition of two (hopefully similar) images can make it hard to check the trace but one can toggle the traced image layer visible/invisible through the layers menu to see the trace in isolation. When the trace has been completed, the layer with the imported image can be simply erased. (Parenthetically, note that the trace, composed of vectors, is usually a small file compared to the imported bitmap image.) Layers are equally valuable when drawing on a grid. Illustrator allows one to create non-printing “guides”. These not be deleted.
Figure 7.14: Illustrator Layer Menu. The tickmark in the left column specifies whether the layer is visible. (There is a stylized icon of an eye above this column. The marks in the second column from the left (under the icon of a pencil) denote whether the layer is modifiable or not. To unlock a frozen layer, one must go to the layer menu and click in this column so that a mark appears next to the layer in this column, and then one can modify objects in this layer. The wide central column gives the names of each layer. It is often convenient to override the default names, which are merely numbers, to give each layer a label which represents its function. The colored rectangles next to each layer name gives the selection color for that layer, which by default is a different color for each layer.
7.14. ZOOM AND GRAB
215
Another use of layering is to avoid inadvertent changes: when many elements are crowded in a small place, it can be very hard to choose the desired line segment and successfully avoid accidental alteration of others. When the elements are in different layers, however, one can work only on layer at a time. Furthermore, other layers can be made invisible, which may make it much easier to see what one is doing.
7.14
Zoom and Grab
The next two tools on the Illustrator palette draw nothing, but merely make the image easier to see. The zoom tool is invariably depicted as a magnifying glass. Click the tool and then click the image, and the screen will be filled with a magnified image which is centered on the location of the mouse-click. Shift-zoom is the anti-zoom, reducing the image so that one can see the whole page again. Most drawing programs support extremely high levels of magnification so that one can literally manipulate individual pixels at 300 dpi resolution if necessary. One drawback of zooming is that sometimes the desired elements will disappear off the screen at high magnifications. The “grab-hang” allows one to re-center the image; click and drag on the screen, and then the image will appear to shift position in the direction of the mouse motion.
7.14.1
Pens and Brushes
Most Illustration programs have at least three tools for drawing lines and curves. KidPix Studio, for example, has a line tool for drawing line segments plus a brush tool for drawing curves. When either tool is activated, a pop-up menu appears at the bottom of the screen, offering a choice of line widths and color intensities: dark, medium, light or an almost transparent wash. The KidPix brush also offers a choice between a square brush (which leaves sharp edges at the ends of each stroke) or a rounded brush. Adobe Illustrator offers a similar range of tools, but with more sophistication and a lot more options. The pen tool is the means to draw straight lines. If one clicks on the pen tool, and then clicks on N points on the screen, the points will be connected by straight line segments. The freehand drawing tool, just below and to the right of the pen, is for drawing curves. As the mouse is dragged across the screen, Illustrator draws a smooth continuous curve with continuous slope that mimics the motion. (Fig. 7.13.) Behind the scenes, Illustrator is actually fitting the mouse or pen motion by a Bezier curve. Tracking the motion to the nearest pixel has disadvantages (usually): the Bezier curve needs lots and lots of control points, which gives a curve that is hard to edit and takes up a lot of storage and display time, and the zigs and zags may reflect smallscale unsteadiness of the human hand more than the bold strokes intended by the artist. Illustrator therefore allows the artist to specify how closely the freehand curve tracks the mouse motion. The default tolerance is keep the curve within two pixels of the mouse motion. Fig. 7.14 shows that reducing the tolerance reduces the number of control points.
216
CHAPTER 7. DRAWING
Figure 7.15: Schematic of the Illustrator freehand drawing tool. Left: the motion of the mouse. Right: the curve laid down in response to the mouse movement; the white disks are its ancho points. The direct handles of the last two anchor points, which end in solid disks, are also shown.
Figure 7.16: Two curves drawn by the freehand drawing tool in Illustrator with the same mouse motion, but different freehand tracking tolerances. Left: track-within-two-pixels (default). Right: track-within-ten-pixels, which halves the number of control points.
7.14. ZOOM AND GRAB
217
Rather confusingly, the pen tool can also draw curves. If an anchor point is dragged after being created, then the dragging will make the point into a “smooth point” with direction lines parallel to the direction of the dragging. (Fig. 7.15). One need not drag all the way to the next anchor point; indeed, the best practice is to drag only a short distance and then release the mutton button and move to the next anchor point, which is created by clicking.
Figure 7.17: Upper left: schematic of anchor points and direction lines. Upper right: three non-identical curves through the same pair of points; the shape varies because of variations in the direction lines through the anchor points. Lower left: a visual definition of the difference between two species of anchor points: “corner” points (where the slope of the curve is discontinuous) and “smooth” points. Lower right: adjusting smooth points and corner points; a corner point has only one direction line whereas a smooth point has two direction lines that can be independently varied. It is terribly easy for the novice to click-and-click without dragging in between, and thereby making the first anchor point a “corner point” where the slope need not be continuous and the two anchor points are connected by a straight line. The reason for this seemingly dumbhead decision is that many real shapes are a mixture of straight lines and curves. The Illustrator pen tool can mix both angles and smooth curves in a single connected element. An experienced user may be driven to drink before mastering the pen, however. Fig. 7.16 schematically illustrates the finer points of Illustrator penmanship. It is most efficient to use a small number of anchor points whenever possible unless one really, really needs to follow an intricate shape. Anchor points are like babies: are you make ’em, they turn out to need a lot of love. Adjusting the anchor points of a curve with many so that the direction lines and locations give a curve that has no obvious kinks can be as hard as teaching a centipede to tap dance. To create a smooth, half-sine-wave loop between two anchor points, one must drag first one way and then the other, which is rather counter-intuitive. Dragging in the same direction twice gives an S-shaped curve. This sort of between-the-anchor-points kink is usually an accident, but it does demonstrate the power of the direction lines to quite drastically alter the shape of a curve.
218
CHAPTER 7. DRAWING
Figure 7.18: Upper left: in using the pen (or freehand) tool, “less is more”. Upper right: to draw a smooth, parabola-like curve between two anchor points, drag in opposite directions at the two points. Dragging in the same direction produces an S-shaped curve. Bottom pair of graphs: inserting a corner point into an otherwise smooth curve.
7.15. STROKE AND FILL
219
To add to the confusion, Illustrator and KidPix have a paintbrush. The color and width of the brush can be varied to lay down broad strokes of color. The “caps” (i. e., the ends of the brush-curve) can be varied to be round or square. In Illustrator, the paintbrush can be slaved to a pressure-sensitive pen-and-graphics-tablet so that the width of the brush is proportional to the pressure, just as in a paintbrush. One can also activate a “calligraphic” feature so that the width varies smoothly with the angle of the curve, in imitation of calligraphic writing. 2 Fig. 7.17 is a sample of the brush’s capabilities. The boundaries of a brushstroke is a Bezier curve, dotted with a few anchor points. These can be manipulated, just as with the output of the pen tool or the freehand drawing tool, to alter the shape of the brushstroke.
7.15
Stroke and Fill
In all forms of art, some objects are shown only in outline whereas others are filled with color. Most drawing programs therefore have tools for both drawing outlines and filling polygons and other outlined shapes. In Illustrator, almost every tool has the ability to apply both a “stroke” and a “fill”. The “stroke” is the outline of the shape drawn; the “fill” is what goes inside the stroke. The pen, freehand drawing tool, brush and special tools for polygons, stars and spirals all support both stroke and fill. For each tool, one may omit either the stroke or the fill. The colors of stroke and fill can be different. Illustrator allows both the stroke and fill to use patterns: patterns of confetti, gradients of smoothly varying color and more complicated shapes and textures such as a brick wall, transparent waves and so on. One can create new textures and patterns in Illustrator which can then be applied in exactly the same way as the generic textures supplied with the program. The metaphor of the brush tool as a computer realization of a paintbrush breaks down when the brush tool is used to apply a swath of texture in a single mouse movement. An oil painter would have to individually paint each line segment for a pattern of confetti, but the computer artist does not. An oil painter would have to paint the fill in red, then change brushes to outline it with a stroke in black. Again, after the paint palette has been used to specify the stroke and fill colors as black and red, the brush tool can apply both the filling and the outline in a single movement. The paint palette offers the option to change colors, line widths, fill patterns, and almost every other aspect of a curve or patch created with the pen, freehand drawing tool, paintbrush, or one of the specialized polygon, star and spiral tools. Fig. 7.18 shows the choices available. The palette can be hidden or displayed explicitly at the user’s option; when invisible, it can always be accessed as a pull-down menu item from the menu bar at the top of the screen. The little colored squares in the upper left of the palette provide access to a wide range of pre-defined colors. To make the stroke of a freehand curve green, for example, one first clicks the box labelled “stroke” in the upper left, just above the color swatches, and then clicks the chosen color. The stroke of any object which is currently selected will turn green, and the same color will be used for the outline of any element drawn in the future until the stroke color is manually changed.
2 Well, yes, calligraphy is usually down with a fountain pen rather than a paintbrush, but consistency is the hobgoblin of simple souls, etc.
220
CHAPTER 7. DRAWING
Black Fill, Black Stroke, Round Cap, 10pt
Round Cap, Square Cap (30 pt)
Black Fill,
Color Gradient Fill
5pt Stroke No Fill
Calligraphic: 120 deg.
yy ;; Brick Fill
1pt Stroke No Fill
Ordinary, Non-Calligraphic
Figure 7.19: Illustrator brush tool variations. The brushstroke can be given both a “stroke”, which outlines the swath of the brush, and a “fill”. The stroke and fill can be of different colors or use textures like “brick” and various color gradients. The width of the brush can be varied from a 1 point swath to very large swaths.
7.15. STROKE AND FILL
221
Figure 7.20: The paint palette from Adobe Illustrator, version 6. This is used to change the stroke and fill colors and also the characteristics of the stroke (line width, solid versus dashed, rounded curves versus “mitered” joins) as well as the pattern of the fill, which may include gradients of color or greyscale or complicated patterns like a brick wall, confetti, fish scales and so on.
222
CHAPTER 7. DRAWING
On the right, labelled by letter “E” in the figure, are several boxes that access menus for custom colors (the four-color) box, named solid colors (solid colored box), patterns (a box filled with a pattern) and the rightmost box gives a menu of predefined gradients. Illustrator allows the artist to add his/her own creations to each of these menu lists; the procedure for creating new patterns is described in a later section. The lines second from the bottom (label “L”). “Caps” refers to the end of a curve or line segment. These ends can be squared, rounded or square but extending a little beyond the control endpoint. “Joins” refers to what happens at sharp bends and corners: these can be rounded, square or “mitred”. A very useful capability is the freedom to change the linewidth (stroke width): type a new number (which can be a fraction) in the box labelled “G” where the number is the width in points (1/72 of an inch). Differentiating curves by thickness is very useful in black-and-white graphics. The lower left of the paint palette (labelled “K” in the figure) allows one to specify a dash pattern. It is only necessary to type numbers into two of the boxes to the right of the “Dashed” button, but if one fills additional boxes, one can create a fairly elaborate dot-dash pattern, or even long dash-dot-short dash. The fill of an object can be similarly altered by clicking the fill box in the upper left of the palette so that a little black bar appears underneath the box. For fills, one can not only change the color, but also specify textures and gradients of colors. (The stroke can be also be given a texture or pattern, too, but these are more restricted than for the fill and may not display or print clearly unless the stroke width is at least several points; gradients are not allowed for the stroke.) The four color bars to the right of the color patches show the mixture of colors in whatever color swatch is currently active. One can manipulate the sliders on each color channel to define new colors which can then be added to the array of swatches and used throughout the rest of the document. (New shades can be permanently added to Illustrator by including them in the “startup” file, which allows the artist to specify all sorts of default preferences; otherwise, new colors are stored only with the document in which they are defined.)
7.16
Patterns
Illustrator unfortunately comes with a very limited suite of default patterns. Shadingby-diagonal lines is a common strategy in scientific graphics, but no such patterns are available. The “Waves” and “Confetti” patterns are sometimes useful, but little else, and the waves pattern is in a pale blue, suitable only for color graphics. The reason Illustrator provides so few defaults is that it is easy to make a new pattern. To make a fill pattern, the first step is to switch to the “artwork” view and then draw a small rectangle. (By double-clicking the square/rectangle tool, the square menu is popped up, which allows one to specify a standard size such as 0.25 inches square.) Set both the stroke and fill equal to “None” unless one wants to include the walls of the rectangle as part of the tiling pattern. The next step is to draw the desired pattern within the square. To draw diagonal lines, for example, one can simply draw a line (of any chosen thickness and color) from one corner to another. Shift-click so as to select both the rectangle and the artwork within it. Then access the “Object” menu at the top of the screen and drag down to “Pattern”.
7.16. PATTERNS
223
A pattern creation menu will appear, listing existing patterns. Click on the “New” button and insert the desired pattern name, then “OK”. The new pattern can then be used just like any other pattern in Illustrator. Well, almost. New patterns are recognized only within the file that created them. One can make the pattern available to other figure files by opening both the figure with the desired pattern (“Source” file) and also the “Target”. In the target file, choose File > Import Styles (that is, drag the File menu at the top of the screen down to Import Styles). Select the desired “Source” file and click “Import”. All custom patterns, colors, and graph designs are then imported into the Target file. Alternatively, Illustrator has a standard Startup file. One can make a backup of the default Startup file and then edit the Startup file by importing all the desired patterns, etc. (Important: one must create a bunch of rectangles (or other shapes) and apply each new pattern to one of the rectangles; unused patterns, it turns out, are not saved with the Startup file, thus causing it to revert to its original form.) Changes to the Startup file will then become available to all Illustrator files.
224
CHAPTER 7. DRAWING
Select both endpoints by (i) shift-clicking or (ii) drag-select
Join by either typing -J or Object > Join
Figure 7.21: Adobe Illustrator’s join command. To select the two endpoints to be joined, either hold down the shift key while clicking on both points, one after the other (“shiftclick”) or drag with the selection tool (solid arrow). A “selection marquee” (dotted rectangle) will appear; release the mouse when the marquee covers both endpoints. One can then join the two endpoints by typing “J” while holding down the Apple key, marked with both an apple icon and a funny symbol shown on the graph, or one move the mouse over “Object” on the menu bar at the top of the screen, drag down until “Join” is highlighted and then release the mouse. A line segment will be automatically drawn to connect the two endpoints.
7.17
Joins, Intentional and Inadverdent
Curves in Illustrator can be joined in three ways. The first is to use the “Join” command, which is accessed from the “Object” menu on the menu bar at the top of the screen or by Apple-J. One must first use the direct selection tool (hollow arrow) to select both endpoints that are to be joined, either by holding down the shift key while clicking both endpoints, or dragging with the hollow arrow to make a selection “marquee” rectangle. (Fig. 7.19.) A straight line will be drawn between the two endpoints unless the points are on top of one another. Note that only endpoints can be joined; an attempt to join a line to a corner of a rectangle will produce only an error message. (A line and a polygon can be effectively joined through the group command, Apple-G, however.) Second, if the pen tool cursor is moved over an endpoint while the curve is selected, then the little mark below and to the right of the pen changes shape to indicate a state of “Over-the-Endpoint”. If one then clicks and draws with the pen in the usual way, the resulting line segment or curve will be joined to the already existing curve. This feature was designed to make it easy to extend an existing curve. Unfortunately, this feature sometimes leads to annoying accidental joins if one starts to draw while a pre-existing segment is still selected. In paper-and-pencil drawing, an element is automatically de-selected as soon as the pencil lifts from the paper. In a drawing program, the last element remains selected until it is manually de-selected. The “Deselect-All” command, Shift-Apple-A, is one of the most useful and frequentlyused commands in Illustrator! The final means of joining curves is to select two objects and then apply the Unite filter (from the Filter menu > Pathfinder > Unite). The two objects are merged into a single object with a stroke running around the exterior of the united object, but with stroked lines that are now on the interior erased.
7.18. CUTTING PATHS, ADD/DELETE ANCHOR POINTS & CONVERTING CORNER POINTS225
7.18
Cutting Paths, Add/Delete Anchor Points & Converting Corner Points
The scissors tool (on the main tool palette) and the knife tool (on the plug-in tools menu) are used to cut paths. The scissors tool makes a point cut: two anchor points are added to a line segment at the point where the mouse is clicked. Both anchor points are open points; the line segment is broken at that point. If one point is moved, then this will open up a gap between the two initially coincident anchor points. The knife tool has to be dragged across a boundary because it literally makes a slice in the interior of the object as well as cutting the side. Two coincident anchor points are placed at the point where the knife is dragged across a side of a polygon (or whatever), but these are connected through another anchor point which is placed where the dragging stops in the interior of the polygon or other object. By moving these anchor points slightly apart, we can open a fissure or crack in the object. (Fig. 7.20). A third method to cut a path is to drag the Object heading on the menu bar at the top of screen down to the Apply Knife item. The selected object, if in the foreground, will then cut all objects that it overlaps as shown in Fig. 7.21. This is a very powerful device; cutting a circle with another circle generates a crescent and a lens simultaneously. One can thus cut very complicated shapes in a single command. The only complication is that the “knife” object is deleted — save a copy first if you need the knife later. The add-anchor-point, delete-anchor-point and convert-anchor-point tools share the same box as the scissors tool. The implication is that these tools are not very important. In reality, novice artists will use them a lot. The functions of the add-anchor-point and delete-anchor-point tools, which have icons identical to the pen tool except for subscripts + or −, are self-explanatory. The change corner-point tool actually toggles an anchor point between the status of a corner point, which is connected to its two neighbors by line segments that are straight at the corner point and meet at an angle, and a smooth point where the slope of the curve is continuous at the anchor point. After the change-corner-point tool has been selected by clicking on its icon in the main toolbox palette, a small wedge-shaped cursor appears. When this becomes hollow, the cursor is within the active proximity of an anchor point. Clicking changes the status of the anchor point from smooth to corner or corner to smooth. After a corner point has been changed to smooth, one must drag the direction points from the smooth point. If the direction points are dragged only a short distance, then the curve will be almost a corner point in the sense that the curve will turn rapidly from one slope to another as specified by the two direction lines, and then will be almost straight until near another anchor point. If the direction points are dragged far from the anchor point, then the curve will curve strongly even far from the anchor point, and the corner will be much more drastically rounded.
226
CHAPTER 7. DRAWING
Drag Path Clicked Here
Figure 7.22: Adobe Illustrator’s scissors tool (left column) and knife tool (right) are used to cut “paths”, which is Illustrator-jargon for a curve or line segment. The icons for each tool are at the top. The rectangles at mid-level illustrate where the mouse is clicked (scissors) or dragged (knife) to make a cut. The scissors tool creates two coincident anchor points which are not connected; one can be moved to open up a gap as shown in the bottom left. The knife tool creates three anchor points: one on the interior of the object and two coincident points on the side of the object; none of these three new anchor points are endpoints. By moving the new anchor points on the side of the object, one can open up a crack as shown in the bottom right. It can be a little tricky to get the coincident anchor points apart, so one may have to experiment to get the crack or opening just right.
;;;; yyyy yyyy ;;;; ;;;; yyyy ;;;; yyyy ;;;; yyyy ;;;; yyyy ;;;; yyyy ;;;; yyyy
Object > Apply Knife
yyy ;;; ;;; yyy ;; yy ;;; yyy ;; yy ;;;yy yyy ;;
Figure 7.23: Adobe Illustrator’s Object/Apply Knife allows one to cut an object using the outline (i. e., stroke) of the foremost object as a knife to cut objects behind it. Thus, if one selects the foreground circle of a pair of overlapping circles and then selects the Apply Knife option from the Object menu in the menu bar at the top of the screen, the “knife” circle is deleted while the circle behind it is cut into two pieces, which have been moved apart for clarity on the right.
7.19. TEXT TRICKS
7.19
227
Text Tricks
The Illustrator text tool, symbolized by the icon “T”, allows one to enter text. Select the tool, then click where the text is to begin, and then begin typing text (including Return) as needed. Deselect the text box to end a given block. Editing a block of text is mildly confusing because sometimes one wants to select the block as a graphic object (so as to move it or convert it to an ordinary graphics object) and sometimes one wants to modify only the text. The rule is: to select-for-moving, use the selection tool (solid arrow at top of palette); to select-for-editing, select the text tool (“T” icon) and then click on the text block. Another mild complication is that it can be tricky to find the “trigger point” for a text block such that clicking near the “trigger” will select the block. Switching to the artwork view (Apple-E) makes it much easier since the trigger point appears as a little “x” in this view; Apple-Y toggles back to the artwork view. It is easy to choose font, style, color and other text properties from the Type pulldown menu at the top of the screen. Illustrator offers two additional text tools which are important because they are capabilities almost never found in scientific software such as Matlab. The “path type” tool allows one to attach text to a path so that it follows the undulations of a path. Thus, one can attach a curving line of text to a contour line even when the graph is so crowded with isolines that horizontal text won’t fit. The “area type” tool (“T” inside a closed curve) allows one to type text so that it is constrained to fit within a given shape such as an ellipse or a polygon. This, too, is a text capability which is rare in scientific software, but very helpful in fitting labels into a graph, as advocated by Tufte and most other graphic doyens. A couple of text-changing options are often useful in scientific graphics. Type > Alignment > Center allows the text to be center-justified, which, for labelling, often looks better than the default left-justification. Type > Alignment pops up a dialog box; by first selecting a letter or letters and then typing in a number in the “baseline shift” box, one make the letters appear as subscripts or superscripts. The “baseline shift” must be negative for subscripts. A good choice is to set the shift equal to about 25%40% of the type size, i. e., 3 to 5 points for 12-point type. The selected type won’t actually shift on the screen until one hits the return key after entering the nonzero “baseline shift” number.
228
CHAPTER 7. DRAWING
T
T
Path Type W
a
Wave
n
o
! !!!
d or
s
Area Type !!
Text in a hexagon. Words fit to the shape. @$#&*
Figure 7.24: Schematic of the path-type and area-type tools; these are accessed by dragging the normal text tool (“T”) icon to the right.
7.20. SHAPE DRAWING TOOLS: ELLIPSES, RECTANGLES, STARS, ETC.
7.20
229
Shape Drawing Tools: Ellipses, Rectangles, Stars, Etc.
Each of the shape drawing tools in Illustrator — oval and rectangle tools on the main tool palette, and the spiral, star and polygon tools on the “plug-in” tools palette — offers a number of options. Oval tool — select the tool and then drag to draw an ellipse. (It is misnamed the “oval” tool in the Illustrator literature; it always draws an ellipse or circle.) 1. Circles are drawn by holding down the shift key while dragging. 2. Circles and ellipses of a desired size may be drawn by clicking once at the spot where the ellipse is to appear on the drawing, which pops up a menu that allows one to type in numbers for the two axes of the ellipse. 3. By default, dragging generates an ellipse with an edge at the start of the drag; by double-clicking the oval tool in the palette or by holding down option while dragging, one can draw from the center so the start of the drag is the geometric center of the ellipse.
R
ot
at e
To o
l
The ellipse is always drawn with horizontal and vertical axes, but it can always be rotated after creation.
D
ra
g,
th
en
Shift-Drag
Figure 7.25: Top: capabilities of the (misnamed) “oval” tool in Illustrator. After the tool is selected, one can draw by dragging either from the side (if the tool is selected by a single click) or from the center (if the tool is double-clicked; a plus sign will appear in the icon). Shift-dragging generates a circle. An ellipse is always generated with semimajor axis parallel to either the vertical or horizontal axis, no matter how one drags, but an ellipse with slanting axes can always be generated by applying the rotation tool.
230
CHAPTER 7. DRAWING
Although the shape drawing tools are directly capable of drawing only very simple, regular shapes, it is possible to build very complicated shapes by applying other tools to the regular shapes. For example, the scissors tool can be used to draw circular arcs, even though this is not a capability of the oval tool per se.
Cut Circle with Scissors
Drag Upper Right Arc Away
Circular Arc
Figure 7.26: The oval tool cannot draw a circular or elliptical arc directly. However, it is easy to draw a circle, cut it in two places using the scissors tool, and then drag away the excess to obtain a circular or elliptical arc. By using other tools, more complicated figures can be drawn from circles. Circular arcs can be duplicated, reflected, rotated and assembled to make highly structured figures.
7.20. SHAPE DRAWING TOOLS: ELLIPSES, RECTANGLES, STARS, ETC.
231
Cut Circle with Scissors
Drag Bottom Arc Away
Move One Arc
Reflect Copy of Arc
Draw Small Fillled Circle and Insert
Enlarge via Scaling Tool
Figure 7.27: An eye can be drawn by using the circle tool twice. A large hollow circle is cut with the scissors tool to make a circular arc. The reflect tool contains a “Copy” button which will apply the tool to a copy of the arc. One arc can then be moved by select-and-drag to complete the eyesocket. The eyeball is simply a filled circle. After the objects in the eye are grouped (via selecting them all through shift-click and then the Apple-G keyboard command), the scale tool will resize the eye to any desired height and width. Using one circle to cut another with the Object > Apply Knife option will also generate a lens-shape from output of the circle tool and is probably faster than applying the scissors tool twice.
232
CHAPTER 7. DRAWING
Rectangle tool — click in the toolbox palette to select the tool and then drag to draw a rectangle. 1. To draw a square, hold down shift while dragging. 2. Click-instead-of-drag to pop-up a dialog box; enter numbers for the sides of the rectangle, which will appear at the point of the click. 3. By default, dragging draws from a corner, but double-clicking the tool or optiondragging will draw from the center, that is, the center of the rectangle will be at the point in the figure where dragging begins. 4. The pop-up menu offers the option to round the corners of the square by circular arcs of a user-specified radius. The rectangle is always drawn with horizontal and vertical axes, but it can be rotated after creation. For all these tools, the object is drawn with the current stroke and fill, which can be altered in paintstyle palette.
Shift-Drag
Rounded Rectangle Tool
Drag, then Shear Tool
Drag to Draw Rectangle; Move Two Anchor Points to Create Trapezoid
Drag, then Roughen Tool: Corner pts; Size: 5; Detail: 10 per inch
Figure 7.28: The rectangle tool is similar to the circle tool except that it has a third option, which is to generate a square or rectangle with rounded corners. By doubleclicking on the artboard (not the tool icon), one can pop-up a menu that allows one to specify the width and height of the rectangle and the radius of the circular arcs for the corners. It is not possible to generate a rhombus by the rectangle tool all by itself, but one can draw a rhombus by applying the shear tool to the result of the rectangle tool. Similarly, a trapezoid can drawn by moving one anchor point of the rhombus using the direct selection tool, or two anchor points of a rectangle. By applying filters to the stroke or fill, one can generate very complicated figures as illustrated by applying the roughen tool to a rectangle.
7.20. SHAPE DRAWING TOOLS: ELLIPSES, RECTANGLES, STARS, ETC.
233
Similarly, stars, spirals and polygons can be drawn by select-tool-and-click-and-drag. The polygon tool is limited to “regular” polygons with an integral number n of equal sides, fit within an inscribed circle of radius r . By rotating, rounding corners, and applying other filters such as “Zig-zag” to the polygon, however, one can make a great diversity of shapes beginning with a regular polygon (Fig. 7.27). The pop-up menu allows one to specify the number of points of the star, the number of segments of the spiral and the number of sides of the polygon along with other information such as the the inner and outer radii of the star, radius and decay percentage and clockwise/counterclockwise orientation of the spiral, and radius of the polygon. Draw-by-dragging allows one to experiment with the size; the objects can be all be rotated by dragging around the center of the object.
;;;;;;;; ;;;;;;;; ;;;;;;;; ;;;;;;;; ;;;;;;;; ;;;;;;;; ;;;;;;;; ;;;;; ;;;;; ;;;;; ;;;;; ;;;;;
;;;;; ;;;;; ;;;;; ;;;;; ;;;;;
Pentedecagon: 15 sides
Hexagon plus Filter > Stylize > Round Corners Corner Radius 0.2 in
Hexagon plus Filter > Distort > Zig Zag Amount: 8 pts Ridges: 4
Figure 7.29: The polygon tool can draw polygons of an arbitrary number of sizes. The fill patterns and stroke can be varied as for any other graphic object. Filters can modify the polygons into more exotic shapes. The “round corners” tool and “zig-zag”, which makes stroke lines wavy with either smooth oscillations or jagged (corner point) oscillations.
234
CHAPTER 7. DRAWING
Three-Pointed Star
Inner radius 1.2 in Outer radius 1.5 in
Three-Point Star after Twirl Tool and Pattern Fill
;;;;;;;;;;;; ;;;;;;;;;;;; ;;;;;;;;;;;; ;;;;;;;;;;;; ;;;;;;;;;;;; ;;;;;;;;;;;; ;;;;;;;;;;;; ;;;;;;;;;;;; ;;;;;;;;;;;; ;;;;;;;;;;;; ;;;;;;;;;;;; ;;;;;;;;;;;; Inner radius 0.6 in Outer radius 1.5 in
Figure 7.30: The star tool can vary the number of points from 3 to infinity. The shape can also be manipulated by specifying a large or small inner radius. The star tool is on the plug-in tool palette. Its menu can be accessed by double-clicking on the artboard (where the drawing appears) after selecting the tool.
7.20. SHAPE DRAWING TOOLS: ELLIPSES, RECTANGLES, STARS, ETC.
Decay 96%, 35 Segments
Decay 80%, 35 Segments
235
Decay 96%, 10 Segments
Decay 80%, 10 Segments
Figure 7.31: The objects drawn by the spiral tool depend on three parameters. One is the radius of the circle which circumscribes the spiral; this is the same for all four spirals shown. The second is the “decay rate”; when this is close to 100%, the curves of the spiral are almost on top of one another. The third is the number of “segments”; when this is small, the curve only circles the origin a few times; when the number of segments is large, the spiral circles the origin many times. These four spirals all rotate clockwise as one moves closer to the center, but a counterclockwise orientation can be specified by clicking the appropriate button in the dialog box.
236
7.21
CHAPTER 7. DRAWING
Transformation: Rotate, Reflect, Shear, Scale
All these tools require a center point as well as a magnitude plus additional information for some tools. All transformations require that the object to be modified is selected, using the usual selection tool (black arrow), before selecting the transformation tool. To use the center of the figure as the axis of rotation or reflection, there are two ways to proceed: 1. Dialog box: double-click the tool. When the dialog box appears, specify the angle. 2. Drag method: click the tool and then drag-without-clicking. To choose another point as the axis of rotation or reflection, there are two ways: 1. Dialog box: single-click the tool, hold down the Option key and click on the new center point (the cross-hair cursor will change to a black wedge). Enter an angle in the dialog box. 2. Drag method: single-click the tool. Click with the crosshair cursor to set a new center point and then drag to transform. One useful generic feature is that the dialog boxes always contains a “Copy” button. If this is pushed, the transform tool will generate a copy of the selected object and transform the copy. A common way to generate symmetric objects, for example, is to draw half the object, reflect-a-copy, and then move the two halves together. The group operation (if a line down the center is desired) or the Unite filter (to erase the line segment down the joining axis) can then permanently weld the halves together as in Fig. 7.30. All transforms can be repeated by typing Apple-D; if the “Copy” button is pressed with a rotation angle of say, thirty degrees, then the transform is applied to the copyof-the-copy. To draw a flower, for example, one can draw a single petal and then rotatewith-copy four times to generate all five petals at the proper angles around the center of the flower, which should be used as the rotation point. The dialog box is especially useful for scientists because it allows one to specify precise numerical angles and, for the reflect tool, whether one wants to reflect about a vertical or horizontal axis. The reflection tool can reflect with respect to a tilted axis, but this is a capability one won’t use much.
Reflect with Copy
Move Halves Together
Filter > Pathfinder > Unite
Figure 7.32: The Reflect-a-Copy option of the Reflect tool makes it very easy to create figures which are symmetric about a central vertical axis (or other axis).
7.21. TRANSFORMATION: ROTATE, REFLECT, SHEAR, SCALE
237
The shear tool is for very useful for converting a rectangle into a rhombus, such as the side of a cube or parallelpiped shown in perspective.
+
+
Shear: Horizontal Axis Angle=60 deg. Move top segment
Shear: Vertical Axis Angle=30
= Figure 7.33: The shear tool, combined with the rectangle tool, is a quick way to draw a cube in perspective.
238
CHAPTER 7. DRAWING
The scale tool can dilate an object, but one can specify different expansion or contraction factors for the horizontal and vertical dimensions. One can also scale-bydragging to change the proportions in rather interesting ways. In particular, one can choose to dilate about a point which is not the center of the object. The Arrange menu at the top of the screen offers an alternative way to scale through Arrange > Transform Each, followed by entry of the horizontal and vertical scaling percentages in the dialog box. When the scaling tool is applied to a group of objects, each object is rescaled around its own center point. If one has a grouped object that is a circle surrounded by six circles all touching its nearest neighbor at the rim, then the scale-by-Transform-Each will shrink each circle in place so that the circles no longer touch (Fig. 7.32). In contrast, the scale tool will shrink the seven grouped circles about their common center so that the circles are still in contact after contraction; the centers of the six outer circles have shifted towards the interior of the central disk. Transforming an entire group is thus rather tricky, and one must be careful to choose the proper scaling.
Scale Tool
Arrange > Transform Each
Figure 7.34: Two different ways to scale (“dilate”) a group of objects with rather different results. The “blend” tool is really a “morphing” tool: it is applied to two objects, and generates a set of objects between them which interpolate, in a uniform sequence, the shapes and colors of the outermost pair. The user can choose the number of intermediate objects. Although this is great for artists, it isn’t often used in science.
7.22
Isometric Drawing and the Third Dimension
Fig. 7.48 shows isometric drawing. The best way to employ an isometric grid is to draw it once-and-for-all as a template file. This consists of the isometric grid (on one
7.22. ISOMETRIC DRAWING AND THE THIRD DIMENSION
239
layer) and a second blank layer. This file can be then be opened, saved under a different name so as to preserve the template file unchanged, and then edited by drawing on top of the isometric grid. When the drawing is complete, it is a one-step operation to delete the grid, leaving only the pseudo-perspective drawing. The reason for the adjective “pseudo-perspective” is that in a true perspective drawing, objects at the back of the field of view are smaller than same-size objects in the foreground. Isometric drawing sacrifices this aspect of perspective drawing by drawing all objects at the same size. This enormously simplifies the drawing; engineers are not trying to please art patrons but merely give machinists a visual representation of the object they must build. The equal-size property of isometric drawings is actually an advantage in engineering because measurements can be taken directly from the drawing without the need to correct for the continously-varying scale of a true perspective drawing. For serious design work, one should use a three-dimensional CAD-CAM system. To avoid the steep learning curve of such software, however, isometric drawing may be preferable if one has a small number of quasi-three-dimensional shapes to sketch.
Figure 7.35: Drawing of a chair on an isometric grid. Scanned from pg. 22 of Technical Drawing: An Usborne Guide Usborne Publishing, written by Susan Peach, published 1987 1. isometric grid is good use of layering; the grid layer can be deleted later 2. isometric drawing is popular for engineering and CAD/CAM because “all the sides of the object are drawn at their true length, so you can take measurements from the finished drawing”. 3. isometric is fake perspective, which reminds us that engineers don’t need to be artists; “faking it” is usually sufficient.
240
7.23
CHAPTER 7. DRAWING
Filters, Styles and All That
Illustrator allows one to modify curves through a variety of operations that we will collectively call “Filters”. These filters are so numerous that only a professional artist can learn them all, and many are useful only in artistic drawing. However, some filters can be helpful in scientific drawings. Some exceptions and possible engineering uses are listed below. 1. Add Arrowheads . This is helpful to generate arrow-headed coordinate axes, arrows that point from labels to the labelled object and in schematics of velocity fields (quiver plot). The Filter > Stylize > Add Arrowheads command pops up a menu of 27 different choices. One can further specify from the menu arrow-atend, arrow-at-beginning, or arrowheads-at-both-ends. This function works with both line segments (pen tool) and with curves draw by the freehand or pen tools. 2. Zizag filter. This makes wavy lines from straight lines. The waves can either be rounded or jagged. Hint: the arrows look best when the line segment is horizontal or vertical when Zigzag is applied; one can then rotate the wavy line to any desired angle. 3. Round Corners. This adds rounded corners to any object with corners. When invoked by Filter > Stylize > Round Corners, a dialog box appears which allows one to specify the radius of the circular arcs that will placed at each corner point. One can always round the corners manually, but it is tricky to round each corner of a polygon by exactly the same amount; the Round Corners filter automates this process. 4. Free distort. This places the object inside an imaginary rectangle; a menu allows one to freely move the four corners of the parallelpiped, and then distorts the figure inside the box to follow the movements of the corners. Filters > Distort > Free Distort. 5. Roughen. If this filter is applied repeatedly with a variety of scales and sizes, a smooth surface can be distorted into an approximation of a fractal, such as a schematic coastline. 6. Unite. This allows one to join two objects so that boundary lines which are on the interior of the united object are automatically erased. This is good for drawing complicated shapes in schematic diagrams. (Filter > Pathfinder > Unite.) 7. Minus Front. This filter allows one to create a hole in an object so as to create an object that a mathematician would call “multiply-connected” and Illustrator calls a “compound path”. The hole object is dragged in front of the larger object, both are selected using shift-click with the ordinary selection tool active, and then the filter is applied. The “hole” is automatically destroyed, so it is a good idea to make a copy if the hole is needed. The hole is transparent, so the hole can be filled by dragging an object with a fill pattern in front of the hole and then sending the object to the back using the Arrange menu. (Filter > Pathfinder > Minus Front.) Fig. 7.33 shows that a wide variety of filters are available under the Distort submenu. The Distort filters operate by shifting the anchor points in various patterns. The Pathfinder filters allow one to make complicated shapes from pairs or groups of simpler shapes. There are far too many variants to discuss in detail, but Fig. 7.34 shows the variety available.
7.23. FILTERS, STYLES AND ALL THAT
Free Distort
241
Bloat 50 %
Roughen
Punk 50 %
Zigzag Amount: 3pts Ridges: 4
Tweak .1in H .1in V Twirl Angle 90 deg.
Scribble 10% H 10% V
Figure 7.36: The effects of all the Distort filters in Illustrator version 6 on a hexagon. Many of the filters can user-adjustable parameters as indicated in the box. The “Bloat” filter curves the object outward from its anchor points (in this case); “Punk” produces an inward curvature. “Scribble” and “Tweak” move the anchor points themselves — randomly in “Scribble” and by the precise amounts specified in the dialog box in “Tweak”. The “Twirl” filter is similar to the Twirl tool in that the inner parts of the figures are rotated more than the outer parts; the maximum rotation angle is specified in the filter dialog box. The “Zigzag” filter can generate waves with corner points as well as smooth points. The “Roughen” filter adds anchor points at small random distances from the original boundaries of the object.
242
CHAPTER 7. DRAWING
Figure 7.37: The Pathfinder menus. The Unite and Minus-Front are especially useful.
7.24. PICTOGRAPHS ALIAS VISUAL TABLES
243
An engineer rarely needs to draw the sort of artsy shapes shown in the illustration of the Pathfinder filters. However, filters and other tools are very valuable in many kinds of scientific line drawing. The Feynman diagrams in Fig. 7.35 are an example.
Figure 7.38: Feynman diagrams are essential tools in particle physics. By convention, different types of particles are represented by different types of lines: solid, dashed, dotted, and wavy. Feynman diagrams are simple enough to be drawn in Matlab (after creating some specialized drawing functions for wavy lines, arrowheads, etc.), but it is easier to draw them in Illustrator. The Zigzag filter created the waves in the wavy line; specifying dash and gaps in the bottom right of the Paint Style palette generated the dotted and dashed lines. The lens was created by cutting one circle with another using Object > Apply Knife and discarding unnecessary pieces. The arrowheads were added by drawing short line segments and then Filters > Stylize > Add Arrowheads. The arrowheads were rotated into place by using the rotation tool: the back of the arrow was dragged onto the line it was intended to adorn, then Rotation tool was clicked, then the back of the arrow was clicked with the crosshair cursor (to specify that point as the axis of rotation) and then the front of the arrowhead was rotated by dragging with the black wedge cursor until the arrowhead was aligned with the wavy line.
7.24
Pictographs alias Visual Tables
Pictographs, which are figures in which copies of a single, simple shape are repeated to indicate quantities, are uncommon in scientific graphics. Therefore, Matlab and most other scientific software lacks pictograph-making subroutines. Of course, pictographs are rarely used in scientific graphics in part because there are no easy ways to make them using standard scientific software! Illustrator draws pictographs as follows. Step One: Make a bar graph. 1. Click the graph tool at the bottom left of the main palette. Drag it diagonally across the screen to create a rectangle to contain the graph. 2. Graph creation automatically pops up a spreadsheet for data entry. Labels and numbers can be typed into the columns of the spreadsheet. (Numerical labels, such as a year, should be typed between quotes). As an alternative to one-at-atime typing, an array of numbers can be copied from the Matlab screen as a row vector and pasted directly into a column of the spreadsheet. To edit the data, use
244
CHAPTER 7. DRAWING Object > Graph > Data where “Object” is a pull-down menu on the menu bar at the top of the screen, “Graph” is the bottom of the Object menu, and “Data” is an item in the “Graph” menu.
3. By default, Illustrator makes a “grouped column” chart and puts the legend on the side; both can be changed through Object > Graph > Style. Step Two: Make a pictograph icon. 1. Draw the icon. 2. Draw a rectangle around the icon. Set the stroke and fill of the rectangle to “None”. 3. Select the rectangle and then do Arrange > Send to Back where “Arrange” is a pull-down menu at the top of the screen. 4. Drag the selection marquee over both the rectangle and the icon within it and choose Object > Graphs > Design. 5. Click New. 6. Enter the name of the new icon, then click OK. In Illustrator parlance, a pictograph icon is a “graph design”. Illustrator identifies a possible “graph design” by looking inside the backmost rectangle; hence, we used the “Send to Back” command on the rectangle. Step Three: Apply the pictograph to the graph. 1. Using the group selection tool, select all the columns (and if there is a legend, the corresponding legend) using shift-click until all the columns in a given group are highlighted. 2. Objects > Graphs > Column.
350 300 250 200 150 100 50 0 1940 1941 1942 1943 1944 1945 Figure 7.39: Pictograph of sunk allied merchant years during World War II (with madeup numbers!). Each icon represents fifty vessels sunk in a given year by German U-boats. The flattened icons represent a fraction of fifty ships.
7.24. PICTOGRAPHS ALIAS VISUAL TABLES
245
3. In the dialog box, choose “repeating” in the column design box, to specify the quantity associated with each icon, such as fifty ships per ship icon. Fill in the box that will appear: “Each design represents” with the number of units per icon. 4. Group-select the second set of columns (for a second variable) by shift-clicking. 5. As for the first column, Objects > Graphs > Column, then choose “repeating”, and finally fill in the number. 6. When the graph is done, delete the rectangles-with-icons that were used to define the “graph design”. Warning: it is easy to select only subelements of a column, so one may have to use the group selection marquee to select an entire column, as necessary to change it from a bar to a cluster of icons. Illustrator saves the pictograph icons in its internal file format as part of the “style” of the graph. One may recycle icons by using the “Import Styles” command when making a new graph; this will allow the new figure to use pictograph icons created in an earlier figure.
5 4 3 2 1 0 1941
1942
1943
1944
1945
Figure 7.40: Two column pictograph. For each year, labelled at the bottom, the left column (milk bottle) icons depicts the consumption of milk and the right column (martini glass) the consumption of alcohol.
246
7.25
CHAPTER 7. DRAWING
Image-processing in Science
When a photograph is to be used in a scientific or engineering publication, it oftens need editing. Broadly speaking, photo-editing can be grouped into three categories: 1. Extraneous details 2. Defects (fixing deficiencies of focus, color, etc.) 3. Overlay Photographs often contain extraneous details. For example, a photo of the Michigan solar-powered car (“Sunracer”) will likely include road surface, street signs, sky and a variety of other irrelevant features. Painting tools are very valuable in eliminating unnecessary details. One strategy is to use the “lasso” selection tool to choose the interior of an irregularlyshaped object, such as the automobile, and then crop everything not selected. This is a particularly good way to show only the essentials without misleading because the irregular shape of the photograph shows that the rest of the image has been cut away. An alternative is “cloning”. Unobstrusive bits of background can be duplicated and then placed over background features that are brightly colored or otherwise eyecatching but irrelevant. However, this can be controversial because the photograph has been edited, and the editing is hidden. Some years ago, a newspaper ran a photograph of a reporter who had just won the Pulitzer Prize in journalism. The photograph had been taken in the reporter’s office in great haste. When the photo was developed, the editors discovered to their horror that the most prominent feature was a bright red aluminum can of Coke Classic on the edge of the reporter’s desk. The newspaper therefore airbrushed the can away, replacing the hole with “cloned” background. This caused a major controversy when the hasty retouching was noticed by a rival publication. The Pulitzer Prize is awarded for accurate, truthful reporting — but the picture of the prize-winner was neither accurate nor truthful. On the other hand, what is the relevance of a Coke can to a journalism prize? In spite of the “Coke can” controversy, elimination of extraneous details from photographs is widely practiced in science and engineering. The use of filters to sharpen blurry images is also legitimate. However, it is important to clearly state in the caption and the text what filters have been applied to the raw image, especially to the essential, scientifically-relevant parts of the image. Photographs often contain defects that can to some extent be fixed in Photoshop or other image-processing program. The “sharpen” and “blur” tools (really just Diffusion and Anti-Diffusion filters) can partially compensate for an image that is a little bit out of focus or otherwise has poorly defined edges. Scientific images often have poor contrast: Voyager photos of Neptune for example, are basically green-on-green. By increasing the contrast, many features become visible such as the large anticyclonic storm that covers much of the planet’s surface. To enhance contrast, the computer makes pale green very, very light and a slightly darker green becomes very, very dark. A Photoshop user can play with the “sharpen”, “blur” and contrast controls to obtain a processed image that shows the greatest amount of detail. Scanned images are often contaminated by dust. These stray pixels of dark on light or the reverse can be deleted by hand, but Photoshop has a filter that automatically removes isolated pixels that differ by a user-set tolerance from neighboring pixels — a sort of electronic lint-cleaner.
7.25. IMAGE-PROCESSING IN SCIENCE
247
A third use of painting tools is to overlay information on the photograph. Fig. 7.38 is a good example. The satellite cloud photograph is almost incomprehensible by itself. However, radiosonde observations have identified the warm front and cold front. By using drawing tools, one can superimpose the fronts and coastlines on the cloud photograph so that one can discern what features of the clouds are correlated with the fronts.
Figure 7.41: Scanned from Weather Systems by Leslie F. Musk, Cambridge University Press, (1988), pg. 90. A satellite photograph (Nimbus-3) of an occluding front approaching Britian, July 25, 1969. The lines with symbols denote the warm front (triangles) and cold front (semi-circles). The lines without symbols show the coastlines of Ireland, Scotland, Wales and Normandy. The letter “L” denotes the minimum of pressure.
248
7.26
CHAPTER 7. DRAWING
Scan-and-Decorate
A common scientific use of a drawing or painting program is to add modifications to an image that cannot be made in the original source. Sometimes, the source is Matlab or other scientific software, and the difficulty is that Matlab lacks the graphical capability we want. It is equally common for the source to be a printed image which is input to the computer by a scanner. Since this can’t be modified at all in its original form except by drawing, this is obviously an important application of drawing programs. The figure below shows two versions of an illustration by a small child. The blackand-white draft was drawn in pencil. The colored version was made by scanning the pencil drawing and then modifying the result in KidPix Studio, which has a one-step command (“paint bucket”) to paint the interior of a region defined by a closed curve with a given color. The bucket, like the paintbrush, can be modified to lay down a texture or pattern if desired. Scan-and-decorate is literally child’s play.
Figure 7.42: The lower half is a scan of a hand-drawing by Ian M. Boyd. The upper half is the scanned image after Ian imported it into Kid Pix and then colored it. He was 7.5 years old at the time.
7.26. SCAN-AND-DECORATE
249
Adobe provides several features that are helpful with scanned images. First, Illustrator can import EPS (Encapsulated Postscript) and Macintosh PICT images (as well as a number of other formats). These can be kept as part of the Illustrator drawing, or traced by hand. It is usually helpful to keep the imported image on a different layer from the non-imported objects. Once an image has been traced, it can be deleted by deleting the layer containing it. Illustrator provides two features that are specifically designed to assist tracing. First, EPS images can be dimmed, that is, displayed in a page gray, making it easier to distinguish the trace from the imported image. Second, Illustrator has an Autotrace tool, which will copy a PICT image. The Autotrace tool is rather limited because complicated patterns of connected lines are often rendered as as lines that don’t quite touch, forcing a lot of manual touch-up work. Adobe therefore sells a stand-alone autotracing program called Streamline. This does a much more sophisticated job of tracing. Unfortunately, we are still early in the age of machine intelligence. Consequently, a highly accurate, good-looking copy requires some manual work even with Streamline. Scanned images are most useful when careful, time-consuming autotracing is not needed, such as when one of the following conditions is true: 1. The imported image does not require editing, but can be used, either by itself or placed in a more complex figure, as is. 2. Only a small part of the scanned image is needed.
250
7.27
CHAPTER 7. DRAWING
Painting Tools
Painting programs and image-processing software adds some additional tools that are not usually found in drawing programs, or found only in a different form. For example, the paintbrush tool in a raster graphics program does not lay down a stroke and a fill, but rather paints a swath of bits with color. In Photoshop, the brush has two options that are not available in its Illustrator counterpart. First the brush can be “feathered”, which gives soft, blurry edges. Second, the “opacity” of the brush can be varied. An opacity of 100%, the only choice in Illustrator, means the brush color is completely opaque and totally covers underlying features. Lower opacity allows previously painted features to show through the brushstroke. This is very valuable in imitating oil painting and watercolors where complex effects can be created by superimposing multiple layers of semi-transparent colors. It probably isn’t too useful in most scientific applications. The paintbucket tool exists in Illustrator, but only as a quick way of changing the fill of previously filled objects. The paintbucket tool in a painting program employs the same icon, but it really functions like pouring a bucket of paint on the figure: the color expands from the point where the cursor is clicked until the spread of color is blocked by lines or other objects drawn in a different color. Thus, if one is making a map and has drawn the complex coastline of Lake Michigan in black using the pencil, one can fill the lake with blue merely by making blue the active color, clicking the paintbucket icon on the toolbox icon, and clicking again in middle of the lake. Painting programs offer other tools that have no counterparts in a drawing program. The Photoshop “smudge” tool is denoted an icon in the shape of a finger pressing on the paper. When the cursor is dragged on the image with this tool selected, the colors of a small area around the cursor are blended together — it is a sort of local Diffusion Filter. Ironically, a device for blending shades on a pencil or charcoal drawing is part of the standard toolkit for a conventional artist. Usually, the “smudger” is called a “stomp” and looks like a pencil except that the tip is actually made of tightly rolled paper. It is easy to blend shades in pencil drawing, but much harder in painting where the colors may smear instead of blending smoothly. The “electronic stomp” exists only in painting programs, however, because color blending is a concept that is meaningful only in a pixel-based representation. The “dodge” and “burn” tools allow one to lighten or darken small areas of an image. The “sponge” tool is useful only for color images where it increases or decreases the saturation of colors in a local region. Collectively, the additional features of painting programs are useful mostly for creating complicated textures. As noted earlier, texture is only occasionally useful in engineering because the shapes are the crucial information. Most of the time, texture is only “chartjunk”.
7.28. RASTERIZING OBJECTS OR PHOTOSHOP-IN-ILLUSTRATOR
7.28
251
Rasterizing Objects or Photoshop-in-Illustrator
Objects in Illustrator can rasterized, that is, converted into bitmap objects. Rather confusingly, there are four options: RGB, CMYK, grayscale and bitmap where the fourth option is “bitmap” in the narrow sense of 1-bit images (every pixel black or white). Illustrator allows one to specify several different resolutions. The command Object > Rasterize (with an object selected) will pop up a dialog box. The “anti-alias” option makes for a smoother image, but also one that requires much more storage. An anti-aliased image may sometimes cause printer problems unless one’s printer has a ton of memory. The “create mask” option is very important unless the object is a rectangle. If the box is unchecked, then the rasterized image will be a rectangle circumscribing the object. When filters are applied, the filtered image will extend beyond the boundaries of the original object, perhaps all the way to the walls of the circumscribed rectangle. If “create mask” is checked, then only the object itself will be rasterized. Why rasterize? The answer is that one can then apply a variety of filters that are meaningful only for bitmap images. Illustrator itself comes with only a dozen or so image filters, grouped as three “GE (Gallery Effects)” submenus under the Filter menu. However, all the filters of Adobe Photoshop can be applied, provided aliases (or copies) of these Photoshop filters are stored in the Plug-Ins folder of the Illustrator folder. To an engineer, Diffusion and Anti-Diffusion filters (not available in Illustrator’s own sets) are the easiest to explain. Given a discrete array of colors (or temperature values or whatever), diffusion can be applied by adding the a constant times the average of the four nearest neighbor values to each pixel. This is a simple centered finite difference approximation to the diffusion equation. Sharp, small features are smoothed.
Diffusion Filter
Average Center Cell with its 4 Neighbors
Figure 7.43: Schematic of a diffusion filter. It is applied by taking some weighted average of a cell with its four nearest neighbors as shown in the top half of the figure. The bottom shows what happens when this filter is applied to a rasterized figure with a line: the line is blurred. An Anti-diffusion filter is also popular in image processing. By subtracting the average, i. e., the opposite sign from diffusion, one can enhance small scale features. Edges are enhanced and amplified, making it easy to recognize the edges of features that were blurry in the original image. When the raw pictures were obtained from an
252
CHAPTER 7. DRAWING
astronomical telescope or CAT scan, blurred by instrumental noise which rather acts like a diffusion, the Anti-Diffusion undoes some of the instrumental diffusion to yield a sharper, clearer filtered image. The Diffusion and Anti-Diffusion filters can only be applied after rasterization because diffusion has no meaning for a vector, i. e., a line segment or curve, and therefore is meaningless in vector-based graphics. The filter only makes sense when applied to a block of pixels which are a discrete approximation to a continuously varying image. Fig. 7.36 shows how the Diffusion filter is applied. Sharp, black lines are blurred into wider rivers of gray by diffusion. For this reason, the Diffusion filter is named “Blur” (as a tool) and “Unsharpen” (as a filter) in Adobe Photoshop. Fig. 7.37 shows a potpourri of other filters, applied to a common object. There is nothing special about these particular filters. The point is that filtering of a rasterized object can help to rectify one of the limits of drawing: the lack of a natural-appearing texture on objects. In engineering drawing, usually texture is undesirable; it distracts from the shapes and graphs that carry the cognitive message. However, diagrams in Scientific American, National Geographic and some undergraduate textbooks have illustrated the power of embedding complicated ideas in a professionally-drawn (or professionally-painted) detailed background to provide a context. It is easier to understand the layout of the Lost City of the Mayas (or whatever) from a painting in aerial perspective than from a wireframe diagram. Such realistic images are usually drawn by a professional artist. However, the artist begins with a sketch drawn by an engineer or scientist. So, it is important that the technologist be able to draw at least well enough so that the artist can understand the sketch.
Unfiltered Star
GE Grain
GE Mosaic
GE Rough Pastels
GE Spatter
GE Patchwork
Figure 7.44: A sampler of the effects of various Adobe Illustrator GE (“Gallery Effect”) filters on a rasterized star with a grayscale gradient.
7.29. DRAWING THEORY AND DRAWING PROGRAMS
7.29
253
Drawing Theory and Drawing Programs
A major theme of how-to-draw books is that complex shapes are built up from simple shapes such as circles, cones, squares and rectangles — precisely the kind of shapes that drawing programs are good at generating. Fig. 7.42 shows a third-grader’s drawing of a horse. Although crude and unfinished, one can see how the boy has used two large circles to organize the torso of the horse. Fig. 7.43 illustrates the theory of building up drawings from complex shapes. The first step is to draw assemblies of simple shapes to organize the drawing. In addition, guidelines (dashed) are also drawn. At later steps, the details are added. Many parts of the original squares, circles, and so on and all of the guidelines must be erased or overwritten to create the final, finished shape. Erasing guidelines is both a time-consuming nuisance and a technical challenge in pencil or ink drawing. However, Illustrator and other drawing programs make it easy. First, preliminary shapes can be placed on a separate layer from the real figure. The guidelines can be drawn in a pale gray or a different color than used in the figure so that the guide-shapes can be easily distinguished from the real thing. When one is finished, one can lock the layer, and then delete it at the end. Second, Illustrator allows one to convert graphical objects to what Illustrator calls “guides”. These are non-printing figures that appear as fixed, immoveable patterns of dotted lines on the screen. An architect who wants to draw a three-side octagonal bay on the front of a house could first draw an octagon of the correct size and place using the Polygon tool, then convert the octagon to a guide. One can draw the three segments of the bay on top of the guide. The guide does not need to be erased, but there is less flexibility in altering it or coloring it than when the guides are ordinary objects on a different layer. In any event, the shape tools of a drawing program simplify the creation of guides; one has a couple of different options for exploiting them.
Figure 7.45: Pencil drawing of a horse by Ian M. Boyd, who was eight years old. Even a child can understand the theory of building complex shapes from simple shapes; note the two large circles in the body. If the drawing had been finished, these circles would have been erased.
254
CHAPTER 7. DRAWING
Figure 7.46: Strategy in a how-to-draw book. The rest of the volume consists of several stages in each drawing. The early stages are patterns of rectangles and circles in perspective; much of these organizing shapes are erased or overwritten by details in finishing the drawing. Scanned from I Can Draw Cars, Trucks, Trains and Other Wheels by Tony Tallarico, Simon and Schuster, (1981), pg. 2.
7.29. DRAWING THEORY AND DRAWING PROGRAMS
255
Computer object-oriented graphics programs are also good at implementing some other crucial ideas of drawing theory. For example, to maintain consistency in shading, most monochrome (single color) drawing is done using a “four-value” system (Fig. 7.44). The pencil artist obtains black and two shades of gray by switching pencils, varying pressure, and tilting the pencil on its side. The ink draftsman must fake shades of gray through patterns of cross-hatching. The computer artist can obtain perfect, consistent shades of gray merely by choosing gray swatches in the Paint Style palette. Drawing programs almost invariably have an “Eyedropper” tool. When touched to a region, it alters the Paint Style palette to match the region. Thus, it is easy to consistently apply subtle shades of color in computer art. In four-value monochrome drawing, though, one hardly needs the Eyedropper. “Contrast” is the difference between the light and dark objects in a picture; it is the black-to-white range. In a high contrast picture, the white is really white and black is black. In low contrast, the white is a pale grey and the black is a very dark gray. It is easy in computer drawing to experiment with contrast. Illustrator has a Select-by-Color command which can be used to change any of the four grayscale values. The “key” of a picture is the median of the grayscale values. A “high key” figure is one whose overall values are rather pale, or in other words one in which both intermediate grays are light. A “low key” figure is predominantly dark. This, too, is easily changed. Raster graphics program such as Photoshop have filters specifically to alter “contrast” and ”key”. Thus, in both object-oriented and bitmap graphics, one can change these properties easily.
Figure 7.47: Although pencil and charcoal may in theory create an almost infinite ranges of grayscales from black to white, in practice most artists use only four grayscales — white, black, and two shades of gray — to create a monochrome drawing. This figure illustrates the “four-value” system. As noted by Blake and Petrie, many artists go further by employing a “three-value” scheme with only a single shade of gray. Scanned from Getting Started in Drawing by Wendon Blake with drawings by Ferdinand Petrie, Northlight Books, Cincinnati (1991), pg. 24
256
CHAPTER 7. DRAWING
Figure 7.48: Scanned from Getting Started in Drawing by Wendon Blake with drawings by Ferdinand Petrie, Northlight Books, Cincinnati (1991), pg. 24
7.30. LOGOS AND OVERHEADS: COSMOLOGY ACCORDING TO MICHAEL TURNER 257
7.30
Logos and Overheads: Cosmology According to Michael Turner
“Nelson Algren, the Chicago writer, said he lived by just three rules, two of which could be listed in polite company: Never play cards with any man named ‘Doc’ and never eat at any place called “Mom’s.’ Viewers of the face-of called ‘Great Debate III: Cosmology Solved?’ — pitting the University of Chicago’s Michael Turner against Princeton University’s James Peebles in a crowded auditorium on 4 October — might have come up with another law, to be violated at great peril: Never debate a cosmologist whose viewgraphs are considered objets d’art.” — James Glanz, Science, 282, 1247-1248 “Does science know the vital statistics of the cosmos?” (1998). Fig. 7.46 illustrates the logo advertising a debate between two cosmologists in honor a third cosmologist, David Schramm, who was killed while flying a light plane a few months earlier. Turner is a legend for his flamboyant transparencies; two samples are shown in Fig. 7.47. His adversary, James Peebles, is not flamboyant at all. However, he almost won the Nobel Prize for work done while still in graduate school when he and his advisor, the late Robert Dicke, explained the observations that did win the Nobel Prize for Penzias and Wilson. He also wrote the book on cosmology (literally!). Ability counts, too, which is something to keep in mind while in the throes of graphomania.
Figure 7.49: Logo for the announcement of a debate between Michael Turner and James Peebles in 1998. The Greek letter Λ is the symbol for the “cosmological constant”; Turner argued that it resolves the major problems in cosmology. A good application of a “path-area” tool to wrap text around the inside of the bounding circle.
258
CHAPTER 7. DRAWING
Figure 7.50: Two of Turner’s flamboyant transparencies for his debate with James Peebles.
7.31. SUMMARY OF ILLUSTRATION PROGRAM IDEAS
7.31
259
Summary of Illustration Program Ideas
Generic ingredients of a good drawing program • Multiple object-selection tools: for the entire curve, for an individual anchor point,
for a previously-grouped collection of elements. • A group procedure to link elements into a single entity that can be moved, resized
and rotated as if it were a single element. • Multiple layers, each of which can be individually locked or unlocked, shown or
hidden, traced and then erased. • Zoom and grab tools for shifting the view of the image while it is being drawn. • Line-drawing curves:
(a) straight line segment tool (b) curve-drawing tool with Bezier interpolation • Paintbrush to lay down stripes of color and texture. • Diverse fill capabilities: solid colors, gradients of color
or grayscale, pre-stored texture patterns, and patterns created by the artist. • A join operation to connect two curves into a single curve. • Scissors and knife operations to cut line segments or polygon sides and cut cracks
into polygons or other objects.
260
CHAPTER 7. DRAWING
7.32
Features That Are Useful in Scientific and Engineering Graphics
• Adding different patterns of shading (light stippling, dark stippling, diagonal
lines, etc.) • Arrows, added to axis lines or used to connect text boxes with data curves. • Attaching text to a curving path to make it fit a crowded space and also to make
it clear what element is labelled by the text. • Inserting text into an irregularly shaped box to make it fit easily. • Making wavy lines (Zigzag filter in Illustrator).
Chapter 8
Fonts and Typography 8.1
Fonts
A type “font” is a collection of letters, numbers and punctuation marks which are designed to blend with each other so as to produce text that is easy to read and aesthetically pleasing. A huge number of fonts are available on modern computers and typesetting equipment. Book designers and graphic artists lie awake at night, thinking about the proper choice of font for their next project. Why do engineers and scientists have to worry about this stuff? The reason is that every graph or animation is a blend of text and graphical objects which must blend together to enhance, rather than confuse, the meaning. In short, every scientific plot is a graphical design. This in turn reflects a practical challenge: every program for making a graph offers choices of font type, font size and font style. It is helpful to understand what all these choices mean.
8.2
Type Dimensions
8.2.1 Monospaced and Proportional Type Typewriters, because of the limitations of their carriage mechanisms, were forced to shift the same amount of space to the right for every letter or space. Typewriters therefore use fonts in which each letter has the same width.1 (The two standard widths were “pica” or “ten-pitch”, which is ten characters per inch, or “elite” or “twelve-pitch”, which is twelve characters per inch.) Such fonts are called “monospaced” fonts. Similarly, the first generation of personal computers allocated the same number of pixels to each letter, and used monospaced fonts, too. Printers learned rather early that monospaced fonts look ugly. Why use the same width for “m”, which has three vertical lines, as for “i”, which has just one? Since typesetters composed type by dropping individual letters into a frame, different widths for different letters caused no problems. Such variable-width collections of letters are called “proportional” fonts because the width of each letter on the page is the width each letter needs. 1 So-called “executive” typewriters could generate proportionally-spaced text, but these were extremely pricey and rare.
261
262
CHAPTER 8. FONTS AND TYPOGRAPHY
ascender size
pxb
x-height
descender Figure 8.1: The size of a font in points is the vertical height, measured in units of 1/72 of an inch, of the bottom of a “descender” to the top of the “ascender” On late twentieth century workstations, almost all fonts are proportional. The only two monospace fonts that are still in wide use are “Courier” and “Monaco”. (The former was the usual font on business typewriters.) Monospace fonts have survived, barely, for several reasons: 1. Improves accuracy of OCR (Optical Character Recognition); good for paper archives. 2. Simplifies vertical alignment of numerical tables (obsolete). 3. Convenient for distinguishing computer code listings from the main text. Since the earliest computer fonts were monospaced, there is a sort of historical tradition that computer listings are typeset in Courier or Monaco also. There is a practical reason that this tradition continues: horizontal indentation is a common trick for improving the readibility of a code; all the statements of an inner loop are indented the same number of spaces from the left margin, for example. Again, monospaced fonts have the advantages of (i) vertical alignment and (ii) different font from the text. The march of technology — better table-making facilities, simpler commands for the vertically-aligning the first letters of a line by tabs, etc — have caused monospaced fonts to continue to lose ground. Nevertheless, Courier and Monaco survive. In Latex, such fonts are called “typewriter” style, and Latex documents always have a default monospaced font available. It is accessed by typing {\tt This is a monospaced font sample. 0 1 2 3 4 5 6 7 8 9} This is a monospaced font sample.
0 1 2 3 4 5 6 7 8 9
8.2.2 Font Sizes Type sizes are usually specified in “points” where (i) a point is 1/72 of an inch and (ii) the size of a font is the height between the bottom of a descender and the height of an ascender as illustrated in Fig. 8.1. The reason that this ascender-to-descender height is used to measure type sizes is that the vertical lengths of the ascenders and descenders are the same for all letters in a given font. The other important and universal characteristic of a font is the “x-height”, which is defined to be the height of the letter “x”, and is the height of that part of a letter that excludes the ascender and descender. For proportionally-spaced fonts, the width is different for each letter in the font — only the heights are the same. This is why font sizes are always quoted in terms of the height of the font. Different 12-point fonts, such as 12-point Times and 12-point New York, may have quite different widths. The New York font is the default on Macintosh computers because it is highly readable on the screen. However, proposal writers who are trying to fit a wordy proposal
8.3. SERIFS
263
into the fifteen page limit of the National Science Foundation have learned that the best way to squeeze text is to use the Times font: among the standard Macintosh fonts, it is the narrowest. (Historically, Times, which is also known as “Times Roman”, was designed in the early twentieth century for the London Times, which wanted a narrow, dense font that would still be readable at small sizes.) Different fonts of a given size may also have different “x-heights”. Many modern fonts have fairly large x-heights, which makes the letters appear bigger on the page. The different choices of width and x-height imply that a given block of text may occupy quite different amounts of space, depending on whether it is typeset in Times or New York or Palatino or whatever. The text in books and journals is usually set in either 12-point, 11-point or 10-point text. In Latex, for example, the standard style files allow only these three sizes as the default size for an article. Scientists and engineers often use larger font sizes for two reasons. First, graphs are often reduce by 50is lettered in a 12-point and then reduced by a factor of two in each dimension, the published graph will be labelled in 6-point type. Only the most eagle-eyed reader will be able to read the letters. When a graph is to be reduced on publication, one should use 18-point or 24-point type to produce the graph. Often, it improves readibility to use a larger-than-12-point size even if the graph is not going to be reduced. Second, 12-point letters on a transparency are almost unreadable in a lecture hall unless the audience is equipped with binoculars! Not only graph-letters but all letters on a transparency should be printed in 24-point size, or perhaps even bigger! Latex has a couple of ways to make large-sized text. First, there is a program called “Slitex” which is specifically designed for making slides. However, it is rather awkward to and seems to be sliding rapidly into obsolescence. An easier strategy is to use the place the command \begin{Huge} at the beginning of the transparency text and \end{Huge} at the end of the block of text. The result is illustrated in the next paragraph:
This is a sample of Huge text; good for making transparencies An alternative is the LARGE environment:
This is a sample of LARGE text; note that the name of the environment is all in capital letters. Very small point sizes (9 points or smaller) are sometimes used to label graphs when (i) the graph will not be reduced by the publisher and (ii) there is no room for larger text. Numerical labels for contour lines, for example, often require small text if there are a lot of lines. However, this is a desperate remedy because small type may not be legible in published form.
264
8.3
CHAPTER 8. FONTS AND TYPOGRAPHY
Serifs
Most fonts used for the body of a text are so-called “serif” fonts. The “serifs” are the little points at the ends of the lines as shown in Fig. 8.2. Serifs were first observed on Roman stone inscriptions as wedge-shaped indentations at the edge of the strokes. Were they convenient for the stone-cutters? Or were they simply decorative flourishes? No one knows. What is clear is that serifs improve legibility. And so serifs can be found in the semi-uncial letters used in the Latin church between the fourth and ninth century, in the Book of Kells (Ireland, around 800 A. D.) in the Caroline miniscule standardized by Charlemagne’s scribes throughout his empire, and finally in the scripts of late medieval scribes. In 1465, two German printers named Conrad Sweynheym and Arnold Pannartz were invited by Cardinal Turrecremata to come work for him at the Benedictine monastery of Subiaco. Rediscovering Carolingian manuscripts in the monastery library and also reading manuscripts in the flowing, humanistic script favored by Italian scribes, Sweynheym and Pannartz rejected the “Gothic” or “black letter” fonts employed by Gutenberg and designed the first printed Roman alphabet. The black letters, they thought, were the degenerate product of the barbarians that destroyed Rome. So, they attempted to return to the purity of their models. The only problem was that the Carolingian miniscules didn’t look much like the Roman stone inscriptions (except that both had serifs!) Sweynheym and Pannartz solved this problem by creating the first double alphabet: capital letters modelled on the Roman stone inscriptions, small letters based on Carolingian miniscule. One of their ways of reconciling these two different styles was to add additional serifs to the miniscule letters. Pannartz died in 1476 and Sweynheym only a year later. However, all modern text fonts in English and most European languages are the descendents of their types: uppercase and lowercase letters with serifs. Although modern printers are no longer worried about restoring the lost glories of Rome, serifs and uppercase/lowercase have survived for a very pragmatic reason: they improve legibility. The reason they improve legibility is that these devices increase the contrast between different letters and thereby make it easier for the eye and mind to quickly identify the identities of the letters and concentrate on extracting the meaning. This must be a paramount goal of scientific visualization, too. Fonts that lack serifs are called “sans serif”. Such fonts are rarely used for long blocks of text because the absence of serifs causes eye fatigue. Sans serif fonts, however, are fine for headlines, section headers, and most important for scientific visualization, for graph labels and legends. In single words or short lines, sans serifs fonts are not tiring to the eye. The absence of serifs means that the basic strokes of the letter can be made thicker and stronger. This is good in two very
serif
sans serif
Abc Abc Figure 8.2: A comparison of a serif font with a sans serif font. The small circles surround serifs.
8.3. SERIFS
265
different situations. First, at large size, sans serif fonts are good for headlines because their thick strokes and different style makes the headline stand out from the body of the text. At small size, the thick strokes and absence of small features, i. e., serifs, makes sans serif letters easier to read. Since graphs are drastically reduced for publication, and the letters and numbers must be fit in small spaces between curves or on axes, this legibility-at-smallsize is a real plus for graph labels. Fig. 8.3 compares three different fonts which show the differences between them due to the two major properties of fonts: serif/sans serif and proportionally-spaced/monospace.
Serif, Proportionally Spaced: Times Roman Sans Serif, Proportionally Spaced: Helvectica Serif, Monospaced: Courier
ghijklmnop HIJ ghijklmnop HIJ ghijklmnop HIJ Figure 8.3: A comparison of three different fonts, illustrating the two most important distinguishing properties: serifs (or the absence thereof) and spacing (proportional or monospaced).
266
8.4
CHAPTER 8. FONTS AND TYPOGRAPHY
Fonts and Graphs
Graphs in a book or journal or usually reduced in size so as to fill only a fraction of a page. In a Latex document, the reduction is usually accomplished under the author’s control by specifying the width of the figure in a beginfigure specification. The reducibility test is: print the figure at the size required by the journal and inspect the letter for legibility. If the figure is to be submitted the old-fashioned way, a drawing on paper which is then reproduced and simultaneously reduced by the publisher, then a good empirical procedure is Cleveland’s Copy-of-a-Copy-Four-Ninths Rule. He suggests making a xerox of the figure at (2/3) reduction, then making a similar copy of the xerox so that the final xerox is a copy-of-a-copy at (4/9) the height and width of the original. If this twiceduplicated-and-reduced image is still legible, then your figure is probably proof against any reasonable reduction-and-reproduction procedures of the publisher. Because original drawings produced in Matlab, Adobe Illustrator or the like as 15 x 15 cm images will be reduced to roughly half their original size and because 9 point type is the smallest that is easily read, it is best to use 18 point or 24 point fonts in a graph or drawing program wherever possible. For normal reading, fonts with serifs are best. However, many drawing programs and Matlab typically employ sans serif fonts as the default. (Helvetica is the most common font). There are two reasons why sans serif is popular for graphical lettering. The first is that the absence of serifs is tiring when reading large blocks of text. However, graph labels are so short that fatigue is not a problem. The second reason is that sans serif fonts, because their letters are simpler than those of serif fonts, are easier to read at very small size or when the type has been smeared or damaged by inadequate reproduction. San serif fonts are good for graph lettering because reduction to a small size and poor reproduction are very common problems for published graphs. However, the first rule is the most important: use a sufficiently large font size so that is still legible after reduction by the printer. If the letters and numerals are sufficiently large, one can use any font, without or without serifs, in a graph. In summary: 1. Use large font sizes (18-pt, 24-pt) for axis labels and other text in a graph. 2. Sans serif fonts like Helvetica are good in graphs
8.5. FONTS IN LATEX
8.5
267
Fonts in LaTeX
In LATEX, the document class command specifies three font families as follows: 1. document font family (almost always a Roman font) 2. sans serif font family 3. typewriter style font family The default fonts in LATEXare the Computer Modern fonts developed by Donald Knuth, the designer and programmer of TEX. He designed a Roman font family, a sans serif Computer Modern, and a typewriter style font family. He also created a special italicized math font. This is employed only in the “math environment”. Knuth designed these four font families so they would all go well together, visually. Because LATEXand TEXneeds a lot of information about fonts — not merely the fonts themselves, as required by printer and screen display, but also extra files with the socalled “font metrics” are needed, too — there is rather limited freedom to change fonts in these programs. Non-Postscript fonts may display and print okay in other software; I have amused myself on my Macintosh by using a Celtic font, created by a hobbyist, downloaded from the Internet. The Celtic letters displayed and printed just fine in Microsoft Word, but could not be used in LATEXor TEX. For general purpose math fonts, there seem to be only three options: 1. Computer Modern 2. MathTime 3. Lucida Bright The Computer Modern fonts are in the public domain and are always included with any and all distributions of LATEX. The MathTime and Lucida Bright fonts must be purchased from firms such as Y & Y, Inc., and Blue Sky, Inc. The MathTime font was developed by the mathematician Michael Spivak to better match the Times Roman font. The Lucida Bright math fonts are always sold and used as a set with Lucida Bright text fonts Knuth is a great computer scientist but only fair as a font designer. The Computer Modern fonts unfortunately are composed of rather thin strokes which don’t reproduce too well on a xerox machine — always readable, but hard on the eyes. The MathTime and Lucida Bright fonts are thicker and easier to read than Knuth’s fonts. There is a somewhat larger range of text fonts possible in LATEX. In particular, the Latex command \renewcommand{\familydefault}{ppl} , placed before \begin{document}, changes the text fonts to Palatino. It is also necessary to add “palatino” [to activate “palatino.sty”] to the arguments of the \usepackage] The palatino font is better aesthetically than Computer Modern. Similarly, \renewcommand{\familydefault˝{ptm} changes the text fonts to Times, even if the commercial MathTime font has not been purchased.. It is also necessary to add “time” [to activate “time.sty”] to the arguments of the \usepackage. As noted earlier, the Times font can be a godsend for compressing research proposals and papers so that they fit within page limits; Times is the narrowest of the widely-used fonts.
268
8.6
CHAPTER 8. FONTS AND TYPOGRAPHY
Symbol Overloading
In most fields of science and mathematics, there are conventions about symbols. The argument of a function is “x” when real-valued and “z” when complex-valued. The set of integers is denoted by Z, and so on. (The symbol Z, with its doubled left vertical stroke, is an example of the so-called “Blackboard Bold” symbols that are part of standard Latex, uppercase only, and accessed through \mathbb{Z}, etc.) The “mnemonics” principle is that it is easier to remember the meaning of symbols if there is a logical connection between the symbol and what it symbolizes. Good examples are using “g” to denote the gravitational constant, “m” or “M” for mass, and so on. When an engineer is introducing new symbols, it is highly desirable to follow these two principles: 1. Respect the naming conventions of your field and 2. Employ mnemonics Unfortunately, these principles sometimes lead to difficulties because the mnemonics principle suggests that we use a letter which is already taken for another quantity. One remedy is to use Greek letters: if one needs a symbol which is “g”, and “g” is already taken, then γ. Unfortunately, many Roman letters do not have Greek counterparts, and some are reserved for standard symbols. Σ is the summation symbol and Γ is the factorial function, for example. Standards Latex also supports the Hebrew letter “aleph” via \aleph : ℵ. The free amssymb package adds three more letters: \daleth k, \beth i, \gimel j. A second strategy is to use accents. The Latex math mode accents are listed in Table 8.1. The package “amsmath” allows three-dot and four-dot accents; “amsxtra” allows some additional accents not tabulated above. The wide symbols and overbrace are not “accents” in the sense that a typesetter would understand. However, accents and more elaborate accentuations share the same problem: Latex and other typesetting systems are usually more sophisticated than the text schemes of illustration and image-processing programs. An overbrace, for example, can be created in Adobe Illustrator. It is usually necessary, however, to draw a brace, rotate it through ninety degrees, change the scale, and then manually place this over the letters it should span. The elements can be grouped so that the brace-plusletters can then be moved and resized as a group. But one should be careful in using complicated symbols, and remember that there may be difficulties in reproducing them in an illustration program. A third option is to use variant font symbols. The “calligraphic” alphabet, displayed in the second line below, is upper case only and is built-in to Latex. The “Fraktur” alphabet uses black letter; it requires the “amsfonts” package [available free by download from the American Mathematical Society web site]; is invoked by \mathfrak{a} , and is available in both lowercase and uppercase. The “Euler script” requires \usepackage[mathscr]{eucal} , is invoked by
8.6. SYMBOL OVERLOADING
269
\mathscr{A} , and is uppercase only. Boldface comes in two species: the standard or “upright” form, which is \mathbf{a} , and the “italic” form, which is \boldsymbol{a} . All boldface symbols are available in both uppercase, lowercase and numerals, etc.; the italic-bold requires the (free) “amsfonts” package.
Roman:ABCDEF GHIJKLMNOP QRST UV W XY Z calligraphic: ABCDEF GH IJKLMN OPQRST UV W XYZ Fraktur: ABCDEFGHIJKLMNOPQRSTUVWXYZa Euler Script:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Bold-upright: ABCDEFGHIJKLMNOPQRSTUVWXYZa Bold-Italic: ABCDEFGHIJKLMNOPQRST UV W XY Za (8.1) Calligraphic or Gothic letters pose similar problems to complicated accents. If one’s workstation lacks a black letter font, for example, one can scan in a copy of the needed Table 8.1: Math Accents in Latex Example ˆ a ˜ a ´ a ¯ a ˘ a ˇ a ˙ a ¨ a ` a " a abc abc abc abc abc
\hat{a} \tilde{a} \acute{a} \bar{a} \breve{a} \check{a} \dot{a} \ddot{a} \grave{a} \vec{a} \widehat{abc} \widetilde{abc} \overline{abc} \underline{a}
circumflex tilde acute macron or overbar breve caret or hacek or clicka overdot umlaut or diaeresis grave vector wide circumflex wide tilde wide overbar underline
\overbrace{abc}
overbrace
\overbrace{abc}ˆ{n˝
overbrace-with-superscript
n
abc
270
CHAPTER 8. FONTS AND TYPOGRAPHY
character from a typography sample book, and then resize and duplicate the scanned image as needed. This is obviously much more difficult than simply typing a letter as an axis letter or part of a title. One sometimes sees labels such as “Gothic-g” as a way of honest labeling when the necessary font is available in Latex, but not in Illustrator or Matlab.
8.7
Dingbats, Ornaments and Pi Fonts
Fonts of symbols rather than letters are called “pi fonts” or “dingbat fonts”. The individual symbols are called “pi characters”, “dingbats” or “ornaments”. The latter term is more general; “printer’s ornaments” includes symbols that are not incorporated into fonts, but were in separate little woodcuts or metal plates that were inserted as ornamental borders, printer’s marks and so on. The figures illustrate typical dingbat fonts. Some of the symbols, such as arrows, numbers in reverse type, and so on are useful in scientific graphs. The easiest way to insert such symbols is to insert a text block with a single character from the appropriate dingbat font. The text block can then be moved, duplicated and resized as necessary
8.7. DINGBATS, ORNAMENTS AND PI FONTS
271
Zapf Dingbats ❁❂❃❄❅❆❇❈❉❊❋●❍ a b c
d e f
g
h
i
j
k
l
m
■❏❐❑❒▲▼◆❖ ◗ ❘ ❙ ❚ n
o
p q r
s
t
u
v w x
y z
✡✢✣✤✥✦✧★✩✪✫✬✭ A B C
D E
F G H
I
J
K
L M
✮✯✰ ✱✲ ✳ ✴ ✵✶ ✷ ✸✹✺ N
O
P
Q
R S
T
U
V
W X
Y
Z
✑✒✓✔✕ ✖ ✗ ✘ ✙✐✍✝ 1
2
3
4
5
6
7
8
9
0
-
=
✁✠✃✄☎✾✆☛✈✉✿☞ !
@
#
$
%
^
&
*
(
()
_
+
❀ ❞ ✻ ❛ ✽ ❝ ✼ ❜ ✛✚✇✂✌✜✎✞✏✟ `
~
[
{
]
}
\
|
;
:
'
"
,
< .
> /
Figure 8.4: Symbols in the ITC Zapf Dingbat font, perhaps the most widely available “pi font”. The letters, numerals or punctuation marks that need to be typed to generate the symbol are shown immediately underneath it.
?
272
CHAPTER 8. FONTS AND TYPOGRAPHY
Webdings a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
B
C
u
v
w
x
y
z
! " # $ % &'(
A
t
D
E
F
G
H
I
J
K L M
)*+ , - . / 01 2 345 N
O
P
Q
R
S
T
U
V
W
X Y
Z
6789: ; < = >?@A 1
2
3
4
5
6
7
8
9
0
-
=
BCDEFGHI J K L M !
@
NOP `
~
#
$
%
^
&
*
(
()
_
+
Q R S \| VWXYZ[\]/_ [ {
]
}
\
|
;
:
'
"
,
/
?
Figure 8.5: Symbols in the Webdings font. The letters, numerals or punctuation marks that need to be typed to generate the symbol are shown immediately underneath it.
8.7. DINGBATS, ORNAMENTS AND PI FONTS
273
Wingdings a
b
c
d
e
f
g
n
o
p
q
r
s
h
i
j
k
l
m
⌧
t
u
v
w
x
y
z
!"#$☺&'( A
N
O
B
C
D
E
F
G
H
I
J
K L M
)*+,-./012345 P
Q
R
S
T
U
V
W
X Y
Z
6789:;?@A 1
2
3
4
5
6
7
8
9
0
-
BCDEFGHIJKLM !
`
@
#
$
%
^
&
*
(
()
_
NO☯QR
STUVWXYZ[\]^_
~
}
[ {
]
\
|
;
:
'
"
,
/
Figure 8.6: Symbols in the Wingdings font. The letters, numerals or punctuation marks that need to be typed to generate the symbol are shown immediately underneath it.
?
274
CHAPTER 8. FONTS AND TYPOGRAPHY
Wingdings2 01234 a
b
c
d
e
f
g
h
56789
n
o
p
q
r
s
i
j
k
l
m
t
u
v
w
x
y
z
!"#$%&'( A
N
O
B
C
D
E
F
G
H
I
J
K L M
)*+,-./012345 P
Q
R
S
T
U
V
W
X Y
Z
6789:;?@A 1
!
2
@
3
4
~
6
7
8
9
0
BCDEFGHIJKLM #
$
[ {
%
^
&
*
(
()
-
_
=
+
STUVW℡YZ[\]^_
NOPQR `
5
]
}
\
|
;
:
'
"
,
/
Figure 8.7: Symbols in the Wingdings2 font. The letters, numerals or punctuation marks that need to be typed to generate the symbol are shown immediately underneath it.
?
8.7. DINGBATS, ORNAMENTS AND PI FONTS
275
Wingdings3 a
b
c
d
e
f
g
h i j
n
o
p
q
r
s
k l
m
t
u
v
w
x
y
z
!"#$%&'( A
B
C
)*+ N
O
6 !
E
Q
7
89
2
3
R
G
H
S
I
J
4
5
=
6
K L M
23⇪5
T U V
:;
7
?
8
9
Y
0
Z
@ -
BCDEFGHIJKLM @
#
$
%
NOPQR `
F
, -.⌃⌥1
P
1
D
~
[ {
]
^
&
*
(
()
_
=
+
STUVWXYZ[\]^_ }
\
|
;
:
'
"
,
/
Figure 8.8: Symbols in the Wingdings3 font. The letters, numerals or punctuation marks that need to be typed to generate the symbol are shown immediately underneath it.
?
A
Chapter 9
Scanning 9.1
Introduction
A scanner is a device that looks and works much like a xerox machine except that the copy is not a duplicate on a sheet of paper but rather a computer file. Scanner software can save the image in a variety of formats including as a Postscript file. The image can then be included as part of a book or scientific publication; many journals now can receive Postscript files as email and print directly from the file on their very high resolution printers. The image can also be imported into a drawing program and then edited and modified. Low cost scanners cost only $200 or less, but still do a good job of scanning line art at 300 dpi, and are fair at scanning color photographs or images. Mass-market magazines employ high-resolution scanners (as much as 2000 dpi) to convert colored drawings, advertisements and photographs into a form suitable for layout and typesetting software.
9.2
Why-To or Reasons Scanning is Useful in Scientific Computing
1. To include graphs and diagroms from previously printed work in computer-generated journal articles and reports. 2. To use previously published images as a starting point from a new diagram or image. (A scanned image can be traced in a drawing program, combined with other FORTRAN or Matlab-generated graphs, or otherwise modified to suit present needs better than the original picture.) 3. To extract numerical information from previously published graphs (“data theft”).
9.2.1 Recycling Graphs To introduce a topic or provide background, a previously published graph is sometimes worth more than a dozen paragraphs of text. One then has a choice: regenerate the graph oneself, which may take a year of work, or scanning/xeroxing the image from a book, and asking permission of the copyright owner to reprint the picture. 277
278
CHAPTER 9. SCANNING
Xeroxing is sufficient if your own work is to be typeset by the publisher. However, for a computer-generated manuscript, it is highly convenient to have the copy in a computer file, and that requires scanning.
9.2.2 Scan and Modify Much scientific and engineering work consists of doing old work better. It is then very useful to publish a direct, graphical comparison between the old and the new. The most convenient way to make such an old-and-new graph is to scan the old picture in and then use a drawing program to combine this with your new computer-generated image. One could use a professional draftsman to combine the curves. However, scan-and-modify is almost certainly what the artist will do!
9.3
Scanner Types
Scanners come in several species: 1. Flatbed scanners 2. All-in-one printer/scanners 3. Slide/film scanners 4. Photo scanners 5. Drum scanners 6. Oversize scanners 7. Handheld scanners 8. Digital cameras Flatbed scanners are the most common. They vary in price, but a decent scanner is only $100. Many home computers now have flatbed scanners attached, and many stores bundle computers with scanners. Flatbed scanners usually employ a laser as the light source; xerox machines also employ laser light sources, and indeed the mechanics and electronics of the moving laser is very similar in both types of equipment. The reflected or transmitted light is captured by a CCD array just as in a digital camera. However, the scanner array does not need to be as dense or as sophisticated as in a camera because the camera must capture the entire image in a fraction of a second whereas the scanner array literally scans the image over a few seconds, capturing a tiny piece of the image at each instant. Because there is great commonality between scanners, xerox machines and laser printers, so-called “all-in-ones” have become popular. These combine a flatbed scanner with a copier, printer and fax machine. The earliest all-in-ones printed only black-andwhite, using a laser printer mechanism. (The laser did double-duty for both printer and scanner). Many new models combine a color ink-jet printer with a scanner; these can make color copies. As scanners, the all-in-ones are usually less capable than stand-alone scanners. The great selling point of all-in-ones is that they are very compact, allowing several functions in a container which can fit into a crowded home office or computer study. Consequently, all-in-ones rarely allow the scanning of images bigger than 8.5” x 11” whereas
9.3. SCANNER TYPES
279
larger sizes are common in flatbed scanners, even cheap ones. However, many all-inones offer the option of an automatic document feeder (ADF). Slide/film scanners are designed to scan transparent media such as slides or film in small sizes at very high resolution. Inexpensive slide/film scanners usually have much higher dots-per-inch ratings than even top-of-the-line flatbed scanners, but are limited to media that will fit in a holder that can accomodate only 35mm film or slides. A recent variation is the dedicated photoscanner. A developed 3” x 5” scanner is an opaque media that can be scanned perfectly well on a flatbed scanner. However, the photo scanners are more compact than flatbeds because they are just big enough to accomodate a photo. Their optics has been designed so as to trade moderate resolution over a wide area (flatbed) for higher resolution over a small image size (photoscanners). If one intends primarily to scan either slides or photos, a special-purpose scanner will give better results, and take up less space, than a general purpose flatbed scanner. However, a flatbed is more flexible in that it scan just about anything as explained below. A drum scanner requires that the scanned object be thin and flexible so that it can be wrapped around a drum which rotates in front of the light source and light collector. Drum scanners have much higher resolution than flatbed scanners because they employ a different light source (halogen lamps) and different light collector (Photomultiplier Tubes, alias PMT). Such scanners are so expensive (many thousands of dollars and up) that it is unlikely that an individual scientist or even a large research group would ever own one. Nevertheless, drum scanners are important to the scientific community. The reason is that publishers use them as the standard means of scanning documents for publication. These days, publishers try to bypass the scanner by collecting electronic image files from authors whenever possible. However, because of the lack of standardization of image files and so on, journal publishers are routinely forced to fall back on their drum scanner. This is particularly so for photographs and other images which are initially generated on a non-electronic media such as film; the publisher would much rather use his high resolution drum scanner for a photo than accept an electronic image that is the author’s low resolution scan of the photograph. In addition, it should be noted there are “service bureaus” in most large cities that serve the graphics design and publishing industries. An engineer who needs an ultrahigh resolution scan can take his image to a service bureau and pay a small charge to have it drum-scanned and returned as an electronic file on a Zip disk or CD-ROM. There are oversize scanners that typically have a long bar that can accomodate paper as much as two or three feet wide plus a feed mechanism to pull the paper through the scanner and past the imaging equipment. These scanners are sometimes found in large engineering and architecture establishments to allow the scanning of blueprints and architectural drawings, which often are of rather heroic size. These scanners also are too expensive to buy, but often not that hard to “borrow” by using a service bureau, or a centralized university facility. Hand-held scanners received a lot of publicity a few years ago. The theory was that these little scanners could be slipped in a backpack and taken anywhere. Instead of xeroxing articles in the library, one could use a hand-held scanner to capture the image electronically. Unfortunately, the head is a lot less steady than the mechanical track of a flatbed scanner, so the quality of hand-held scans of an 8.5” x 11” page is awful. Such scanners are still sold, but never became popular. Nevertheless, small, portable scanners will likely make a comeback. First, scanner technology has improved and price has come down. Second, libraries in the near future
280
CHAPTER 9. SCANNING
may have coin-operated scanners similar to the coin-operated xerox machines that they already have. Digital cameras are not usually thought of as scanners, but sometimes are used that way. The cartographer David Rumsey has put his library of 6000+ historical maps online. Because the maps are very large, they cannot fit in a standard flatbed or drum scanner; because many are a couple of centuries old, they are too fragile to be pulled through an oversize blueprint scanner. His procedure is to spread the maps on the floor, illuminate them with standard photographic spotlights, and then capture the map using a high-quality digital camera mounted on a standard several feet about the maps.
9.4
Scanner Substitutes
9.4.1 Digital Cameras As noted previously, digital cameras are often the best way to scan very large maps. Flatbed scanners have been used in the past to scan three-dimensional objects such as coins or leaves, etc., taking care not to scratch the glass surface. However, digital cameras are probably better for imaging three-dimensional objects. (The exception is very small objects that can be laid on a flatbed, but not easily photographed because a “close-up” would be outside the focal range of the camera.) Digital cameras vary widely in cost and resolution. The latter is usually expressed in “megapixels” where a megapixel is a million pixels, or in other words a 1000 x 1000 bitmap. How many megapixels does one need? A digital image should be printed at a resolution of 150 dpi to 300 dpi. At less than 150 dpi, the image looks fuzzy and pixelated to most observers. A picture at more than 300 dpi is indistinguishable from a print at 300 dpi even for the most keensighted observer. In general, a picture printed at about 200 dpi looks crystal clear. It follows that 200 dpi is a good resolution goal for digital cameras. The number of megapixels required to reach this goal depends on two issues: 1. Final print size 2. Cropping Table 9.1 shows the number of pixels needed at 200 dpi resolution for various print sizes. The lowest resolution digital cameras, costing $35 to $50, create images that match the VGA screen resolution, 640 × 480. For a passport photo, even the most humble of digital cameras would seem to be adequate, but this is not the whole story. First, digital cameras (and film cameras) are bothered by imperfect color fidelity; people photographed with a VGA camera often look slightly seasick (“green cast”) or drunk (“red cast”). More expensive cameras reproduce colors more faithfully than cheap cameras, if color fidelity is important. Second, and more important, digital cameras allow very easy cropping. An ordinary photograph can be physically cropped by cutting away extraneous parts of the picture with scissors. Unfortunately, this renders the picture a non-standard size. The cropped picture will fall out of our scrapbook, and look wierd when viewed on the same page with a lot of standard size figures. In contrast, digital pictures may be cropped with reckless abandon in Photoshop or similar programs. The image can then be reexpanded to a standard size.
9.4. SCANNER SUBSTITUTES
281
This goes double for scientific graphics. There is no standard size; a graph can expanded to fill an entire column width in Latex without even bothering to alter the size in Photoshop. Furthermore, there is no such thing as “pretty background scenery” in a scientific image; it is desirable to crop away everything except the experimental apparatus, or whatever is the focus of the picture. Thus, it is a little tricky to use a digital camera as a scanner substitute. A picture that may be satisfactory as a 3” x 5” image may be cropped to 2” x 3” and then published as a 3.2” x 5” — with visible pixelation and streaking. In estimating resolution needs, one must allow for cropping and also estimate the final published size of the cropped image. The conventional wisdom is that a six-megapixel digital camera is needed to match the resolution of 35 mm film. Cameras in this range are now available, but very expensive (thousands of dollars) in 2002. However, prices are dropping rapidly. Digital cameras have one significant drawback compared to film; they are relatively slow at capturing images. Film speed is rated from AS100 to AS1000; by using the latter and a very short exposure, a 35 mm camera can freeze very rapid motion without blurring. Digital cameras have a speed roughly equivalent to AS100. Consequently, sports photographers are forced to use film for many applications even though they can afford six megapixel digital cameras and love the freedom to bypass the delays of development, and go straight to digital editing.
9.4.2 Scanning Substitute: PDF files The American Meteorological Society has archived all articles in its journals, going back to the founding of each journal, as PDF files. These can be opened in Photoshop and individual figures extracted and modified. 1. First, open a PDF file such as KeyseretalBAMS01.pdf. A little window will appear with the legend “Generic PDF Parser”. 2. Select the desired page number by clicking on the arrows and watching the page marker change. Click OK. A window will appear that allows one to select the numbers of pixels per inch, etc. Click “continue”. The selected page will then be rasterized. 3. Erase unwanted bits of text and figures to leave only the desired figure. The easiest way is probably to simply crop the Photoship image around the desired picture. 4. Add text to the figure as desired, and whatever modifications or adornments as seems appropriate. 5. Save the image in Photoshop format. Save it again as an EPS file if that format is needed. Table 9.1: Pixel Requirements of Digital Pictures Print Size
Pixels at 200 dpi
1.375” x 1.75” 3” x 5” 5” x 7” 9” x 12”
275 x 350 600 x 1000 1000 x 1400 1800 x 2400
Total pixels 0.10 0.60 1.40 4.30
megapixels megapixels megapixels megapixels
Print name passport photo standard snapshot medium framed picture oversized
282
CHAPTER 9. SCANNING
When all this is done, one obtains the same result as an annotated scan, but without actually using a scanner
9.4.3 Scanning by Video Camera Frame-Grabbing This is effective. However, it is limited to low-resolution images ( 640 x 480 pixels) on older video cameras. Some of the newer digital camcorders have higher resolution, but even the best are inferior to a good digital camera.
9.4.4 Scanning by Photo CD With this option, film is developed and returned to the photographer as a CD-ROM. The scanning is effectively done with a pretty good drum scanner. The CD contains several image sizes for each photo. The largest size image is 2048 x 3072 pixels.
9.5
Copyright and All That
Many images, including most pictures in a scientific journal or a book, are protected by copyright. Some images are now protected by a “digital watermark” which is encoded in the pictured; decoding software can recover the watermark for a scanned image and so prove that the image was copied in violation of copyright laws. There are several ways to circumvent copyright. 1. Use old images for which copyright has expired. For example, images created in the nineteenth and early twentieth century are now in the public domain and can be freely copied. Some books contain collections of such images; these books of “clip art” explicitly state that these images are not protected by copyright. 2. Trace the scanned image and then delete the scan. 3. Ask permission of the copyright owner.
9.5.1 Copyright-Expired Images American and international copyright laws contain time limits. For example, until recently, copyright protection expired 56 years after the original publication. Changes in the copyright law (about 20 years ago) altered the status of publications after that date: copyright now extends fifty years from the death of the author. All graphs published before 1942 are now in the “public domain”, which means that copyright law no longer protects them and these images can be freely copied and republished. There are subtleties. For example, da Vinci painted the Mona Lisa in the early sixteenth century and it is therefore not directly protected by copyright. However, the Louvre Museum owns the physical copy of the painting and does not allow unauthorized reproduction. One could copy the image from a book, but technically, the book is protected by copyright. In practice, since the image has been published in many books, one can safely scan it as long as one crops away all information that might indicate the book where it was published. Government authors of scientific publications are required by law to place them in the public domain, and publishers have been forced to respect this. Such publications can be a useful source of royalty-free, copyright-free scanned images. But there is still a moral and cultural obligation to credit the original source in your caption.
9.6. HOW-TO
283
9.5.2 Scan, Trace and Delete the Original Drawing programs such as Adobe Illustrator support graphical layers. One can copy the scanned image into layer one, trace the image in layer two, and then delete layer one. Some specialized programs, such as Adobe Streamline, are designed specifically to do high quality automatic traces; Illustrator has a lower quality automatic trace. Even the best automatic trace usually requires some manual clean-up, but auto-tracing can greatly improve the usefulness of scanning. Copyright law is not infringed as long as the trace is modified so that the final image is different from the original. (How different? Not very, but ask your lawyer!) The law states that the expression of an idea can be protected by copyright, but not the idea itself. Thus, one can always draw (or auto-trace and modify) a graph of the partial sums of the piecewise linear (or “sawtooth” function) even though such graphs have published many times before. The idea of a partial sum graph cannot be copyrighted. However, a pixel-by-pixel copy of someone else’s published partial sum graph would be a violation of copyright law.
9.5.3 Asking Permission Since scientists want maximum publicity for their own work, obtaining permission to use a copyrighted image is easy. One simply sends a form letter to the author. The subtlety is that most journals and professional societies require the book or article author to transfer copyright to the publisher. However, to avoid annoying the author, publishers usually grant only conditional permission: the permission takes effect only when one has also obtained the consent of the author if still living. So, one must write to both the author and publisher. If the article has multiple authors, one must write to all the authors unless one authors signs on behalf of all the authors. Only once have I been asked to pay a fee to reuse an image. A textbook publisher asked $200 to use an image of the partial sum of a Fourier series for the piecewise linear function. I regenerated the graph using Matlab, and paid nothing.
9.6
How-To
A scan is composed of mandatory steps plus others that are optional. The steps that must be done for every scan are the following. 1. Place the image to be scanned on top of the glass sheet and drop the cover over it, as far as the cover will go without forcing. This step is identical to making an ordinary xerox. 2. Open the scanning software, such as Ofoto which is standard for Apple scanners, and click the button to begin the scan. 3. Save the image as a computer file of the chosen file type: Postscript, Encapsulated Postscript (EPS), Pict [Macintosh only], TIFF, etc. The scanner hardware almost never requires manipulation by the operator except to turn it on and off and to put the transparency adapter in place. Almost all options are implemented by clicking in the scanner program. These options include the following:
284
CHAPTER 9. SCANNING
• Scan as line art, grayscale, or color photograph.
If an image is drawn only in black lines, dashes, and curves without grayscale shading or color, then it is a good idea to click the “line art” option on the scanning software. There are two reasons. First, line art is stored as one-bit-per-pixel. Grayscale is 8-bit and color as 24-bit, which implies that at a given number of dots-per-inch, a grayscale file will be eight times as large as a line art scan of the same image. Second, line art images, if scanned as grayscale, will often be rather muddy-looking as the scanner represents the background as pale shades of gray. Some scanner software, such as Ofoto, provides the option to scan line art at 8-bit resolution even though the result will be stored and printed at one bit resolution with the “threshold” option. The reason that the in-memory grayscale scan is useful is that one can observe what areas are treated as black and which areas as white by the default threshold criterion. If the scan target is a xerox, for example, the paper is likely sprinkled with a lot of tiny random dark spots. If these little gray noise blotches are being interpreted as black, then altering the threshold so that only really black pixels are printed as black may effectively eliminate a lot of noise from the scan. • Dithering & Halftones
Most scanning software allows several 1-bit options. The best choice for line graphs is usually “threshold”, which interprets all sufficiently dark pixels as black, and all pixels lighter than the threshold as white. (The threshold can be adjusted in the “Tone Controls” menu of Ofoto software, and similarly in other scanning software). Another option is “dithering”. This tries to correct for the “jaggies”. The best option is to scan at higher resolution, but if this isn’t possible, dithering may be helpful. “Halftone” represents grayscale images by little black dots of various sizes and densities, similar to the way photographs are printed in newspapers. If the image is really grayscale, then one should scan it as a grayscale image. The little black dots of a halftone image will likely “bleed” when printed in ways even more unpleasant and uncontrollable than when grayscale images as printed. (To put it another way, scanning software and laser printers do a better job with grayscale images when they know the images are grayscale.) • Printer & Monitor Calibration
Scanner software will optimize the image file so that it will print as well as possible on a given model of printer. (The software manual describes how to do calibrations for your particular printer; the software has been built-in calibrations for many common models of printer). This calibration is particularly helpful for color, less so for grayscale, and almost irrelevent for line art. The scanner software will generate a standard chart to be printed, and then scanned. By comparing the scan of the calibration chart with its exact specifications, the software can “tweak” the scan so that the printed image resembles the scanned image as closely as possible. The monitor can be similarly calibrated. Both printer and monitor calibrations are stored as files, to be applied as needed. • Manual rotation.
The scanner software will try to identify the top edge of the page and then rotate
9.6. HOW-TO
285
the image is right side up. Of course, if one placed the paper absolutely level, this automatic rotation would be unnecessary. However, it is difficult to place the paper perfectly flush against the top of the glass sheet; even if the placement is perfect, the act of closing the cover may twist the paper a couple of degrees. So, the scanner tries to compensate. Often, automatic rotation fails either because the image to be scanned is twisted relative to the top of the sheet — common when scanning a xeroxed page, for example, or because the contrast between the top of the page and empty space is so weak that the software cannot detect the top edge. The software allows one to rotate the image manually when automatic rotation fails. Usually, only a rotation of one degree, either way, is sufficient. • Cropping
When a xerox of a journal article is scanned, the scanner will scan the entire 8.5” x 11” page. If the goal is to copy a graph that occupies only a fraction of the page, then the extraneous material needs to be deleted. The cropping option allows one to move a box around the target image, using the mouse and cursor, and then cut away everything else. Cropping is easy but important because it tremendously reduces the size of the image file • Size Transformations
Scanning software allows one to change the size of an image. This is rarely needed because Latex, for example, can scale images when it prints them. (The image size can also be changed in a program like Photoshop or Illustrator). • Photoshop filters
Photoshop is a program for transforming bit-map images, which are the only kind generated by a scan. Photoshop offers a wide variety of “filters” to distort the shapes, change colors, and do almost anything one wishes to an image. The computer shelves at a local bookstore will offer a large collection of books devoted entirely to Photoshop. • Contrast
Scanning software usually has a built-in filter to manipulate the contrast of an image. • Lighten/Darken, Balance and Exposure
This lighten/darken filter allows one to manipulate what artists call the “key” of an image. A very dark image, composed almost entirely of dark grayscale, can be lightened to use a wider range of grays. Underexposure or overexposure of a photographic image will artificially change the key of an image. Therefore, Ofoto has a “balance” option which corrects for under/over exposure by automatically adjusting the image to a mid-range key. If this is inadequate, one can manually apply the lighten/darken filter. “Key” correction can be done more precisely in Photoshop. However, if one is going to scan a whole bunch of very dark or very light images, it may be useful to adjust the default on the scanner to automatically apply a lighten/darken filter, if the scanner software allows this. • Resolution
Usually specified in dots-per-inch (dpi). The default for line art is 300 dpi (which is the resolution of most laser printers). The default for photographs is usually 150
286
CHAPTER 9. SCANNING dpi because color images yield very large files when scanned at high resolution. However, the software allows one to vary the resolution within wide limits.
9.7
Choice of Scanning Resolution
There is a tradeoff in the user-chosen resolution of a scan: high resolution yields very large file sizes. It is silly to scan at 300 dpi if the image is intended for a Web site where it will be displayed at 72 dpi. What choices are good for different situations? The usual rules-of-thumb are the following: Rule-of-Thumb 1 (Scanning Resolution) If an image is to be used at its physical size at a desired resolution of X dpi (dots-per-inch), then the scanner resolution should be set, in the scanning software, to scan at 2X dpi. In other words, scan at twice the desired resolution. This rule is most significant for making Web sites. A computer screen has a resolution of only 72 dpi, so it is sufficient to scan images for the Web at 150 dpi. The exception is if the Web image is going to displayed at a larger size than the original. If a tiny picture only 3 cm on a side is to be displayed as 6 cm square screen image, then the original should be scanned at 300 dpi. This rule isn’t too useful for published images because journal typesetters have a resolution of 2000 dpi, far beyond the capabilities of most scanners in a scientific or engineering facility. Even a low cost laser printer has a resolution of 300 dpi; the better models are 600 dpi. This is roughly the same as the maximum resolution of low and medium cost scanners. For published images, the alternative rule is the following: Rule-of-Thumb 2 (Scanning Resolution for Print Publication) Scan at the print’s highest resolution, especially for line art [black-and-white images]. Although not strictly a part of “visualization”, scanners are often used to convert printed text into electronic form by first scanning the text and then deciphering using Optical Character Recognition (OCR) software. Rule-of-Thumb 3 (Scanning Resolution for OCR) Sullivan(1995), pg. 47, states that the best procedure is to scan at 300 dpi, black-and-white, which is the resolution that most OCR software is optimized for. Grayscale just slows down the OCR software and may degrade quality a little. Drawing programs like Adobe Illustrator allow one to import scanned images. An imported bitmap or EPS image may have some undesirable features such as very large file size and extraneous graphical elements. Often the simplest way to keep the essential parts of the image while eliminating the undesirable features is to trace the scanned image. Of course, manually tracing a complicated image can take a long time. Illustrator and its ilk therefore have an “auto-trace” option which lets the software do the tracing. Unfortunately, auto-trace is far from flawless. First, software in the year 2002 isn’t capable of making the subtle judgments that a human can: should two adjacent lines, perhaps separated only by scanner error, be joined into one or left with a pixel-size gap in between? Second, such decisions about what to join and what to smooth are problem-dependent, and even very sophisticated software will be unable to make all
9.8. SCANNING TRANSPARENCIES
287
the decisions correctly unless the software is somehow educated in the specifics of the problem. Nevertheless, auto-trace can take much of the work out of tracing a scanned image if one is willing to do some manual clean-up afterwards. Rule-of-Thumb 4 (Scanning for Auto-tracing) Sullivan (1995), pg. 47, states that “For autotracing purposes, only one thing counts — the highest possible resolution.” On pg. 80, he suggests that a good way to cope with a low resolution scanner (300 dpi) is to scan as a grayscale image. This is less subject to the jaggies than a black-and-white image.
9.7.1 Resolution and Resizing When one is saddled with a printer which has lower resolution than the scanner, one useful trick with a small image is to rescale it to larger size. For example, suppose the scanner has a 600 dpi resolution but the printer is limited to 300 dpi. If the image is doubled in size, and the scanning software is order to prepare the image for printing at 300 dpi, the result will use the same number of print dots as if the image were printed at its original size, but with 600 dpi resolution. The restriction of this trick is to print the image at N times its original size at a resolution of X dpi, the scanner must be able to resolve NX dpi.
9.7.2 Service Bureaus Most large cities and many universities have “service bureaus” or “university printshop” operations where very high resolution scanners are available. Industrial-strength scanners have a resolution of at least 2000 dpi. If very high resolution is needed, these specialized shops will provide it (for a fee). For photographs, the simplest way to high resolution is to use a purpose-built photograph/slide scanner.
9.8
Scanning Transparencies
Transparencies cannot be scanned in the same way as images in a book or on a sheet of white paper. The reason is that the green scanning light reflects off a sheet of white paper, but it goes through a transparency. The good way to scan transparencies is to use a scanner which has a transparency adapter. Such adapters are widely available, but add several hundred dollars (or more) to the cost of the scanner. So, many scanners don’t have them.
9.8.1 White-Paper-Trick The sneaky way to scan transparencies on an adapter-less scanner is to insert a sheet of white paper above the transparency. The scanning beam will then pass through the transparency and bounce off the white paper back to the imaging head — but only where not blocked off by the pigment on the transparency. This trick works well for transparencies which are colored only in black. We have no experience in copying colored transparencies this way.
288
CHAPTER 9. SCANNING
Figure 9.1: A comparison of scanning for opaque and for transparent media.
9.8.2 Newton Rings When a transparency is scanned on a normal flatbed planner, the interaction of partial reflections between the glass platen of the scanner and the transparency film can create patterns of concentric rings on the scanned image which are called “Newton rings”. These are not inevitable, and indeed can often be eliminated simply by repositioning the transparency film and rescanning. (The rings tend to occupy only a small portion of the image.) Transparency scanners therefore eliminate the glass sheet so as to remove any possibility of Newton rings.
9.9
Scanning Photographs
A photograph which has been printed or developed onto paper is an opaque object, and can therefore be scanned like any other sheet of paper. A photographic slide is transparent, and therefore should be scanned on a flatbed printer using the whitepaper-backing trick like other transparent media. The best option with slides is to use a purpose-built slide scanner. One great advantage of purpose-built slide scanners is that they have very high resolution, typically at least 1800 dpi. They also come with software specially designed to handle photographs, photographic negatives and so on. “They offer superior software algorithms for capturing the subtle differences between different transparency types and color negatives. Because film companies such as Kodak and Fuji manufacture their films differently for consumer and professional use, this can be a significant feature. Your sunsets look great when shooting Kodachrome because “amateur” films like Kodachrome and Fujichrome are oversaturated to give ‘truer’ reds and greens. Ironically, Kodak’s and Fuji’s professional E6 films are nearly indistinguishable — they don’t want to unduly influence a professional photographer’s results. Dedicated slide scanners have to know how to distinguish between these two film types. As a result, most transparency scanners come with a fairly complete list of different film types that the scanner software supports and thus can compensate for when scanning.” (Sullivan, 1995, pg. 37).
9.10. SCANNING MATERIAL OBJECTS
9.10
289
Scanning Material Objects
Sullivan (1995) notes that a scanner will often give good images of objects such as a dime or a bottle of white-out. It is helpful to put a sheet of white paper or Bristol board on top of the object to give a better image. It is usually necessary to use Photoshop to clean up the background. Still, this might be a good way to put images of small pieces of computer equipment or experimental apparatus into an image. However, digital cameras as noted earlier are usually better unless the object is small. A closeup so that the object fills most of the picture may then be beyond the minimum focal distance of the camera.
9.11
Tone Curves, Gamma and All That
Definition 19 (Tone Curve (of a Scanner)) This is a curve that gives the scanned brightness (output) as a function of the intensity of the image being scanned (input). By convention, the horizontal axis of the plot of a tone curve is input and the vertical axis is for output intensity. Ideally, the default tone curve of a scanner is linear, but this is never exactly true. However, to understand the adjustments that can be made by software, it is helpful to pretend the default tone curve is linear. Scanning software has the ability to increase or decrease contrast so as to reveal details in deeply-shadowed areas, for example, that would be lost if scanned using the scanner’s default settings. However, there are some subleties. First, a few scanners and many image-processing programs allow for the linear controls of “contrast” and “lightness”. Sullivan detests linear corrections to the tone curve because they usually lead to loss of data. Definition 20 (Contrast Adjustment (of a Scanner)) The angle of the tone curve is increased or decreased. When contrast is increased, a range of dark on the image is output as black and a range of light tones is also output as white (right middle panel in Fig. 9.2). Information is lost because a whole range of intensity is mapped to a single tone. When contrast is decreased, the output range is truncated. A low-contrast image does not use the blackest blacks or the lightest whites; we have the approximate equation low-contrast
↔
all-grey, black-free & white-free output
Definition 21 (Lighten/Darken (of an Image)) The tone curve is moved up or down without a change in shape or slope. (An artist would refer to this as raising or lowering the “key” of the image.) Lightening adds a constant amount to each tone in the output. A range of dark tones is thus truncated from the image: lightened
↔
grey & white, black-free output
darkened
↔
black & grey , white-free output
290
CHAPTER 9. SCANNING
Output
Default: Γ=1
Output
Γ=1.5
1
1
1
0.5
0.5
0.5
0
0
1
Low Contrast
1
0.5
0.5
0
0
1 Output
Γ=0.5
Lightened
1
0.5
0 0
0 0
High Contrast
0.5 Input
1
Darkened
0.5
0.5 Input
1
0 0
0.5 Input
1
Figure 9.2: Tone curves for an image, with and without the use of various filters. Contrast uses the full output range of the scanner, but there is loss of data because part of the input range, either the black end or the white end, is ignored. Lightening and darkening use the full input range, but part of the output range is ignored. In contrast, scanner software allows easy manipulations of the tone curve which force it to be nonlinear, but preserve the totality of both the input and output range. The simplest nonlinear tone curve manipulation is to vary the parameter called “gamma”. Definition 22 (Gamma) “Gamma” is a numerical parameter which specifies the brightness of midtones relative to default. Thus, Gamma=1.0 is the default. Gamma = 0.75 improves resolution in light areas; Gamma = 1.5 improves resolution in dark areas. The ends of the tone curve (blackest-input-to-blackest-output, and similarly at the white end) are not altered by manipulating Gamma. Sullivan is a big fan of Gamma manipulation because the full input and output ranges are preserved. When Gamma is set equal to 0.75, the midtone input is mapped to a darker tone on output so that the tone curve becomes a parabola dragged down below the default line curve. Thus, the brighter half range of tones in the image is mapped to say, two-thirds of the range of tones in the output. Thus, contrast is increased for the lighter tones.
9.12. SUMMARY
9.12
291
Summary
1. Scanners come in an enormous range of prices, but good inexpensive flatbed scanners are now widely available in stores and in university computer labs. 2. Transparencies are best scanned in a scanner with a transparency adapter which eliminates the glass sheet on which the paper rests when scanning paper. However, an ordinary flatbed-scanner-with-glass can usually be employed successfully, too, with the aid of one or more of the following tricks: (i) Insert blank white paper on top of the transparency. (ii) Reposition the transparency if “Newton rings” appear. 3. Photographs on paper can be scanned like other images on paper; slides can be scanned as transparencies, but the best option is to use a purpose-built slide scanner, which has very high resolution and software that can correct for the idiosyncrasies of various kinds of film. 4. Scanning can be performed without a scanner by using the following alternatives: (i). Video camera (with a computer frame-grabber board). (ii). Photo CD (iii) Extraction from PDF files (iv) Digital camera 5. An excellent reference on scanning is the following short monograph: Make Your Scanner a Great Design & Production Tool by Michael J. Sullivan, Northlight Press, Cincinnati, 160 pp. (1995).
Chapter 10
Halftones, Photos and Grayscale Printing 10.1
Continuous-Tone and Black-and-White
A computer screen and a photograph are both examples of continuous-tone media. The phosphors that are sprinkled on the inside of the glass of cathode-ray tube glow with an intensity proportional to the strength of the electron beam striking them. By varying the beam strength, the monitor can vary the glow of the smallest addressable pixel from black to white continuously. Similarly, a photograph emulsion can vary continously on the smallest scales visble to the eye.1 In contrast, a laser printer, an offset lithographic printer, an ink-jet printer and a xerox copier are all black-and-white devices. These printers cannot vary the composition of each tiny drop of ink, but instead can only throw drops of solid black ink or toner. Nevertheless, these monotone printers are capable of printing gray? How? The answer is that monotone printers organize the smallest addressable dots into larger blocks. There is no standard name for these blocks; perhaps we can call them “screen-blocks” by analogy with half-tone screens, which will be explained below. The smallest addressable area that can be targeted by a single drop of ink or toner is usually called a “pixel” by analogy with the smallest unit of a monitor screen. If the screen-block is an 8 x 8 array of pixels, then the monotone device can represent 65 different shades of gray by putting between zero and 64 drops of ink in a given screen-block. The good news is that this more shades of gray than the eye can usually distinguish. The bad news is that the effective resolution of the grayscale image is much poorer than the dots-per-inch of the printer. A 65-shade grayscale image on a 600 dpi printer has a resolution of only 75 screen-blocks per inch, and this is poor enough to be noticeable. One can obtain higher resolution by using few shades of gray. A 4 x 4 array of pixels allows only 17 shades of gray, but the resolution with a 600 dpi printer is doubled to 150 screen-blocks per inch. With a monotone device, there is thus a tradeoff between the number of shades of gray and resolution (Fig. 10.1). 1 On an invisible scale, of course, the electron beam is made up of discrete quanta, the phosphor is composed of discrete molecules, and the photographic emulsion contains microscopic grains; on the nanoscale, everything is discrete. However, the discreteness of a CRT monitor and a photograph is on such a fine scale that it is not visible to the eye.
293
294
10.2
CHAPTER 10. HALFTONES, PHOTOS AND GRAYSCALE PRINTING
Halftones and Photographs
Many decades ago, a clever technique for transferring continuous-tone photographs to monotone printers was developed: halftone-screening. The name is a misnomer: the result of halftoning is a photolithography plate or an etched printing plate which is monotone. However, just as in modern printers, a halftoned image simulates grayscale by very fine dots which appear various shades of gray when seen from normal viewing distance. The key idea is diffraction. The earliest screens were lattices of thin, criss-crossing wires, little different from ordinary window screens except that the mesh was finer. When light bounces off a photograph and through the mesh, it is diffracted. The diffraction translates intensity into volume. The diffracted image consists of a pattern of solid-black dots whose area is proportional to the shade of gray falling on that little cell of the screen. When very pale gray falls on a particular screen-block, a tiny black dot appears on the far side of the screen. When little light falls on a cell, a large black shadow appears within that cell. By employing a chemical process that etched away a metal plate where light fell upon it while leaving the black dot untouched, the fine network of variously sized dots in the diffracted image would be left as raised areas on the printing plate. The philosophy is similar to a modern laser or ink-jet printer: a small area of blackand-white is percieved as a shade of gray whose lightness depends on the rate of blackto-white within the small screen-block. However, the means of achieving this ratio of black-to-white is different. There is only a single black dot within each block of a halftoned image, but the blocks are of variable area; a laser printer lays down a varying number of dots within the screen block, but the dots are all identical in size (Fig. 10.2). For obvious reasons, the resolution of a halftone image are expressed in lines-perinch or lpi where “line” is simply the spacing between neighboring parallel wires in the screen-mesh. Our 600 dpi laser printer, laying down 65 shades of gray through 8 x 8 arrays of pixels, each array 1/75-th of an inch across, has an effective lpi of 75. In modern offset lithography, the etched metal plate has been replaced by a film, and the wire-mesh screen has been replaced by a film or sheet of plastic, too. Modern screens have a checkerboard of very fine, slightly diffuse loads imprinted upon them. To get the proper diffraction, the screen film needs to be as close as possible to the photolithography film. The usual technofix is use a vacuum seal so that the screen is literally sucked onto the photolithography film. There are three types of screens in widespread use (plus additional specialty screens): “square”, “elliptical” and “stochastic”. The usual screens create a pattern of squarish dots so that the “midtone” pattern — half-black, half-white — looks like a checkerboard with the black squares just touching at the corners. A modern variation staggers and
Figure 10.1: The same pattern printed on a 300 dpi printer using a 75 lpi screen (left) and a 150 lpi screen (right). The lower screen frequency actually gives a much betterlooking picture.
10.3. LPI AND PAPER
295
angles the squares on the screen to produce a so-called “elliptical” screen. This helps to minimize “dot gain”, which will be discussed more below. When high resolution images needed to be converted to grayscale, software can define the dot pattern. However, the range of patterns can be wider because the computer is not restricted by the need of a mechanical wire-mesh to hold together. The “stochastic” screen lays down a pattern of random dots whose density controls the shade of gray. In contrast to conventional screens, all the dots are the same size. “Stochastic” screens are also called “FM” or “frequency-modulation” screens because the frequency of dot deposition varies with the desired shade of gray. Stochastic screens are used for very high quality photographic reproduction. (A 600 dpi scanner can save effectively scan at 600 lpi resolution, far higher than can possibly be printed; the task of the software is to create a printable pattern of dots which preserves as much of the scan information as possible.) Because there are no regularly spaced lines is a stochastic screen, the “lines-per-inch” measurement standard does not, strictly speaking, apply. Nevertheless, the effective resolution per block of gray is still much lower than the black-dot-per-inch resolution of the printer. Some limits are inescapable! Laser printers and ink-jet printers produce identical dots, as noted previously, whereas the dots produced by a physical screen on a photolithography plate are variable in size. Usually, the nonuniform dots of the film screen do a better job of fooling the eye than the uniform dots of the computer printers at the same lpi. This has further motivated the use of stochastic or FM screening when the final output device is a computer printer.
10.3
LPI and Paper
Newspapers usually employ halftone screens with resolutions of 65 to 85 lpi. Finer screens are useless because newsprint is coarse, absorbent and printed with watery inks. Even if a printer spits a dot of ink only 1/600-th of an inch in diameter at a piece of newsprint, the final printed dot will be much wider because the ink will spread out a fraction before drying on the coarse, textured paper. Printed books and glossy magazines use better paper and screens with 133 to 150 lpi. Most web presses cannot support an lpi higher than 150 because they rotate so rapidly, and the ink must therefore dry so quickly on mechanically-stretched paper, that the minimum drop size is inadequate for higher resolutions.
10.4
Dot Gain
Definition 23 (Dot Gain) This is a printing defect in which the dots dry at a larger size than specified by the printing plate.
Figure 10.2: Closeup of output pixels forming a halftone screen-block from a photographic-and-physical-screen halftone (middle) and a laser printer (bottom).
296
CHAPTER 10. HALFTONES, PHOTOS AND GRAYSCALE PRINTING
Low resolution printers, acqueous inks and porous or textured paper contribute to dot gain. In a web press, the paper is stretched around a drum while being printed, and this mechanical stretching imposes its own limits on the minimum dot size. Dot gain is a very unpleasant problem for printing halftones because when the dots are larger than intended, the whole printed image is darkened. Dot gain also tends to create noticeable jumps in shade or color. Elliptical halftone screens and stochastic screens help some. However, the best defence against dot gain is restraint; being greedy for high resolution leads to ugly printed images when the paper or the printer aren’t up to the task of printing a halftone that has been created with a very high lpi screen.
10.5
Xeroxing Halftones
Xeroxes of halftones usually look rather bad. The reason is that it is very uncommon for the little dots of toner to match the size of the dots of the halftone. This leads to “dot gain”: the xerox has big dots where the halftone had small ones. A midtone that consisted of 32 tiny dots of black interspersed with 32 dots of white in a given screen-block will appear in the xerox as 32 larger blocks that fill almost the entire screen-block. The result is that the xerox has turned gray into block, and the image is almost unrecognizable.
10.6
Rescreening
It is usually a very bad idea to try to make a halftone from a halftone. The reason is that the dots of the original halftone are so small that they are probably close to the resolution limits of the scanner, and likely beyond the resolution of a xerox machine. Consequently, some dot gain will occur in the scanned image. When the scan is printed, more dot imperfection will happen because the printer is being asked to reproduce dots near the limits of its resolution. Suppose, for example, that the scanner records dots which are each 1/300-th of an inch in diameter, and these must be reproduced on a 600 dpi printer. If the scan dots are perfectly aligned with the printer dots, then all is well: the printer can print each scan dot as a 2 x 2 array of ink-jet drops. Only all is not well: the drops of the jet are round, but the scan dots may have been bounded by diamonds or slanting ellipses. In that case, the printed array of four dots will not exactly match the shape of the scan dot, and some distortion of the gray shade will happen. If the scan dots are not exactly aligned with rows and columns of the array of ink dots, then the printer cannot even come close to matching the scan dot. It is not possible for the printer to lay down a pattern of half-disk plus a full circle plus a half-disk to match a scan-dot that is two ink dots wide, but displaced by half a dot. The interaction between the spacing of the scan and the spacing of the ink dots can lead to interference patterns which create so-called moir´ e patterns. These oscillations in shade are due to frequency-aliasing. They were first seen in the shimmering patterns of watered-silk. Because the moir´ e patterns usually have a spatial frequency that is small compared to that of the printer and scan frequencies — the frequency of the moir´ e pattern is the difference of the printer and scan frequencies — the watered-silk variations in shade are very obvious. These moir´ e patterns can be eliminated by “rescreening”. A special calculating tool is used to estimate the frequency and angle of the screen used to create the halftone.
10.7. PHOTOSHOP AND HALFTONES
297
If the new halftone matches this, then spatial frequency aliasing is suppressed. Unfortunately, the problem of dot gain and dot shape distortion cannot be suppressed. So a halftone of a halftone will still look crummy.
10.7 Photoshop and Halftones A grayscale image is always printed as a pattern of black dots. Photoshop and other image-processing software allows one to control this conversion. Image ⇒ Grayscale ⇒ Bitmap initiates this process. It pops a dialogue box that offers four options for the conversion, the last of which is “Halftone”. If this is selected by clicking on the button, then the Halftone Dialog Box appears. This offers options of line frequency (lpi) and shape of dot. One must be careful; if the image is specified to have an output of only 72 dpi (monitor resolution), then specifying a high frequency will still leave a very coarse image. To successfully use a high lpi, one needs to have first scanned the image at a much higher dpi, and then specified a very high dpi for the output before the halftone conversion is attempted.
Chapter 11
Lighting and Surfaces 11.1
Introduction to Lighting
Three-dimensional surfaces can be drawn as meshes or wireframe diagrams, and these are often useful. However, a wireframe turns off most of the visual cues that we use to perceive three-dimensional objects in the real world. Coloring, shading and highlighting the surface can help. To understand the possibilities, we need to understand how real objects react to light, and how computer graphics simulates this. There are three species of light (or “illumination models”): 1. Intrinsic (self-emitting) 2. Ambient light (sometimes called “diffuse light”) 3. Light sources (that is, concentrated, lamp-like sources) There are two kinds of reflection: 1. Specular (“mirror-like”) reflection 2. Diffuse (“Lambertian”) reflection When the surface is approximated as the union of a lot of flat-sided or non-planar polygons, there are three kinds of shading: 1. Flat (also called, more precisely, “faceted”) 2. Gourard 3. Phong There are two strategies for computing the total light environment: 1. Ray-tracing 2. Radiosity There are several strategies for applying a texture to a surface including: 299
300
CHAPTER 11. LIGHTING AND SURFACES
1. Texture mapping 2. Bump mapping 3. Reflection mapping In this chapter, we will discuss each of these in turn.
11.2
Lighting or Illumination Models
A graphics window may display many objects, some of which are brightly illuminated and others which are in the shadows. It follows that to discuss lighting models, we must take it one-object-at-a-time. “Intrinsic” light is the light emitted by the object itself, such as the glow from a TV screen, a light-emitting diode, or a star. “Ambient” light is an illumination that seems to come from all sides. In the real world, light scatters off the walls of a room (or the ground) and then bounces off an object and then to our eyes. In scientific visualization, ambient light is usually assumed to be uniform, that is, to be coming with equal intensity from all directions. In photorealistic graphics, the ambient light is allowed to vary so that it is relatively intense in the directions subtended by walls painted in glossy white and relatively weak from dark, light-absorbing wood paneling. Ambinet light is sometimes also called “diffuse” light, which is rather misleading because it has nothing to do with diffusion. “Light sources” are lamps, but lamps in the narrow sense of a source of oncescattered light that bounces directly off the object into our eyes. A real-world lamp is usually a source of both once-scattered light as well as multiply-scattered light. By convention, “light source” is used to describe the once-scattered light only while “ambient light” is applied to light that bounces off something other than the graphic object before reflecting, in the final scattering, from the object itself. In photorealistic graphics, light sources can be extended objects, that is, the graphics calculation must allow for the fact that a fluorescent overhead light may be several feet long, and is most effective at lighting objects directly underneath. In scientific graphics, it is usual to pretend that all “light sources” are point sources, sufficiently far from the object that all rays fall onto it from a single angle in a spherical coordinate system centered on the middle of the object.
11.2. LIGHTING OR ILLUMINATION MODELS
AMBIENT
301
LIGHT SOURCE
INTRINSIC (SELF-EMITTING)
Figure 11.1: Schematic of the three sources of lighting for an object.
302
11.3
CHAPTER 11. LIGHTING AND SURFACES
Reflection
The scattering of light from an object is usually described by considering two extreme cases: specular reflection and diffuse reflection. Real objects reflect light as a mixture of these two extremes, but by adding a little bit of diffuse reflection to a little bit of specular reflection in some object-dependent fashion, one can obtain a good approximation to the scattering from almost anything. “Specular” is derived from the Latin “speculum”, which means “mirror”. If a line is drawn perpendicular to the surface (the “surface normal”, shown in Fig. 11.2 as a dashed line) and the incoming ray makes an angle of θ with the normal, then all the reflected light will also make an angle of θ with the normal but on the opposite side. If the object has a curved surface, then the eye will see only that part of the surface where the angle condition is satisfied. The bright reflection from that small part of the surface is a “highlight”. Real objects are never perfectly mirror-like; under a microscope, every surface is pitted with small peaks and valleys. These bumps scatter the light at all angles as illustrated in Fig. ??. The intensity of the scattered light is ILamber t = Isour ce kd cos(θ) = Isour ce kd (N · L)
(11.1)
where Isour ce is the intensity of light from the source (as measured by the energy falling on a plane perpendicular to the incoming rays), kd is the “diffuse-reflection” or “Lambertian coefficient”, θ is the angle between the surface normal and the incoming light from the source; in the alternative form, N and L are the unit normal and a unit vector pointing at the light source, respectively, with the dot denoting the usual inner product of two vectors. Lambertian reflection gives a “matte” finish to an object. It is common to fudge the appearance of diffuse reflection by the empirical artifice of adding an exponent to the cos(θ) term to modify the calculated reflection to n ILamber t = Isour ce kd cos(θ) d
(11.2)
where nd is the “diffuse reflection exponent” or “Lambertian exponent”. Taking nd < 1 gives a broader, more diffuse ring of light from the object whereas nd > 1 gives a more concentrated ring of light than the default nd = 1. A major difference between the two types of reflection is that in their purest form, the color of Lambertian reflection is the color of the object. In contrast, in specular reflection, the default color of the reflection is the color of the light source. The specular-is-source-color assumption is accurate for plastic, but inaccurate for metal and velvet. The highbrow way to correct for this is to use either the TorranceSparrow or Cook-Torrance lighting models, which use a theory of microfacets and some physics. A lowbrow way is to provide the user with a tweakable parameter that makes the reflected color a weighted average of the object color and the light source color. The usual (simplest) formula for specular reflection is Ispecular = Isour ce ks (N · H)ns
(11.3)
where ks is the specular reflection coefficient (which depends on the material the object is made of), ns is the specular reflection exponent, and H is the “halfway” vector which is halfway between L, the vector pointing at the light source, and a vector V that points at the viewer’s eye. If H is parallel to the surface normal N, then the viewer will see the highlight, so H is the known as the vector of “maximum highlights”. (For a perfect
11.4. SHADING
303
mirror, H would be more precisely the vector of “only highlights” since that point of the surface would be invisible if H did not parallel N, but real lights are not point lights, and real surfaces are not perfectly mirror-like.)
11.4
Shading
A scheme for applying color to the polygons of a surface is called a “shading” model. It might equally well be called a “coloring” model except that the methods are equally applicable to grayscale. The simplest model is called “flat” or “faceted” shading. Flat shading means that the color or grayscale is uniform within each polygon. This is computationally cheaper than any of the other alternatives (except setting the face color equal to none, and thus reducing the surface to a mesh). However, unless the polygons are very, very numerous, there will be obvious discontinuities of color across the edges of each polygon. In photorealistic graphics, this is almost always a bad thing. In scientific or engineering graphics, it may be okay. If the object is a crystal, for example, the flat-sided facets are real, and color discontinuities actually make it easier for the viewer to perceive the true shape of the crystal. Similarly, scientific graphics almost always allow the user the option of a black mesh to emphasize the edges between different polygons. Even when the model object has a smooth surface, the mesh and flat shading may be useful in identifying the subdomains of the finite element or spectral element that was used to compute fluid flow or elasticity or other properties of the surface. Gouraud shading is the next step up in both photorealism and computational cost from flat shading. (This method is named after its inventor, Henri Gouraud, whose name rhymes with “Thoreau”.) The first step is to compute the vertex normals, which are the normals to the surface at the vertices. Of course, a vertex is a “point”, which casts serious aspersions on the concept of “perpendicular”, which can be defined only relative to a surface. The vertex normal is defined by computing the normals to the surfaces of each of the faces that meet at a given vertex and then taking the average.
Specular Reflection
Diffuse Reflection θ
θ Light
θ
Light
Figure 11.2: Two species of reflection. In diffuse or Lambertian reflection, the light scatters in all directions. However, the intensity of the reflection light is proportional to the intensity of the source multiplied by cos(θ), multiplied by a constant kd < 1 that depends on the reflectivity of the object. θ is the angle between the incoming rays from the source and the surface normal, which is shown as the dashed line perpendicular to the surface, which is the horizontal thick line. In specular or “mirror-like” reflection, the reflected light is concentrated in a narrow angle which makes the same angle θ with the surface normal.
304
CHAPTER 11. LIGHTING AND SURFACES
The vertex normal provides the angle θ between the surface and the incoming rays from the light source. The second step in Gouraud shading is to apply the formulas given in the previous section to compute the Lambertian and specular reflection for each vertex. The third step is to interpolate the reflection between the reflections at each of the vertices that define a given face so as to compute a smoothly varying reflection for each pixel on a given polygon. The color discontinuities are completely eliminated. Phong shading, originated by Phon Bui-tuong, is much more expensive than Gouraud shading. The reflectance is calculated at many sample points on a given face instead of just at the vertices. The result is a more realistic shading. However, the improvement is often small, so Gouraud shading is still widely used. Scientific and engineering visualization, because they rarely strive for photorealism, does not desperately need the extra fidelity of Phong shading. However, because the rendering times for scientific graphics are rather short, again because of the lack of photorealism, the price for Phong shading is usually only an extra second or two.
11.5
Ray-tracing and Radiosity
Ray-tracing and radiosity are both schemes of “light bookkeeping”. In the first method, rays are traced from the light source to various objects and thence by reflection to the viewer’s eye, or in reverse from the eye to the light source. (Reverse, eye-to-source raytracing is the more common than direct tracing because it omits rays from the source that are reflected away from the viewer and thus are irrelevant to the displayed image.) Radiosity eschews rays in favor of breaking down all objects (including the walls and other contributors to the ambient light) into lots and lots of patches. Each patch is then treated as an emitter or a reflector. The radiosity method then computes the interactions of each patch with every other patch. Radiosity software is rather complicated because it employs a lot of tricks to ignore the interactions of distant patches with one another, and thereby reduce rather humongous calculations to a managable length. Ray-tracing is computationally intensive, too. One major difference between the two methods is that ray-tracing is view-dependent. If the viewing angle is changed, then all ray-tracing calculations must be redone from scratch. In contrast, radiosity is viewindependent in the sense that only a small fraction of the overall calculations must be repeated when the viewing angle is changed. Radiosity is very popular in virtual reality simulations and in architecture computed-aided design. For the latter, for example, the computer can precalculate most of the numbers it needs to present an entire building. The client can then take a virtual walk-through the building; the workstation is able to present changes of view so quickly that the client does not become bored and distracted between scenes because the computer only has to recalculate a tiny portion of the overall radiosity computations each time the view is changed. The other major difference is that ray-tracing is oriented towards specular reflection; ambient light can always be modelled as the union of N light sources where N is sufficiently large, but the work of ray-tracing ambient light is then N times the labor of tracing a single light source. The radiosity method, in contrast, is optimized for diffuse reflection and ambient light. The light in most architectural structures tends to be rather diffuse, which is another reason that architectural graphics are dominated by the radiosity method. In an environment with both light sources and ambient light, ray-tracing and radiosity can be combined. Some applications use radiosity for non-reflective surfaces and ray-tracing for reflective surfaces.
Chapter 12
Color 12.1
Introduction
Image-processing programs like Photoshop and Illustrator support a bewildering variety of color models. In place of the simplicity of the eight-color crayon box or the elementary school claim that there are only three primary colors, one has a blizzard of RGB, CMYK, HSB, PANTONE, Duotone, Bitmap, Grayscale, and a host of other characters. Where does all this come from, and what does it have to do with scientific graphics. The short answer is that the human visual system, a computer monitor, and a printer all reproduce the color spectrum in different ways. In part, the multiplicity of color models and jargon reflects the different physics of different color-making and coloranalysis hardware. However, the variety of models also reflects that artists approach the world differently from their hardware, and this introduces additional ways to look at color. Finally, other color schemes have been introduced because of the practical needs of the publishing industry. In this chapter, we will try to sort them out.
12.2
Spectroscopy: the Digital and Analog Eyes
A spectroscope splits light into many spectral bands and computes the intensity in each band. It is a sort of digital eye. It would be very difficult for a scientific visualization system to reproduce a spectroscopic analysis; each pixel would need to have thousands of elements, one for each band resolvable by the spectroscope. Fortunately, the human visual system can only resolve three broad bands of color. This makes it possible for color televisions and monitors to produce very realistic color using just three different colors of phosphors (red, green, blue) for each pixel. However, the input from these color-channels is processed in very sophisticated and complex ways by the human visual machinery. When the eye perceives a lot of light in both the red and blue channels, but little in green, it produces a distinct color “purple”.
12.3
Emission: Red-Green-Blue (RGB) or “Additive” Color Model
A computer monitor or television screen glows because phosphors on the screen are blasted with a controlled beam of electrons. Screen light is thus emission of light. 307
308
CHAPTER 12. COLOR
The three primary colors of emission are red, green and blue. These correspond to bands of wavelengths in visible light: red is the band of long wavelengths, blue is the the band of short wavelengths, and green is intermediate. Emission color is therefore described by the RGB (Red-Green-Blue) color model. Since there are three phosphors, each emitting in a different band, all monitor-displayable colors are described by specifying the intensity with which each of these phosphors is stimulated. Put another way, three numbers describe a color, and each number is the intensity of red, green, or blue.
12.3.1 The Purple Phosphor The eye perceives purple as distinct from red and blue. Why then, couldn’t one apply a different color model with purple as one of three primary colors? The answer is that it is almost impossible to make a purple phosphor. Such a phosphor would have to emit strongly in both the red and blue parts of the spectrum, but not in the middle (green). It would have to emit with roughly equal strength in both red and blue, or the purple wouldn’t be very purplish. It would have to have identical power-to-emission curves in both red and blue. One complication with phosphors is that the intensity of the emitted light is not a linear function of the power applied to the phosphor. Monitor circuit corrects for the nonlinearity. A purple phosphor would likely have different nonlinear response curves for blue and red. The phosphor might shine as a reddish-purple at low intensity but a bluish-purple at high intensity, for example. This would make it very difficult to control the color. If the primary phosphors were red, green and purple, then it would be very difficult to make a pure blue at low intensity because the purple phosphor is the only phosphor capable of making blue, but at low intensity (by assumption) it generates even more red. Thus, a useful emission model that replaces red or blue with purple would be very impractical. RGB is the fundamental emission model because it is fairly easy to create three different phosphors that emit in a single contiguous band of visible light, and these bands are red, green and blue.
12.3.2 Additive Color Model To build up more complicated colors from the three primaries, we add the emission from different phosphors. The RGB model is therefore said to be an “additive” color model.
12.4
Reflection: The Cyan-Yellow-Magenta-Black “Subtractive” Model
Unlike a cathode ray tube monitor, a sheet of paper has no internal energy source. The light which allows us to read a sheet of paper is light which has come from an external source, such as the sun or a lamp. As a first approximation, we can pretend that the light source is white, that is, a blend of red, green and blue. The reason that we do not see white on a printed page is because the dyes in the ink absorb some of the white light.
12.4. REFLECTION: THE CYAN-YELLOW-MAGENTA-BLACK “SUBTRACTIVE” MODEL309
Figure 12.1: A comparison of the primary additive and subtractive colors, showing how other colors are constructed from the primaries. Because paper is an absorbed of colors rather than an emitter, printing is forced to use a different color model than screen display. The standard print employs cyan, magenta and yellow as the primary colors. Why not use red, green and blue as the primary colors? To make a printed image appear red, one must use a mixture of dyes which absorb in both the green and blue bands of the spectrum. This is not a difficult technical problem, and indeed every printing shop has red inks. However, red is not a primary “reflective” color because the red ink is absorbing in two of the three bands of wavelength, not one. A dye which absorbs in only the green band will reflect both red and blue, creating a reddish hue which printers usually call “magenta”. When printing a photograph or other image with a wide range of colors, it is not feasible to use a bright, emission-type red as a primary color. By eliminating two of the three bands of color, a red-appearing dye leaves too little control for the other primary dyes. Instead, we have the relationships blue-absorbing
=
yellow
(12.1)
green-absorbing
=
magenta
(12.2)
red-absorbing
=
cyan
(12.3)
In theory, the mixing of all three subtractive colors will give black. In practice, mixing the cyan, magenta and yellow inks gives only a muddy-black, a dark brown. This looks very bad when used for figure labels and the main text, which should be black-on-white. For this reason, a fourth ink which is very absorbing is added to give black. In the usual acronym, black is denoted by“K” to avoid confusion with blue. The usual subtractive color scheme requires four inks. It is abbreviated CMYK for Cyan-Magenta-Yellow-Black. Fig. 12.2 shows how different colors are constructed from the primaries in the two color systems. Fig. ?? is another popular aid to understanding the models, the so-called “color cube”.
310
CHAPTER 12. COLOR
Figure 12.2: “Color cube”. The numbers next to each color indicate its representation in the RGB color scheme. Thus, red is (1,0,0), green is (0,1,0) and blue is (0,0,1). The subtractive colors are each a mixture of two of the RGB colors; the color which is zero in the numerical label of a subtractive color indicates which RGB color that substractive color absorbs. The Visualization of Natural Phenomena by Robert S. Wolff
12.5. GAMUT
12.5
311
Gamut
The range of colors that can be represented by a color model is called the “gamut”. A crucial point is that the gamut of CMYK inks is smaller than the gamut of RGB screen phosphors. This means that many bright hues which look fine on a computer monitor cannot be effectively printed. Naive users are often very surprised that bright colors print rather dully. Illustrator and Photoshop provide some help. When moving the colored sliders in the RGB model, a little yellow triangle with an explanation point sometimes appeared. This is a warning that the RGB color, as chosen by the instantaneous position of the red, green and blue color sliders, is outside the gamut of CMYK. Such a color will display well, but print badly.
12.6
Hue-Saturation-Brightness (HSB or HSV) Color Model
Drawing and image-processing programs provide ways to adjust a color by moving sliders that control the intensity in each of the primary colors — one slider for red, one for green, one for blue in the RGB model. Although the RGB and CMYK models are closely connected to the physics of emission and reflection, respectively, manipulating color sliders is not an artist’s or a photographer’s way of manipulating color. For this reason, many image-processing programs offer a third model, which is called the HSB or HSV model. (The third letter is for a property which is variously called the “brightness” or “value’; the “brightness” label seems to be growing in popularity. “Hue” is a synonym for “wavelength”. A “red hue” means that the color is centered in the long wavelength region of visible light. The “saturation” is a little more subtle. In graphics, “color” and “wavelength” never denote precise quantities as in spectroscopy. Rather, a “red” is always a broad band centered on the red part of the spectrum. A smooth Gaussian shape for the distribution of intensity versus wavelength implies that “red” usually has a little intensity in the green and a tiny bit in the blue parts of the spectrum, too. The “saturation” is the inverse width of this distribution of intensity versus wavelength. A “fully saturated” color has a narrow distribution with near-zero amplitude in green and blue. A weakly saturated red has some green and blue, too. However, the Gaussian shape of a spectroscopic band is misleading. In the graphics world, a better model is a peak about some wavelength plus a background of white light. The saturation is the amount of this white background. An unsaturated image is pure white. A fully saturated image has no white and is narrowly peaked in wavelength as already asserted. The “brightness” is the intensity of a color, the amount of energy being pumped toward the eye by the pixel. Some purists reserve “brightness” for self-luminous or emitting objects (like computer monitor phosphors) while reserving “lightness” to describe intensity-in-reflection. However, this distinction is usually ignored. The reason that HSB model is helpful is that a child picking crayons out of 64-color Crayola box does not think “20 % green, 40 % blue, 70 % red”, which is the RGB way of describing a color. Instead, a child first thinks “Trees — I need some green.” This is a choice of hue. The second question is the choice of saturation, “dark red” versus “red” versus “pink”. The third question is: “How hard do I rub the color on”, which is a choice of intensity. Professional artists pose the same questions often without conscious thought. But the simple choice of “red” versus “pink”, which is easy in the HSV system and hard in
312
CHAPTER 12. COLOR
either RGB or HSV, explains why this third color system is used.
12.7 Uncolor Models: Bitmap/Line Art and Grayscale Most image-processing programs support a mode which stores only 1 bit per pixel. This is sometimes called “Bitmap” mode, as in Photoshop, and sometimes “Line Art” mode, because it is appropriate for many species of scientific graphs where the curves are drawn in black-on-white. All colored modes support black-and-white images, too. However, the file size of an image is enormously reduced when only 1 bit is stored per pixel than when 8-bit color intensity numbers are stored for each of three or four primary colors. The other major uncolor mode is grayscale. This is always one byte or eight bits per pixel, which is sufficient to specify 256 levels of grayscale. In practical terms, this is far more levels than the eye can readily perceive. There is little pressure to increase the number of levels because of this human visual limit; there is little pressure to reduce the number of levels below 256 because computers can handle information efficiently only in 8 bit or one bit groups.
12.8
Duotone
Because four-color printing is so expensive, a lot of children’s book are printed using just two colors. “Duotone” is the technical term for a mode that supports just two colors. Duotone is rarely used in science.
12.9
Indexed Color
To reduce image size, many graphic systems do not store bytes for the red, green and blue separately at each pixel, but instead store only a 1-byte index into a palette of 256 colors. This greatly reduces file size at the cost of a little photo-realism. Because computers and storage devices have improved enormously, indexed color has diminished in importance relative to 24-bit or 32-bit RGB and CMYK color. However, indexed color is unlikely to go away any time soon. One reason is historical. Matlab’s ubiquitous colormaps are indexed color. Because 256 colors are quite adequate for most scientific visualization, a domain where photorealism is a low priority, there is little pressure for Matlab’s coders to undertake the enormous chore of rewriting codes to allow a wider range of color. Many other software systems have a similar historical legacy. Another reason is that Web bandwidths are still mediocre. An indexed image can be transmitted three times as fast as a 24-bit RGB image. For this reason, Web images are almost always stored in a file format such as GIF which employs indexed color.
12.10
Spot Color
Professional-grade drawing and image-handling programs support “spot color”. The usual CMYK inks, also known as “process colors”, can never exactly represent the full range of colors that a graphic designer might wish for. In particular, the CMYK inks are relatively poor at representing very bright colors. For that reason, some high-end
12.11. PANTONE COLORS AND ALL THAT
313
printing jobs supplement the usual four inks with additional inks whose sole purpose is to cover parts of the page with a pure, bright color. These additional inks are called “spot colors”. Logically speaking, “black” is a spot color. However, black is so important, and the use of a black ink to supplement cyan, magenta and yellow, is so common that by convention black is classified as a process color. However, the motive for including black as a separate ink is the same motive as for other spot colors. Scientific graphics almost never employs spot colors. However, they are fairly common in high-end publishing. The program for a University of Michigan football game might use Wolverine blue as a spot color for the cover, while printing the interior in only the usual CMYK inks.
12.11
PANTONE Colors and All That
Different ink manufacturers use slightly different ratios of pigments and slightly different solvent and binder mixtures. This creates small but sometimes noticeable discrepancies when an image that was proofed on an office computer printer is printed on a huge offset press for a mass-market magazine. The computer printer and web press use different inks; why should the colors look the same? To reduce this difficulty, the publishing and graphics industry have introduced a number of color-matching schemes. A professional designer, for example, can buy a PANTONE swatch book that shows the exact printed appears of PANTONE #32, for example. By specifying PANTONE # 32 in Photoshop software, and then informing the publisher that PANTONE inks are to be used, the designer can ensure that what she has chosen is the exact shade that will appear in the final printed product.
12.12
Summary
It is important that scientists and engineers understand the RGB and CMYK models because these reflect the basic properties of computer monitors and printers, respectively. It is also important to understand the 1-bit-per-pixel bitmap/line art and grayscale modes since these uncolored formats are widely used in scientific graphics, too. Scientific graphics rarely use spot colors, duotones, or commercial color-matching schemes like PANTONE, PANTONE Coated, TOTYO or TRUMATCH. These can largely be ignored, at least for the present.
314
CHAPTER 12. COLOR
Chapter 13
Image-Processing Using Photoshop and Other Tools [Of the lost detail in the darkest and lightest areas of a photograph due to the limited dynamic range of photographic film]: “strong shadows swallow up all timid lights within them, as her blazing lights obliterate all intrustive halftones across; and thus strong contrasts are produced, which, so far from being true to Nature, it seems one of Nature’s most beautiful provisions to prevent.” — Lady Elizabeth Eastlake in her essay “Photography”, London Quarterly Review, pgs. 442–468 (1857); reprinted in Classic Essays on Photography, ed. by Alan Trachtenberg (ed.), Leete’s Books, New Haven (1980).
13.1
Introduction: Scientific Applications of Photoshop and Other Image-Processing Tools
1. Text, arrow, and other annotations of photographs. 2. Deleting unwanted background elements from photographs or scans. 3. Removing “stray light” damage from scans of books, journals or xerox copies. 4. Decolorizing a photo so as to create a black-and-white image that is cheap to publish. 5. Contrast enhancement. 6. Inverting images 7. Reducing the bits/pixel to make Web-publishable graphs.
13.2
Annotated Photo
Fig. 13.1 is a picture of Mars, taken on December 11, 1999 from the Mars Global Surveyor in orbit around the planet. For more than a year, the science team had noticed lots and lots of dark streaks on the planet’s surface. It is known that dust devils, which are miniature tornados made visible by entrained dust, are very common on Mars. 315
316
CHAPTER 13. IMAGE-PROCESSING USING PHOTOSHOP AND OTHER TOOLS
The desert-like conditions create convective instability; with even a modest amount of horizontal shear in the wind, the convective plumes can spin up into concentrated whirlwinds. But were dust devils really responsible for the streaks? The figure answered their questions. The bright patch is a dust devil, photographed from almost directly above. The shadow shows its true columnar shape and the dark curve to the right of the dust devil is exactly the kind of streak that had been seen so often in earlier photographs. However, without arrows and captions, the photograph is gibberish. The Mars Camera Science Team knew that, seen directly above from orbit, a whirling column of dust would look like a bright streak, but this is hardly obvious to the casual observer. Similar, the shadow is hard to tell from the streak. Only because this photograph was annotated by the Science Team using both arrows and text does the photograph become comprehensible. One can then immediately identify the key features and concentrate on the crucial question: Is the Science Team’s interpretation reasonable?
Figure 13.1: Annotated photograph of the Promethei Terra region of Mars, taken from Mars Global Surveyor. The dust devil is less than 100 meters (less than 100 yards) wide and the picture covers an area approximately (about 1 by 1 mile). The text annotations are by the Mars Science Team. The image was opened in Photoshop and cropped to a width of 1.3 km and height of 1 km from its original 1.5 by 1.7 kilometers size; the scale was moved to fit within the cropped image. Mars Orbit Camera (MOC) Team: M. C. Malin, K. S. Edgett, M. H. Carr, G. E. Danielson, M. E. Davies, W. K. Hartmann, A. P. Ingersoll, P. B. James, H. Masursky, A. S. McEwen, L. A. Soderblom, P. Thomas, J. Veverka, M. A. Caplinger, M. A. Ravine, T. A. Soulanille, and J. L. Warren, NASA’s Planetary Photojournal (http://photojournal.jpl.nasa.gov/), MOC2-220-C.
13.3
Before and After Scientific Photos
Fig. 13.2 illustrates a cutaway of the earth’s interior temperature which was made with a rather garish black background. It is easy to cut away the black in Photoshop. The “elliptical selection marquee” can be constrained to be a circle by holding down the shift key; it can be constrained to draw from the center of the globe by starting the drag at that point while holding down the Option key. The selection can then be inverted to select everything outside the globe by going to the Select menu and choosing Inverse.
13.3. BEFORE AND AFTER SCIENTIFIC PHOTOS
317
Thus, the background outside the circle can be deleted in about thirty seconds, but the maneuver is so easy only because Photoshop has powerful selection tools (circle, draw-from-center, inverse).
13.3.1
Removing Unwanted or Irrelevant Graphical Elements
Figure 13.2: Cross-section from the outer mantle to the inner core. Blue areas are cold, dense, and transmit seismic waves at relatively high speeds. Red regions are hot and light. Plot generated by Adam Dziewonski and John Woodhouse.
318
CHAPTER 13. IMAGE-PROCESSING USING PHOTOSHOP AND OTHER TOOLS
Figure 13.3: Same as previous figure but with the black background exorcised in Photoshop.
13.3. BEFORE AND AFTER SCIENTIFIC PHOTOS
319
Figure 13.4: A photograph taken through the Isaac Newton Telescope in the Canary Islands, showing a 1.5 million kilometer string of nuclei of Comet Shoemaker-Levy, 15 May ’94, two months before its collision with Jupiter. (M. Irwin, A. Fitzsimmons and I. P. Williams). Fig. 13.4 shows a telescope photo of Comet Shoemaker-Levy. Like most astronomical photographs, the raw image includes a vast amount of extraneous detail including many background stars. The simplified image was produced by • Using the polygonal select to delete two large wedges of extraneous material. • Selecting and then rotating the remaining image. • Cropping the image using the crop tool, which is similar to the rectangular selec-
tion marquee (and can be obtained from it by dragging on the selection marquee item in the tool menu). • Rubber stamping to eliminate some remaining disks that are clearly background
stars. • The contrast was moderately enhanced using a Contrast/Brightness Adjustment
Layer. Rubber-stamping has to be applied carefully; one should only eliminate elements that are clearly extraneous.
320
CHAPTER 13. IMAGE-PROCESSING USING PHOTOSHOP AND OTHER TOOLS
Figure 13.5: Same as previous figure except that extraneous parts of the image have been cut away, a few background stars have been removed by rubber-stamping, and the contrast was slightly enhanced.
Figure 13.6: Same as previous figure except that black-and-white were inverted. The original image had a histogram that included only the upper half of tonal values. This was changed using an Adjustment Layer/Levels, and then the image made into a negative image through Adjustment Layer/Inverse.
Figure 13.7: Same as the previous negative image, but with Adjustment Layer/Threshold, which stores 1 bit per pixel. File size was reduced from 284 kilobytes to 95 kilobytes (EPS files). However, the tubular tail that extends from the leading nucleus back through the trailing fragments has been eliminated by thresholding. This image is good if one is focusing on nuclei, but disastrous if one wants to investigate the tail!
13.3. BEFORE AND AFTER SCIENTIFIC PHOTOS
13.3.2
321
Removing “Stray Light” Damage
Fig. 13.8 shows the result of xeroxing a page of graphs from an ancient journal and then scanning. It is difficult to get good quality xeroxes of pages from a journal because it is impossible to close the cover of the xerox machine. A useful procedure in reducing the amount of stray light is to lay sheets of blank paper or other journal volumes on top of the glass next to the “target”. When the glass is completely covered, the amount of stray light reaching the xerox detector is reduced. If the xerox machine is near a wall, it may be impossible to completely block the wall side. The result is a xerox (and ensuing scan) which are contaminated by large blotches that are the image of stray light. Photoshop is a good vehicle for removing the “stray light” damage because the damage can be simply erased. In cleaning up this figure, the “polygon-lasso” tool is quite helpful because one can click straight lines to bound the rather irregularly shaped blotches. The “magic wind” is not helpful because the entire image is black, so magic wand selects both the graphs and the noise. The ordinary “lasso” can be used, too, but it is slower because one must manually draw lines nearly parallel to the top and bottom of the page. The eraser is very useful for eliminating blotches that overlap lines of the graph, and thus have to be removed very carefully. Because the eraser has a “brushes” palette available, one can choose various eraser sizes as one works.
13.3.3
Contrast Enhancement
Fig. 13.10 shows a photograph from a fluid mechanics laboratory experiment. The contrast between the yellow-tinged vortices and the ambient reddish fluid is very poor. So, we enhanced this figure in Photoshop in the following ways: • The black wedges in the corner and the outer wall of the tank were eliminated
by using the elliptical selection marquee with Shift held down (to constrain it to a circle) and also Option held down (to draw from the center of the tank); the spacebar was held down to allow a slight adjustment of the center of the circle. Finally Select > Inverse was used to select the exterior of a circle centered on the tank, and this exterior was deleted. • The contrast was enhanced by creating a new Adjustment Layer in the Layer menu,
choosing the type of the new layer to be Brightness/Contrast and then adjusting these until the image seemed much clearer. (Adjustment Layer changes are previewed, but not actually applied to the image until “OK” is clicked.) • The red color was replaced by first selecting the entire image, then Image > Adjust
> Replace Color. This brings up a dialog box with a preview area and three eyedroppers. By clicking on the left eyedropper, one can pick a color to be replaced. The middle eyedropper (labeled with a plus sign) can be dragged to add more and more regions of color; the selected areas will be displyaed in white in the preview box. One can then choose a new color to replace the old by dragging sliders that are also in the Color Replace dialog box. The red background of zero vorticity was replaced by blue. • The rubber stamp was used to replace the black photoguide disks by ambient
colors. The black disks in the blue regions, for example, were replaced by Optionclick on a blue region and then clicking on top of a black disk. A black disk that intruded on a region of yellow streaked with a little orange was replaced by three bands of yellow, orange and yellow by using the rubber stamp with a smaller
322
CHAPTER 13. IMAGE-PROCESSING USING PHOTOSHOP AND OTHER TOOLS
Figure 13.8: Scan of a collection of figures from an 1882 article by Henry M. Jeffrey, F. R. S. The scan was made from a xerox. Unfortunately, the xerox was contaminated by a lot of stray light because the fragile pages of the more-than-a-century old journal could not be easily manipulated without damaging them. The “stray light” damage was fixed in Photoshop as shown in the next figure. This figure is some interest independent of the stray light. First, Jeffrey’s article contained some 84 numbered figures; even in the 19th century, it was possible to use graphics extensively. Second, the figure shows how many graphs can be combined into a single page without loss of clarity, especially for line art. Third, the absence of captions is bad because the reader has to jump constantly between the text and the page with graphs. Fourth, in order to facilitate comparisons between different graphs printed on the same page and perhaps also to reduce the cost of the special printing plates for the graphs, the figures were printed on fold-out pages. These opened up to create pages much larger than the digest-size pages of the rest of the journal. Because all the graphs were crammed onto foldouts, individual figure captions had to be sacrificed.
13.3. BEFORE AND AFTER SCIENTIFIC PHOTOS
323
Figure 13.9: Same as previous figure except that the xerox imperfections have been erased using Photoshop.
324
CHAPTER 13. IMAGE-PROCESSING USING PHOTOSHOP AND OTHER TOOLS
Figure 13.10: Scanned from a photograph of a laboratory fluid tank experiment by Harry Swinney of the University of Texas and collaborators. The yellow patches are vortices; the complete sequence of photos from which this has been taken illustrates the formation of vortices in a shear zone in a tank which is rotating on a turntable, and the subsequent merger of these vortices. The black disks are aids to the measurement of flow properties as the tank rotates and a camera and/or video camera photographs the tank from above. brush size. Finally, the “stamped” areas were blended more smoothly into their background by applying the “smudge” tool.
13.3. BEFORE AND AFTER SCIENTIFIC PHOTOS
Figure 13.11: Same as previous figure, but “improved” in Photoshop
325
326
CHAPTER 13. IMAGE-PROCESSING USING PHOTOSHOP AND OTHER TOOLS
13.3.4 Decolorization Fig. 13.12 shows a photograph of a laboratory experiment on the collision of two pairs of contra-rotating vortices. If one wanted to publish this photograph in black-and-white, such as would be useful in a theory paper that purported to explain these experiments, how could one do it? Fig. 13.13 shows the result of converting the color image to a grayscale image. The grayscale image is not entirely successful. The contrast between shades of gray makes it difficult to see the green/orange differences of the original photograph — unfortunate since the colors indicated the origin of the vortices, which have exchanged partners by the time of this post-collision photograph. (In other words, the two green vortices have split up, each leaving the collision with a vortex of opposite sense of rotation from the other vortex pair, which was dyed orange.)
Figure 13.12: Colliding vortex pairs (modons) in a laboratory experiment by GertJan van Heijst and Jan-Bert Flor, published as Plate 18 by Ball(1999). The image was scanned from a photograph of the rotating tank; green and orange fluorescent dyes were used to mark each of the two initial vortex pairs, which have collided and exchanged partners at the time shown.
13.3. BEFORE AND AFTER SCIENTIFIC PHOTOS
327
Figure 13.13: Same as previous figure, but converted to a grayscale image in Photoshop. The Trace Contour option was used to provide a black border around the main features of the vortex.
328
CHAPTER 13. IMAGE-PROCESSING USING PHOTOSHOP AND OTHER TOOLS
13.4
The Manipulated Photograph
A photo has always been regarded as strong evidence because “photos do not lie”. No professional photographer has ever believed this. In reality, photographs have manipulated visual reality from the very earliest experiments of Daguerre and Fox Talbot in the 1830’s. One difficulty is that to quote Michell(1992): “the range of intensities in a visual field will often be very much greater than the range of tones than be captured and presented by a photograph. Pigments, inks and dyes can yield a ratio of tonal values, from darkest to lightest, of about forty to one, bu the ratio from deep shadow to sparkling highlights in a sunlit field can be thousands to one. Thus the photographer must compress the intensity range of the scene with inevitable distortions and loss of detail”. The perceived intensity of sound and light and other stimuli may not appear to have such a huge reason. However, human senses operate on a logarithmic scale, a fact which is known in physiology as Weber’s Law. Photographers have developed a wide variety of strategies to cope with image problems. Deliberate overexposure or underexposure of an image is obvious. However, selective adjustments to parts of an image, known as “dodging” and “burning”, were developed in the nineteenth century. This eventually became elaborated into the Zone System, popularized by Ansel Adams, Minor White and other well-known photographers. “Dodge” and “burn” are two of the tools in Photoshop. Colored filters are popular with photographers, too. Yellow filters are used to darken skies and bring out the detail of clouds. Red filters lighten foliage while also darkening skies even more than yellow filters. To dramatize building forms, architectural photographers have long been fond of covering their lenses with a red filter. It is sometimes helpful to adjust the tone values of an entire image by either brightening or darkening. The “Claude glass” was a popular eighteenth century filter for darkening the view, which seems to make landscapes look more harmonious. Photoshop allows one to dodge and burn, color filter, apply a Claude glass, and a wide range of other color and tone adjustments far more easily, and with far finer control, than similar adjustments with film and developer. Many of these adjustments are merely cosmetic, and therefore much more important to the photojournalist than to the photoengineer.
13.5
Common Boo-Boos
• When a tool fails to work, it is probably because one is in a different layer than
one thinks. • Another reason for tool failure is that the previous selection is still operating. One
must make frequent of Deselect, which is an item under the Select menu, or the keyboard shortcut Apple-D. • When the Save menu does not allow an option such as Photoshop EPS, it is probably
because the file needs to be flattened, that is, have all the layers combined into one, in order to be saved in EPS, or any other format that does not support layers.
13.6. ALPHA CHANNEL
13.6
329
Alpha Channel
Full-color RGB image files use 24 bits/pixel: 8 bits to specify 256 different intensity levels for each of the three additive colors. However, graphic designers found that this was not enough. What if one wanted to specify transparency properties, or other non-color properties at each pixel? Some file formats, such as TIFF, Pict, and PNG, therefore support an “alpha channel”. This optional feature of a file is a place to store transparency information, etc. The concept of an “alpha channel” is a little bit fuzzy because there are potentially a lot of different additional properties that might be appended to a graphic file. Adobe Photoshop allows a lot of alpha channels; some file formats support only one such channel. In any event, an alpha channel is a place to store properties of the pixels other than intensity-of-each-color.
13.7 Delayed Execution, History and All That It is easy to reverse the drawing of a line in vector graphics simply by deleting the line. Reversion is more difficult in image processing because allowed operations include blending old and new colors together, diffusing features, and so. Blending and diffusion are much harder to cleanly reverse than the addition of a vector-graphics feature. For this reason, “delayed execution” is a major theme in image-processing. Good software allows one to do all sorts of operations without changing the underlying image so that one can revert to an earlier state of the image. Adobe Photoshop offers a rather bewildering array of tools for delay. Some important ones include the following: 1. layer masks 2. adjustment layers 3. history palette 4. history brush
13.7.1
Layer Masks
Artists often cut shapes out of paper or a material called “frisket” and fasten them to an illustration to block parts of the picture from the spray of an airbrush. Imageprocessing programs make it even easier to apply masks to confine various operations of painting, lightening, etc., to selected portions of the figure only. Frequently, one only wants to apply adjustments to a portion of the image. For example, a flash photo may contain a picture of a person that is very bright (because the light from the flash could illuminate the subject) against a background that is extremely dark (because it was too far from the flash to be illuminated). One can create a layer mask by using all the standard painting tools to layer the label with white, black, or gray to indicate which pixels should allow an effect, prohibit an effect, or allow the pixel to average the effect with the original state of the pixel. Once the mask has been created, one can then apply effects with wild abandon only to the chosen area. The alternative is to draw a selection border on the image and then apply the effect within the border. The trouble is that if the change needs to be altered later — coloring the sky a dark blue may need to be modified by adding in some clouds, for example
330
CHAPTER 13. IMAGE-PROCESSING USING PHOTOSHOP AND OTHER TOOLS
— then one has to painstakingly draw the selection border all over again. However, a layer mask is a permanent feature of the illustration, saved as part of the file whenever the image is saved in Photoshop format. One can apply, or not apply, a given layer mask very easily at any stage. The layer mask indefinitely delays the destruction of a selection border.
13.7.2 Adjustment Layers Adjustments to brightness and constrast, saturation and hue, etc., can be made directly to the image, but are not easily unmade. One can alternatively perform these same operations in a “layer mask”. The advantage is that the change can then be unmade simply by deleting the layer. Furthermore, one can return to the layer at a later time to tweak the adjustments. The adjustments are never closed, but are like a layer of paint that is allowed to remain indefinitely wet.
13.7.3 History Palette This feature shows the names and snapshots of the last 20 graphical operations. (Changes to global preferences are not shown, but almost everything else is; the number of operations kept as “history” can be changed by the user, if the computer has enough memory to support a large number of “history” snapshots.) By dragging items in the history palette to the little trash icon underneath the history palette, one can delete graphic operations that were not a success. In normal operation, deletion of a state also deletes all later states. However, at the expense of a little more memory and more thinking by the software, one can check an option called “Allow Nonlinear History”. When an operation in the middle of the “history” is deleted, only that operation goes away.
13.7.4 Snapshots One may explicitly save an intermediate image state as a “snapshot” so that it will appear permanently in the history palette with its own name. This can provide a convenient visual anchor when doing (or undoing!) a complicated set of operations.
13.7.5 History Brush Instead of brushing on strokes of a color, the history brush allows one to create by brushing sections where the image reverts to a previous state or snapshot. Thus, if one brightens the dark background of an image, and accidentally got some foreground pixels, one could use the history brush to revert those foreground pixels to their original state. Alternatively, one can also apply the eraser with “Erase to history” option turned on. This reverts the chosen parts of the image to their appearance in the last SAVED version of the file.
13.8
Paths
Vector-graphics instructions, such as the walls of a polygon, are sometimes called “paths” in software manual. Photoshop allows one to draw “paths” using the pen tool
13.9. TRANSFORMATIONS
331
and its variants. The pen operates almost exactly as in Illustrator; it creates a curve controlled by Bezier polynomials. By using tools under the pen tool, one can and delete anchor points, move segments bounded by two anchor points, move the direction arrows that radiate from anchor points and so on. Paths can be used in two very different ways. First, just as in a drawing programs, paths can be given a “stroke” (the color/linewidth, etc. of the curve that defines the path) plus a “fill”, which is a color, color gradient or texture that fills the interior of the path. This use is simply a way to add vector-graphics items to a bitmap image. The second use is that paths can be converted to selection borders. (Click the little triangle on the right of the “paths” palette to bring up a menu of options.) This allows one to draw very intricate selection borders, just the way you want them, when the square and elliptical selection marquees and the pixel-edge selection tools are inadequate.
13.9
Transformations
Just as in vector graphics, one can select an area of an image and apply rotation, shear, dilation, and other transformations to the selected block of pixels. Indeed, Photoshop has some three-dimensional transformations which can be very useful in modifying photographs of real, three-dimensional objects. Because of the similarity of these transformations to those in Illustrator and other drawing programs, these transformations will not be discussed in detail.
13.10
Organizing Images: Contact Sheets
A “contact sheet” is a collection of miniature images, all on a single page, which illustrates all the images in a single roll of film. Such contact sheets are very helpful in organizing graphics files because the thumbnail sketches allow one to easily identify a desired picture when the filenames alone are inadequate. Photoshop has a command (under the Automate command under the leftmost main menu) which will automatically make a contact sheet showing all pictures in a given folder or subfolder. An example is shown in Fig. 13.14
332
CHAPTER 13. IMAGE-PROCESSING USING PHOTOSHOP AND OTHER TOOLS
Figure 13.14: Contact sheet generated by Photoshop.
Chapter 14
Animation 14.1
Introduction
In this chapter, “animation” will be used as a shorthand for “a sequence of computergenerated images, rapidly displayed so as to create the illusion of continuous motion, as in a movie”. Unfortunately, the technology to both generate the image-sequence in the computer, and to output it to screen, videotape, CD-ROM, DVD or film, and the software tools and file formats to do so, are rapidly evolving. Nevertheless, because an animation is often the only way to display time-dependent reality through a time-dependent visualization, animation is becoming increasingly important
14.2
Animation versus Stills
A single frame from a film, or a single image used as a substitute or supplement to an animation, is called a “still”. The first theme about animation is that it should be used sparingly: animation is expensive both in computer resources (rendering time, hard disk storage) and in reader time (because the viewer must concentrate intensely for the whole duration of the animation, and process a large number of images). The best advice is: dynamic phenomena are best presented dynamically (that is, as animations) whereas static phenomena are best visualized as stills. However, there are some subtleties. I once had a Ph. D. student who proudly (but inappropriately) created an animation of the developing wave in a linearized hydrodynamic stability calculation. The animation was rather useless because the approximations inherent in the “linearization” meant that the wave never changed its shape as it evolved, but only grew in amplitude at a steady, exponential rate. The contour lines flickered during the animation because the contouring subroutine had to adjust the contour levels as the wave amplified, but the shapes depicted by the isolines — that is, the location of the highs, lows, zero-lines, etc. — never changed. A single still conveyed exactly the same information as the entire animation. So, the notion of “static” (and animation-inappropriate) has to be generalized to include not only behavior which is truly independent of time, but also time-dependence that is trivial and shape-invariant. Spatially-uniform growth is one example; steady, shape-invariant wave propagation is another. 333
334
CHAPTER 14. ANIMATION
The notion of “dynamic” needs to be narrowed, too, because what animation does best is to display motion. When the shape changes, it sometimes does so only to shift from one quasi-steady state to another (“snap-through dynamics”.) In such a case, it may be far more useful to display a set of stills of the quasi-steady states, preferably combined into a single figure, rather than an animation of the entire time-dependent evolution. Animation is not justified merely because the flow evolves with time; the evolution must be so dramatic that it is difficult to follow all the shape changes through a collection of four to six pictures in a single figure. A multi-panel graph has the advantage that the reader can linger over each frame as long as desired, drinking in the details. In contrast, an animation shifts continuously so that is possible to linger over nothing. Most of us have had the feeling, when watching a theatrical movie, that an interesting scene flashed by too fast — to fast to comprehend the intricate plot details, too fast to enjoy the beauty of the backdrop (or the leading actor/actress). A partial remedy for this is to hybridize the panel-of-stills with the animation. Computer animation formats such as Quicktime display a slider underneath the “movie screen” so that one can display the animation one frame at a time, or move forwards or backwards one frame at a time at a user-controlled rate. Alternatively, one can click a button to play the motion at full speed, either forward or backward. While freeze-frame, slow motion, and reverse are options with ordinary celluoid movies, these options are much easier on a computer, where a touch of a key suffices, than with celluloid movies, where a mechanical projector has to physically slow, stop, or reverse gears. The late Tetsuya “Ted” Fujita, the world’s leading authority on tornadoes, was a master of visual presentation. In 1974, an Indiana TV cameraman filmed the first movie of a multi-vortex tornado. The short film clip (about ten seconds) was made widely available to the scientific community, and several authors showed it at the 1975 SESAME conference in Boulder. One group began with an apology; to identify features in the fast-moving whirl of subvortices, they had rerun the film so often that their copy had become heavily scratched and degraded. It was hard to see much of anything as the four subsidiary vortices danced around their common center while simultaneously their center rapidly translated parallel to the ground. In contrast, Fujita had duplicated the clip and reshot it. His two-minute film showed the ten-second clip twice at normal speed, then twice in slow-motion, then once in slow reverse motion, then paused to freeze-frame several key moments. (The freezeframe images were reproduced by filming the same frame of the original fifty times to make two seconds of the Fujita film.) There were no pauses to slow down or stop the projector, which ran at full speed throughout Fujita’s presentation. Fujita’s clever reprocessing had overcome most of the limitations of movie film. Nevertheless, the viewer has much more control over a Quicktime animation, and Fujita, who retired in the mid-90s when computer video editing had just arrived, doubtless wished it had been available when he was analyzing and editing the multi-vortex tornado. When movie film or video is captured into a computer, editing and viewing is enormously simplified; a computer is the ultimate freeze-frame/slowmo/reverse movie projector. Nevertheless, even Fujita’s cleverness and/or the replacement of projector gears by silicon and on-screen controls cannot entirely compensate for limits of animation. A multi-panel graph can be printed; an animation can’t. A multi-panel graph allows graphto-graph movement controlled only by the eyes; an animation can be shifted only with a mouse. A multi-panel graphs allows easy comparison of different states; an animation shows one frame at a time. So the first great issue in animation is: Do I need a movie? Would stills be better?
14.3. FILMS VERSUS VIDEO VERSUS QUICKTIME
335
Quicktime movies or other rapidly-played sequences of images are a powerful tool for depicting many phenomenon. However, there are plenty of situations where animation is not appropriate, but is “chartjunk” and/or a “graphical duck” instead. To summarize, situations that should NOT be animated include, but are not limited, to the following: 1. Steady-state phenomenon 2. Steadily-growing solution without shape change 3. Steadily-translating wave 4. Snap-through dynamics: rapid changes from one quasi-steady-state to another with uninteresting brief periods of transience. Actually, it may be helpful to animate a steadily-propagating wave for K-12 education, but college students can mentally translate a shape without needing to be shown it.
14.3 14.3.1
Films versus Video versus Quicktime Film
Celluloid film is now rare in scientific visualization. First, cheap movie cameras have been largely replaced by videocameras; movie equipment is relatively rare and therefore expensive, aimed more at Hollywood than daddy-filming-his-little-girl in a suburban backyard. Second, export from the computer requires special equipment and is relatively expensive; Industrial Light and Magic has the necessary equipment, but it is increasingly rare for a non-professional to do so. Third, movie projectors are becoming rarer, older and less reliable. The great advantage that film has over other media is long-shelf life. Paper has been a very successful archival medium: the linen-rich, acid-free paper and carbonbased inks of Gutenberg have degraded but little in the half-millenium since he printed his Bible in the 1450s. Film is not so long-lived — indeed, the celluloid stock of early twentieth century movies is chemically unstable, and some early silent films have quite literally exploded in the vault — but is likely to be much more durable than other computer-based formats.
Animation Inappropriate Steady Translation
Steady Growth
Figure 14.1: Schematic of time-dependence that too is simple for animation: If the shape doesn’t change, it doesn’t need to be animated.
336
CHAPTER 14. ANIMATION
14.3.2 Archiving Archival survival is based on three factors: 1. Durability of the medium 2. Availability of readers/projectors 3. Interest and ability to preserve through duplication. Acid-free paper can last many centuries; ordinary wood-pulp paper will last a few decades; modern black-and-white film stock can probably last fifty to one hundred years; analog (VHS) videotapes may last five to twenty years; CD-ROMS and DVDs will last a couple of decades or more, but no one is entirely sure. Paper is the champion in the “projector” category; the only “reader” needed is the viewer’s eyes, the only complication would be a switch to a simplified spelling system. Of course, paper is useless for stills. In contrast, analog (VHS/SVHS/Betamax/VHS-C) video is likely to disappear in the next decade, replaced by digital video. Thus, an animation-on-video in 2002 will be very hard to view in 2012 even though the magnetic oxide coating on the tape is still okay. Similarly, CD-ROM drives will likely be gone in ten years also; however, the present generation of DVD readers can also read CDROMS, so this format is likely to more long-lived than analog video. Computer formats are hard to predict; theoretically, there is a lot of backward compatibility and it seems likely that it will be possible with effort to read animation files of twenty years earlier. However, most workstations will have only the latest standards, and these may or may play current-day Quicktime and AVI formats. Animations in old formats can be preserved by copying to new formats, such as analog video to DVD. However, this takes time, money, and enthusiasm. Undoubtably many films and computer videos of today will never be converted to DVD (or whatever), and will simply disappear like the hoop skirt and Nehru jacket.
14.3.3 Video The charm of video is that the tapes are inexpensive, and can be played on hobbylevel equipment. All conferences and academic departments and many private homes have video players. A computer is not necessary for replay. Further, video always includes audio whereas including or even playing an audio track on film usually requires professional-grade equipment. Creating video from computer animations is fairly straightforward. Some solutions require buying a card which does the conversion in hardware and contains a video connector that projects out through the back of the computer. The new generation of Macintoshes (even though the bottom-of-the-apple iMac Powerbook) all have builtin hardware and software to input and output video; it is not possible to buy a new Macintosh that doesn’t have video input/output capabilities. One downside of video is that are several incompatible formats including VHS, SVHS, 3/4” tapes, Betamax, Digital 8-mm, etc. VHS is an analog format which is very widely used; there are tens of millions of VHS players in the world. The bad news is that VHS is a low resolution format. In the early days of PCs when color computer monitors were hideously expensive, it was common to use a TV as a monitor for color graphics. Even in the early 80s, though, monochrome computer monitors with much higher numbers of pixels were available. My first PC was a dual monitor setup. Letters were visible on the TV only when displayed in twice the size of what was clear and legible on the 720 x 540 monochrome display.
14.4. MOVIE JARGON
337
Thus, animations that will be transferred to VHS must be designed to use big letters. The other features of the graph must similarly be oversize. Flow vector arrows that may look fine on the computer screen may well be washed-out, visible only as directionless, blurry black sticks, on VHS. Analog video records a record of the intensity of the camera signal without digitization. Although it works, it is hard to tune; an engineers’ joke is that the acronym NTSC for standard video means “Never Twice the Same Color”. Analog video is not a good format for computers because the workstation must perform an analog-to-digital conversion and back before doing anything useful with the signal. Because an analog signal degrades a little each time is copied, a heavily edited VHS tape looks awful. To compensate, professionals use 3/4” tape for editing. The format is the same as standard VHS except that the signal is recorded at lower density on the wider tape, which greatly reduces editing degradation. In contrast, digital video never degrades because of copying. For these reasons, analog TV (and video) are being phased out. It may be another decade before the number of digital home TVs exceeds the number of analog boxes, despite the government’s present timetable to cease analog broadcasts at an earlier data. Digital cameras are growing in popularity much faster than digital TVs because 1. They’re much less expensive than digital TVs (though more costly than analog cameras). 2. Digital video is much easier to edit. 3. Digital camcorders have always have a digital-to-analog converter so that they can be played on an analog TV through a cable. Apple’s integrated software/hardware video capability is therefore focused entirely on digital video. The iMovie software not only edits, but also sends stop/start commands to most digital camcorders. (In contrast, analog camcorders are only rarely configured so that they can be controlled by software.) This is yet another reason why digital camcorders are rapidly pushing analog aside, especially as a camcorder/computer combination. It is unfortunate that video in an unstable analog-to-digital transition. For conference presentation, a VHS tape is the best because analog players are more widely available than digital (though this is changing). However, the VHS tape will be obsolete in a few years. So, unless the tape has only one-time value, it is desirable to make a digital video, too, where possible. This is easy if the editing is done on a digital camcorder; the VHS copy or “dub” can be made by rewinding the tape, connecting the digital camcorder to the input of a VHS player or “deck”, and hitting the play button on the digital machine and “record” on the analog tape.
14.4
Movie Jargon
ANALOG (VIDEO): Videotapes (and TV) in which the record or displayed signal is simply the strength of the signal detected by the camera. This is opposed to DIGITAL VIDEO, in which the camera signal is converted to numbers. CLIP: Movie jargon for a short section of an animation, typically containing one scene or a portion of a scene; a clip is a portion of the film bounded by two “cuts” where the viewpoint shifts to a different camera, viewing angle, etc.
338
CHAPTER 14. ANIMATION
CODEC: A protocol for compressing and then decompressing video files. Codecs are extremely important because all but the shortest video files require so much storage in uncompressed form as to be unmanageable; in addition, uncompressed files require too much processing to permit real-time display on older workstations. Video editors support several protocols each, which may be implemented either in software or on special hardware video cards inserted into the computer. DIGITAL (VIDEO): TV/video in which the input from the camera is converted immediately to numbers so that numbers, rather than undigitized pixel intensities, are recorded onto tape. DUB: Movie jargon for “copy”. When an audio track is added in the studio to a video track which has been photographed on location, the audio track is said to be “dubbed” into the movie. When a computer animation is copied onto a VHS videotape, the result is a “VHS dub”. KEYFRAME: In animation, a frame that is drawn or compressed very accurately; frames between keyframes are drawn by interpolating or “tweening” between the keyframes. (Used both in animation/drawing and also in video compression/decompression.) ROTOSCOPING: Drawing directly on invididual frames of film. Adobe Photoshop can import video in filmstrip format as a single file from Adobe Premiere, draw on individual frames, and then export the filmstrip back to Premiere for video rendering or export. SPRITE: Graphic objects which are stored once in a movie file, and then duplicated or moved as needed. Early personal computer sprites were bitmaps were moved, without making big demands on the CPU, by blitting the sprite to the frame buffer. Modern sprites may either bitmap, vector, or 3D. STILL: A single image, often taken from an animation, as opposed to the ANIMATION itself, which is composed of many frames. STORYBOARD: A collection of sketches which narrate the plot, settings and characters of a movie. TRACK: Different components of a movie or animation, playing simultaneously, are “tracks”. Most movies have both a video track and an audio track, but with the use of transparency masks, it is possible to layer a larger number of tracks in a single animation. Different species of images which are played at different times may also be identified as distinct tracks, such as a video track which is followed a still-image track that freezes a single picture on the screen for a couple of seconds. TWEENING: In old-fashioned celluloid animation, a small subset of the cells were sketched by the animators; most of the drawings were produced by less-skilled artists called “tweeners”, who interpolated between the KEYFRAMES created by the animators. Computer animation programs, notably Flash, use similar strategies to reduce the workload on animators.
14.5
Computer Animation Formats
The major animation format on the Macintosh is Quicktime, which was developed by Apple itself. Apple freely distributes its Quicktime Player on both Macintosh and all
14.5. COMPUTER ANIMATION FORMATS
339
makes of Windows platforms. Its simple video editor, Quicktime Player Pro, may be purchased for $30 as a download for either Macintosh or Windows. The format is rich enough to support various compression options, still images, audio; Quicktime Player can directly open Animated GIF, AVI, DV, FLC/FLI, MPEG-1 (only on Mac), MPEG-2 (only on Mac) video files, AIFF, Audio CD, MIDI, KAR (Karaoke) and Sound Designer audio files, 3DMF three-dimensional graphics files, and BMP, GIF, JPEG/JFIF, MacPaint, QuickDraw GX, Photoshop, PNG, SGI, Targa, and TIFF image files, among others. The format allows a large number of different video and audio tracks including sprites, three-dimensional object tracks, hinting tracks to assist Internet streaming and so on. The AVI format was once Microsoft’s answer to Quicktime, but AVI allows only video and audio tracks. It is so limited compared to Quicktime that Microsoft actually adopted its rival’s Quicktime for some of Microsoft’s own products such as the Encarta CD-ROM encyclopedia. Microsoft attempted to replace AVI with something called ActiveMovie, but this was never fully released, and was instead replaced by Direct Show. In practice, the FLI/FLC format has been the standard Windows animation protocol. The DV format is the standard cross-platform protocol for digital video. As digital camcorders rapidly chase analog camcorders from the field, DV is rapidly growing in importance. It seems unlikely to entirely replace Quicktime because DV is strictly a video/audio TV format, and was not designed to accomodate Internet streaming, sprites or other kinds of technology that are important in computer graphics. It will almost certainly handle 99% of the camcorder/computer data transfers by 2005. Apple has embraced digital video so enthusiastically that it is no longer possible to buy an Apple that is not equipped to import, export and edit DV. The hardware side is a fast cable/interface technology that Apple developed and calls “Firewire”. Apple put this into the public domain and allowed it to be standardized by a committee of the Institute of Electrical and Electronic Engineers (IEEE). Other computer manufacturers usually refer to Firewire as the IEEE 1394 interface. Even the lowliest iMac Powerbook has one Firewire port; desktop models have two. It is becoming increasingly common for PCs to have Firewire (IEEE 1394) ports. Using a program called iMovie which is supplied free with all new Apples, one can plug a Firewire cable to the corresponding port on a digital camcorder, and import, edit, and export digital video with the software controlling the play, record, and rewind functions of the camcorder. (Almost all digital camcorders are Firewire/Apple compatible, but there are a few exceptions, so one should check the documentation of the camcorder.) Windows PCs are made by a huge variety of vendors, so there is not as much standardization in the Windows world. However, most PC companies sell hardware/software combinations that will do digital video editing right out of the box. If one wants to show an animation at a conference which lacks a DV player, , it is fairly easy to make a “VHS dub” of a digital tape by connecting the video-out of the digital camcorder to the input of a VCR. (Because digital video must almost always be played on a standard, VHS TV, digital camcorders always have a VHS video-out port.) MPEG, which comes in several flavors, is a public domain standard that is very widely used for Internet movies. Free players are available for almost all types of platforms. MPEG movies are usually somewhat grainier than Quicktime animations, but this will probably change as more advanced flavors of MPEG become more common. The longterm future of MPEG is a little confusing because there is no vendor with a strong, vested interest to continue rapid development of this format. Flash is a widely used format for vector animation which is aimed specifically at the Web. It was developed in conjunction with the animation program, Macromedia Flash, but the format and Web player-plugins have been placed in the public domain. Flash is
340
CHAPTER 14. ANIMATION
very good at allowing Web site designers to create simple animations that will jazz up a Web site. However, it has been used very little for scientific and engineering visualization. Flash assumes that the animation will be drawn by the animator from simple shapes combined with “morphing” or “tweening”, which is described more below.
Acronym QuickTime AVI FLI/FLC DV MPEG Flash
14.6
Table 14.1: (Selected) Animation Formats Preferred Platform Remarks Mac (Windows, too) Windows (Mac, too) Once dominant for Windows, now becoming obsolete Windows New official Windows animation format, replacing AVI All New digital video standard All Several flavors: MPEG-1, MPEG-2, etc. Popular, still evolving. Hardware MPEG codec available. All Vector-based animation, primarily for the Web
Video Players with Quicktime as an Example
The Quicktime Player, in common with other video players, has a control panel which imitates a VCR. The main button is for normal playblack; just to its right is a Pause buttom, marked by two vertical bars. These controls are always visible. By clicking on an icon with four dots, one can make a tray of additonal controls appear below. Included are buttons to jump to the beginning and end (right pair), play one frame at a time forward or one frame at a time backwards (middle pair; triangles plus a vertical bar) and fast forward/fast rewind (left pair; each icon is a pair of triangles). If there is an audio track, a little speaker icon is always visible next to a volume dial (extreme left of the player) which can be dragged up or down to change the volume. When the control tray is visible, there are additional treble/balance controls for the sound at the extreme bottom of the player. There are some additional features, not available in a VCR, in Quicktime Player and other computer video software. First, there is always a time slider which can be dragged to jump to any point in the movie: videotape is sequential access (meaning one has to wait while the mechanical process of spinning tape proceeds) but computer animations are always random access, meaning one can jump instantly to any point in the film, independent of the speed of a mechanical tape-winder. Some Quicktime movies have “chapter” or “cue points”. If a Quicktime animation has such, then just to the right of the time slider will appear a pair of up and down arrows. Clicking these allows one to jump to the beginnings of the segments (“chapters”) constructed by the movie’s creator. Quicktime has a “Present as Movie” option which eliminates the control frame, and shows just the movie itself against a black background. This is very helpful when (i) showing the movie at a conference and (ii) copying (“dubbing”) the movie to videotape. “Present as Movie” has a slideshow option in which the movie is displayed, framefree, one image at a time. Clicking on the image, or pushing the forward and reverse arrow keys, allows one to navigate through the slide shown.
14.7. AUDIO
341
14.7 Audio Though silent movies have obsolete in commercial theaters for over 70 years, most scientific animations have no audio. The first reason is that when a video is played at a conference, the speaker usually provides the commentary live. The second reason is that computer animations tend to last only a few seconds. If the time-dependence is so complex that it requires even a couple of minutes to display it, it is unlikely that the viewer will be able to absorb and the entire sequence. Further, a couple of minutes of video is, even a compressed form, a very large fil. For Web distribution, an audio track is theoretically useful. However, 100 MB animations take a prohibitively long time to download, even with a cable modem or other fast connection. Web animations therefore must be rather short. This means that it is difficult to convey useful information while an animation of say, twenty seconds duration, unfolds. In a theatrical film, the audio and video of a scene are closely integrated: the sound of a battleship blowing is accompanied by fire and smoke and ship fragments flying out of view. Narrating computational parameters while a flow field simulation is playing is a distraction, however, because this sort of important background information is divorced from the vortices and fronts that appear. Narration of features, such as “The primary vortex divides into two smaller vortices, which then rotate around one another”, is audio that is integrated closely with the video — but also a bit insulting. The viewer can see the big vortex split into two, etc. It is difficult to devise narration which is simultaneously (i) well-integrated with the pictures and (ii) not merely a description of what the viewer can see for herself. In presentations of scientific animations, it is common for the speaker to make a number of prefatory remarks before starting the film, and then remaining silent while it is playing. Consequently, we shall not discuss audio further. However, all standard animation formats and editors support audio tracks, which can be added separately after the video has been created.
14.8
Functions of Videotape Editors
1. Assemble an image sequence into an animation. 2. Delete sections of boring or redundant video or computer animations. 3. Assemble multiple clips or cases into a single film 4. Mix disparate visual tracks, such as videotape clips and Quicktime or FLI/FLC or MPEG computer-generated clips, into a single movie. 5. Add full page text blocks, such as movie or chapter titles 6. Add text underneath the image to run in parallel with it for edit-chosen durations. 7. Add documentation blocks of text to make the film self-documenting [in the spirit of comment statements that make computer programs self-documenting]. 8. Add audio or music tracks. 9. Add transitions between chapters or cases so as to avoid abrupt jumps from scene to scene.
342
CHAPTER 14. ANIMATION
Table 14.2: Quicktime Track types Track Types Video Sound Music Text 3D tween hint streaming
14.9
Remarks Standard Quicktime visual track, but not the only visual track Standard audio track Musical score, analogous to MIDI very low storage compared to standard sound track Used to caption movie (if enabled) Used for chapters (jumppoints) and searchable index (usually disabled) holds geometric definitions of objects, texture and lighting operates in conjunction with “tween” track, which describes motion describes motion of 3D objects in the 3D track Must be one for each Web-streamable track: tells browser how to break up the hinted track into packets All streamable-tracks are flattened into a single streaming track for viewing while streaming
Tracks
A movie can hold a large number of disparate tracks, at least in a rich format like Quicktime. Each track can be manipulated, turned off, turned off, and deleted independently of the others, and the tracks need not run parallel through the entire animation. A video might have three music tracks, for example: one for the music of the first part, a second for the sound of the middle frames of the animation, and a third piece of music on its own track for the conclusion.
14.10
Text: Captioning and Documenting
A text track can be used to provide information about the video in three ways: 1. Separate, detailed documentation pages. 2. Silent film captions: blocks of large-type text that are displayed for a couple of seconds between clips of animation. 3. Under-the-image captions. In an ideal world, movie formats would support a special type of text track that is invisible when the animation is played at the normal rate, but accessible through a “documentation” button or something. Alas, no format provides this. We shall describe workarounds for this limitation in a later section. Silent films put the dialogue onto frames of text which were displayed for several seconds at a time, long enough for the audience to read them, between clips of action. All computer animation formats support audio, so there is no absolute necessity for silent film text captions. However, when the action clips are rather short, and also when the movie creator has a strong accent, it may be difficult to present all the necessary information by voice while the pictures are being displayed. Silent film captions are a useful option. These text blocks allow one to present necessary background information and documentation without distracting the viewer from the movie frames themselves. Quicktime and some other formats allow one to play a text track and a video track simultaneously. The text will display in a small rectangular box underneath the video frames, thus providing a running caption.
14.11. RESOLUTION AND FONT SIZES
343
In scientific visualization, the best way to caption is using the program that generated the video. Matlab, for example, can create running titles, labels, and text blocks that can be updated (using the num2str and int2str functions) as the animation evolves. Use these features to the max because then both image and text are being controlled by a single program, and one can see at once if there are any problems, such as text obscuring key features of the pictures. However, sometimes key information can only be added later after the animation has been analyzed. Then, adding a text track with this late-discovered information can improve an animation.
14.10.1
Example: Quicktime Procedures
Non-text track method: How to add text to a movie as silent film caption. 1. Select current frame in the movie; text will be pasted before current frame When the current frame is the result of a paste to the end of a movie, it may be necessary to back up a couple of frames and then go forward to paste text in the middle, or else the text may be tacked on at the very end of the movie.
2. Create the text block in a word-processing program (use large font size, such as 24 point) and then paste. The text will appear as white letters on a black background. To add small amounts of text as under-the-image-running caption, do the following: 1. Create a text file with the blocks of text in the desired font and size. Copy a block. 2. Move diamond in time slider to point where this block should first appear. 3. If this isn’t the first block, then Edit > Select None 4. Move the right triangle — before movement, the two triangles form a single triangle just below the current location diamond. When right triangle is at the correct stopping point, let go. The grey area between the diamond and right triangle is where the text block will appear in the movie. 5. Hold down Shift and Option-Alt keys simultaneously 6. Edit > Add Scaled 7. Repeat The text will appear in a thin black box, as white letters, just below video track, providing an after-the-fact caption. There are more sophisticated text track creation schemes which are useful when one wants to add a lot of text, but these procedures will give a flavor of how video editors add text.
14.11
Resolution and Font Sizes
Analog videotape lacks the resolution of a full computer screen. (The maximum is about 640 x 480 pixels whereas a typical computer screen is about 1024 x 768 and an 8.5” x 11” printed page on a 300 dpi printer has a resolution of 2250 x 3000, making allowance for nonprinting margins.) Just as in labeling graphs which will be reduced for journal publication, it follows that it is highly advisable to use
344
CHAPTER 14. ANIMATION
Table 14.3: Frame Rates Rate (Frames/second) 30 29.97 25 24 12 2-10
Format some video formats NTSC video (analog standard in U. S. and Japan) PAL & SECAM video (usual analog standards outside North America) Theatrical movies Hanna-Barbara cartoons Streaming Web video
1. Large font sizes 2. Sans serif fonts One must exercise similar care with other graphical elements. The arrows of quiver plots are easily blurred by video. It is therefore better to use a few large arrows rather than a lot of shorter arrows. (Note that to avoid overlapping arrows, the maximum length of an arrow must be inversely proportional to the spacing of the grid on which the arrows are displayed.) It is usually necessary to “downsample the quiver grid”. This means that if the flow field is computed on a grid of 100 x 100 poins (say), the arrows will be legible on video only if displayed on a 10 x 10 or 20 x 20 grid. Fortunately, it is a trivial exercise to “downsample” to a coarser grid as long as the grid spacing of the coarse grid is an integer multiple of that of the fine grid.
14.12
Frame Rate
Broadcast video and theatrical films use a rather high frame rate. Hanna-Barbara, founders of the cartoon animation firm that still bears their names, discovered that a frame rate of 12/second did not produce unduly jerky images, and adopted this for their cartoons. Streaming video is even slower because typical Internet connections rarely can support anything close to 30 frames/second even with optimum codecs. In making scientific visualizations, a frame rate of 10-12/second is probably adequate to avoid jerkiness, and at the same time keep the file size manageable.
14.13
Tweening
A ten-minute animated cartoon requires about 12000 drawings at the usual cinema rate of 24 frames/second. It is quite impossible for a small team of highly skilled animators to create so many drawings. Therefore, the usual production method was to have the folks with the job title of “animator” draw only a small subset of the total, the “key frames”. All the rest was drawn by less skilled draftsman called “tweeners”. The “tweeners” were doing a kind of manual linear interpolation between the key frames. Since computers are very good at linear interpolation of numbers, one might suppose that “tweening” would be important in scientific visualization. Actually, tweening is rare in scientific applications for two reasons. The first is that if the animation is the result of a numerical simulation, the computer can generate all the intermediate frames simply by saving more images to the hard disk as the simulation is being calculated. Direct calculation is far more accurate (and simpler, since it requires no additional programming) than interpolation.
14.14. ROTOSCOPING
345
The second reason is that tweening is actually very difficult except for vector graphics. For example, suppose the keyframes show the same shape in two different positions. If the shape is a trapezoid, then in vector graphics, this shape is defined by the locations of the four vertices (together with the subsidiary information that each vertex is connected by straight lines). When the trapezoid is moved, the subsidiary information is unchanged, so it is trivial to interpolate. If the vertices are interpolated between the initial and final positions of each vertex, then the “tween” frames will correctly show the exact shape (trapezoids) at smoothly-varying intermediate positions. Success! Suppose that the same trapezoid is approximated by a block of white pixels against a black background, and suppose further that the trapezoid moves by more than its own width between keyframes. Interpolating the colors of the pixels in the keyframes means averaging black-with-white for each pixel covered by the trapezoid in either of the keyframes. It follows that the tween frames will not show a trapezoid of white, but instead both the initial and final shapes will appear in the tweens as shades of gray. As we move from the initial keyframe towards the second keyframe, the trapezoid at the initial position will fade to black whereas the pixels of the final position will brighten from black to white. Interpolation will create a fadein/fadeout transition instead of movement. If the keyframes are closer in time so that the initial and final shapes overlap, then such pixel interpolation may create a limited sense of movement. But it is not surprising that programs that do “tweening” well, such as Flash, are vector-based formats.
14.14
Rotoscoping
“Rotoscoping” is a cinematic term for drawing on individual frames of film. This was first done back in the silent film era. The video editor Adobe Premiere has an export option, “filmstrip”, which is helpful in rotoscoping. The filmstrip file can be imported into Adobe Photoshop as a single file. The filmstrip appears in Photoshop as a single picture in which the individual frames appear as if one were looking at a celluloid filmstrip with the images one above the other, separated by thin grey borders which are automatically supplied. If the filmstrip will be eventually played as a normal animation, then the overdrawings in neighboring frames must be very similar, like the frames of a Bugs Bunny cartoon, or the eye will not be able to detect the overdrawing ( except as a blur) when the frames are played at 24 frames-per-second (or whatever). It follows that the easiest way to make the drawing for frame fifty-six is by copying the image from frame fifty-five, and then making slight adjustments in position or graphical elements. Copyand-modify is very efficient when successive overdrawings are only slightly different from one another. Because the filmstrip images are in a single file, it is easy to rotoscope by copy-andmodify. When the overdrawing for the first frame is copied to the second, it is all done in one file and one window — no need to switch between files and/or windows. When the rotoscoping is completed, the filmstrip can be exported back to Premiere, which can then export the animation either direct to video or as a standard computer animation format. Rotoscoping is potentially quite useful in scientific and engineering graphics. If the animation is a sequence of satellite photographs of clouds, for example, one can rotoscope the the warm and cold fronts, the land masses underneath the clouds, add letters “H” and “L” to mark the location of the pressure high and low, etc. Photoshop
346
CHAPTER 14. ANIMATION
rotoscoping is rather labor intensive because the additions are made manually, but the labor may be worth it if the animation is important. Rotoscoping can also be done in Matlab. For example, Matlab could important a sequence of matrices storing pressure data and calculat the location of the high and low for each time. Matlab could then important a sequence of consecutively numbered images in TIFF format — just a for loop — and write the letters “H” and “L” at the appropriate point on each TIFF image, and then rexported each annotated frame as a TIFF file, consecutively numbered, with a new name. A video editor can then import the whole sequence of TIFF files as a single animation.
14.15
Annotations and Documentation
An animation by itself is of little scientific interest. The flow fields may be very pretty, but what was the Reynolds number? The initial condition? The boundary conditions? It is very important to document the animation by providing these answers. In a better world, animation formats would provide a lot of flexibility for selfdocumentation. It would be very nice, for example, if one can read the creator-written documentation for a Quicktime movie by merely clicking a button in the Quicktime player. Unfortunately, the format-developers have not shown that much foresight. Quicktime has a very limited capacity to support what Apple causes “annotations”. Unfortunately, these are limited to three phrases which are further restricted to topics as Name of Creator, Copyright Notice, and so on. However, the range of annotations may expand in future releases of Quicktime and of other editors. In the absence of internal documentation, it is necessary to provide external publication. On Web sites, one can embed the animation in a text page that provides the necessary information. The user can then download both movie and text page. It is annoying, however, to have to carry two files in different formats for each movie. It is also possible to document within a movie by adding pages which are pure text. Even Quicktime Pro, which is the cheapest video editor on the planet, allows this option. If one wants the viewer to actually read the text while the movie is playing, one can specify that the text page will display for say, five seconds, or typically 120 frames. Alternatively, however,one can specify a very short frame rate of 1/30 second. The viewer will not see the documentation when the movie is played at the normal rate, but will be able to peruse the text at leisure by using the step-one-frame-at-a-time controls that most video players (and all flavors of Quicktime) possess.
14.16
Exporting Stills
Video editing programs almost always have the ability to extract individual frames of an animation and export them as still images. Premiere, for example, can export TIFF, Targa, PICT, Quicktime, GIF, and Animated GIF formats. One popular nonscientific use is to stick a still at the end, and use it as the background while the movie credits roll. Stills can be scientifically useful by illustrating key stages or states in the timedependent evolution. These can be published in the print documentation that accompanies or explains an animation, or supplement the animation on a Web page. If one exports a sequence of consecutively numbered image frames, these can be imported by a different video editor, thus providing a method to transfer animations from one video editor to another.
14.17. PUBLISHING
347
The export-a-still function is often irrelevant in scientific visualization, but the underlying philosophy is not. The reason is that if one is performing, say, a time-dependent simulation of fluid flow in Matlab, a good way to make the movie is to Matlab output a numbered sequence of still images in the TIFF format and then ask Quicktime Pro or another editor to assemble these images into a movie. Since one already has still images of every frame of the animation, it is silly to export frames from the movie. However, it may be very useful to move and rename selected stills from the movie to preserve key moments in the time evolution. We cannot emphasize too strongly that movies and stills are complementary. One of the best things about computer video players is that they provide easy, blur-free freeze-frame so that one can linger over key frames. However, to supplement an animation with print publication or notes, it is essential to have the crucial frames in separate, paper-printable form.
14.17
Publishing
Paper, alas, is unable to display movies, so it is impossible to publish animations in a conventional journal. There are three alternatives: 1. Publication-by-conference presentation 2. E-journals 3. Personal Web site Presenting an animation at a conference is becoming easier and easier; an analog VHS player is almost universal at conference venues. Projectors that can take input from a laptop computer are becoming more and more common. The disadvantage of conference presentation (of any kind) is ephemerality: the animation cannot be archived or preserved for the future even if the conference publishes proceedings on paper. The most lasting result of a conference are the new friends that you make. Electronic, on-line journals or “E-journals” distribute articles exclusively over the Web, and thus can include animations as easily as stills and text. Most professional societies have created E-journals, but these experiments are far from flourishing. One problem is that it is much easier to publish in a print journal since most scienists already have learned how to write a conventional paper. Working animations into a paper is alien and unfamiliar. Furthermore, E-journals usually impose some restrictions on graphic formats, file size, and so that the influx of e-manuscripts does not overwhelm their Web servers and editorial staff, who are learning as they go along. A second problem is archiving. The reason journal articles have bibliographies is that one can find and consult the articles upon which the present paper has been built. Print publications are achived simply by keeping the volumes on a library shelf. Ejournal archiving requires that 1. The journal continues to exist 2. The older e-publications are preserved on the Web site 3. Obsolete file formats are replaced by translating animations to new file formats A third problem is subscriptions. E-journals are rather inexpensive in theory because the text and figure preparation is done entirely by the author, and there are no costs for typesetting, printing or mailing. In theory, a single PC-server and a part-time clerical assistant should be able to keep the journal going indefinitely. Unfortunately,
348
CHAPTER 14. ANIMATION
creating and maintaining the Web site is rather costly. An editor must not only be scientifically-literate, but also rigidly enforce file format standards and such that the animations will display on all platforms. In reality, subscribers are likely to have varying degrees of difficulty in reading animations and e-publications, in part because of obsolescent browser or other software on the Web site. An e-journal must therefore hire expensive computer staff to fix such incompatibilities and hold the hands of novice users. The American Meteorological Society and the American Geophysical Union teamed up to create a journal called Earth Interactions. After several years of not-much-happening, the journal was completely revamped. It remains to see whether Earth Interactions will succeed, but the fact that it was not abandoned is a sign that the professional societies and other journal publishers feel strongly that they must experiment with e-publication. Unfortunately, we are still very young in this experiment. Consequently, e-journal publishers have charged rather hefty subscription fees. Already groaning under the weight of subscriptions to thousands of print journals, most university libraries are reluctant to substract to e-journals or indeed to any new journal of an kind. Thus, e-journals often reach a very small audience compared to conventional print publications. Thus, e-publication is not attractive at the moment because of the large technical difficulties and the small readership. However, this will surel change. A personal Web site is good because one has complete control, and catchy animations can make the Web site into a powerful advertisement for the merits of one’s scientific achievements. The disadvantage is that the user must know HTML and must manually build every feature of the Web sight. In addition, the creator’s close friends will come and visit his Web sight, but who else will come? A print journal is automatically send to thousands of subscribers, and its printed table of contents is perused two thousand times a day. Thus, Web site publication may also be unattractive.
14.18
Video Editing, Transitions and All That
Scientific videotapes, CD-ROMS, etc., often contain multiple simulations. If the video is shown all the way through, the viewer will experience some rather disconcerting jumps from one simulation to another. Professional and home video editors usually try to minimize these jumps (so that the viewer can focus on the clips themselves, and not what happens in between). Video editing software offers a rather bewildering variety of transitions. Most of these are designed to be “arty” and visually-striking, thereby distracting the viewer from the content, and therefore are irrelevant to scientific visualization. However, simple transitions may be useful. The Cross-Dissolve, for example, fades out one scene while slowing bringing the second on top of it. A variation is to Fade to Black at the end of one segment, and then slowly increase the brightness of the title of the next segment. Since even these simple transitions are rare in scientific animations, we will not discuss them further. A simple transition can be helpful, though, if a scientific visualization has distracting scene jumps without a transition. The most common scientific transition, however, is a frame of text that is inserted between two animations to introduce and explain the second animation.
Chapter 15
Graphical User Interfaces (GUIs) for Scientific Models 15.1
Introduction
The design of Graphical User Interfaces (GUIs) is usually regarded as an art for programmingfor-the-consumer. Middle managers and fast-food workers need GUIs because they are computer illiterates, so the conventional wisdom goes, but surely scientific programmers know their own codes, and are beyond pull-down menus and radio buttons. To a degree, the conventional wisdom is correct. There is little point in developing a bullet-proof, super-reliable interface for a research code that will be used for a couple of years by a couple of postdocs or students and then discarded. However, there a couple of reasons why GUIs are useful in science. The first is that a computer program is a dialogue between itself and its programmers and users. Comment lines are the traditional way for the program to “talk”. Modern GUIs provide additional modes of communication. In particular, dialog boxes allow a program to bombard users with information even while running. A second reason is that GUIs can simplify tasks such as specifying initial parameters and interactively analyzing output. Without a GUI, one can edit an initialization file and store output numbers in files for analysis by a stand-alone graphics program. However, this is awkward and time-consuming; it easy to push a button or edit a labeled text box than to search among many lines of code for that one line that needs to be modified. If a scientific task needs to be done over and over again, but never exactly the same way twice, a simple GUI may be a worthwhile investment. A third reason is that writing a GUI can force the programmer to think: What’s important? What parameters are needed to completely specify the problem? In theory, one should always think about these questions anyway, GUI or not. In practice, it is easy to omit details that become crucial only later. Modern structured languages like C and Pascal require the programmer to make a lot of declarations in part to force concrete, specific thinking instead of vague, making-it-up-as-you-go-along coding. A fourth reason is that over the lifetime of a research code, the programmer can forget much of the fine structure of a program. When I was an undergraduate, Joel Primack, who was my mentor for a research project, stressed the importance of writing everything down at the time. “After six months, you’ll read your manuscripts and programs as if they had been written by someone else. So you have to document what you’re doing as if you were writing for someone else.” It is obviously important to pro349
350
CHAPTER 15. GUIS FOR SCIENCE
vide written documentation and lots of comments for computer programs; the reader you write for is your own Future Self, and he or she is an amnesiac. GUIs can help to minimize the defects of memory by making it possible to rerun a program even when the programmer has forgotten the A fifth reason for GUIs is that science has become much more collaborative. More and more, codes are community models or group models. More and more, the usefulness of a code is being measured by its ability to be shared. GUIs tremendously improved the “collaborativity” of a program.
15.2
Taxonomy
GUI elements can be classified by who initiates the action: 1. Program-initiated GUIS: (i) Help, Warning and Error Dialog Boxes (ii) Message (Info) Boxes (iii) Input, Question, and List Dialog Boxes 2. User-initiated GUIS: (i) Display and/or Plot (ii) Pause (iii) Exit Loop (iv) Reassign-While-Running These GUI elements can be further classified by their aims and actions: 1. Informational: (i) Help, Warning and Error Dialog Boxes (ii) Message (Info) Boxes (iii) Display and/or Plot 2. Interactive Control: (i) Pause (ii) Exit Loop (iii) Reassign-Variables-While-Running 3. Assigment: (i) Specification of Cases (ii) Modify Default Values at Initialization (iii) Reassign-Variables-While-Running In what follows, we shall describe how each of these different elements can be useful, giving illustrations in Matlab.
15.3
Dialog Boxes
A dialog box is a GUI function that pops up a box full of text on the screen. The program is suspended until the “OK” button is closed. Dialog boxes need to be used sparingly because they do suspend the program. However, warning or information messages that are merely printed on the screen while the program continues can be easily missed. If the program has made a serious and perhaps fatal error, the program should suspend until the user had evaluated the problem.
15.3. DIALOG BOXES
15.3.1
351
Information Dialog Boxes
Matlab provides four easy-to-use dialog boxes that require no response except clicking on the “OK” button: 1. Help: helpdlg(’Message string’,’Title-of-box string’) 2. Warning: warndlg(’Message string’,’Title-of-box string’) 3. Error: errordlg(’Message string’,’Title-of-box string’,’replace’) 4. Message (alias “Info”): msgbox(’Message string’,’Title-of-box string’,’IconData’,’IconCMap’) ´ In all cases, all arguments except the Message string’ are optional. The third argument of the error box forces it to replace the default error box, which does not happen otherwise. Each of the first three species of dialog boxes displays an icon that signifies its function: a face plus comic-strip-like dialog balloon for the “help” box, a triangle with an exclamation point inside for the “warning” box, and a hand help up as if to say “Stop!” for the ”error” dialog box. The universality of these icons is an illustration of good graphic design: the triangle-with-exclamation-point is employed to warn Macintosh users that an old file is about to be written, and Photoshop users that an RGB-specified color is out of the “gamut” of colors that can be printed by the usual CMYK inks. By default, the message box displays no icon. However, an optional third argument can be used to specify one of the standard icons, or one can use the optional third and fourth arguments to specify the image data of a custom icon plus the accompanying color map. In general, use the “help” box to provide information only when the run is not in peril such as “Sarah, I haven’t finished the hydrology subroutine yet, but you can run this to model a “dry” atmosphere”. A “warning” box is appropriate when the program has identified a difficulty that may or may not make the user terminate the run after reading the dialog box. An “error” box should be displayed only when the problem is so serious that the coder thinks that the user should almost certainly abort the run; the purpose of the box is to explain why the run has to be stopped. The message box is used to supply information of a non-threatening nature. If a code is to be shared by other users, it may be very helpful to pop up an initial message to explain (i) what the code does and (ii) how the user can access various GUI menus and input elements to control the program. For example, msgbox({ Hi, Fred! You can control the program as follows; The menu allows you to select any of the five published case; Button ‘Do your own’ will pop up an input GUI screen; Modify the parameters as you see fit.; Good luck! John}) . In Matlab, msgbox will automatically textwrap a string argument. Alternatively, one make the message string into a cell array to force a line break after each element of the array: ’Message String’ = {’line one’; ’line two’; ’line three’} .
15.3.2
Requester (Input) Dialog Boxes
It is possible to write more sophisticated dialog boxes that not only give information, but also request it. Matlab, for example, provides three species of dialog boxes that request input from the user: 1. input dialog box inputdlg 2. list dialog box listdlg
352
CHAPTER 15. GUIS FOR SCIENCE
3. question dialog box questdlg The inputdlg box requests the user to insert one or more lines of text. The allowed syntax is • replystring=inputdlg(’Prompt’) • replystring=inputdlg(’Prompt’,’Box Title’) • replystring=inputdlg(’Prompt’,’Box Title’,number of lines) • replystring=inputdlg(’Prompt’,’Box Title’,number of lines,’Default String or Cell
Array’) where the replystring is always either a string or a cell array of strings. The replystring is of the same type as ’Prompt’: if ’Prompt’ is a cell array with four elements, then replystring is a cell array of four elements also. One can access the second string of the array by Replystring{2} , and convert the string to a floating point number using eval(string). The integer number of lines specifies the number of lines that are to be input for each string Prompt. If number of lines=2 and ’Prompt’ is a cell array of three strings, then a dialog box will appear with three text boxes each of two lines to hold the user input. Of course, one can request input from the command line, without using a dialog box, by using the Matlab command input. The dialog box allows for more complicated string input. Indeed, the input dialog box can be used to replace the more sophisticated initialization GUI described in the next section. The goal is to present the user with a screen full of default values for various parameters with the freedom to change as few or as many as desired and then close the dialog box. For example, suppose the parameters are the number of grid points in the x and y directions, which are integers, and the viscosity coefficient, which is a floating point number. The dialog box shown in Table 15.1 will pop up an input dialog box with three white rectangles, each one line tall, which will contain the default values. The cell array Prompt is used to specify the labels for each input line. The cell array DefaultAns contains the default parameter values, which must be specified as strings. The user can click on some or all of the white rectangles to edit them. The default can be deleted through the backspace or delete key and the new value inserted. When editing is done, one merely clicks “OK” and the dialog box will disappear. The output of the dialog box is the cell array Answer. Its elements can be converted to numbers, either integer or floating point, by using the eval function. In this example, there are three lines, but the input dialog box allows an arbitrary number of lines [as many will fit on the screen!]. One is free to change all the default values, or none, or some. One can also changes one’s mind in the middle of editing, and re-edit lines that have already been changed. The Answer cell array is returned only when the “OK” button is clicked. This input-with-defaults dialog box is so simple and powerful that it is highly recommended. The only limitation is that the input lines are stacked vertically with about thirty spaces reserved for each input, more than one would ever need even to specify a full precision, sixteen decimal place number. In the next section, we will describe a more sophisticated GUI that allows the user to pack more input boxes on a screen at the cost of more fiddling.
15.4. PUSH-BUTTON MENU
353
Table 15.1: Initialization GUI: Input Dialog Box Prompt = ’no. x grid points=’;’no. y grid points=’;’viscosity=’; % labels for each input line Title=’initialization dialog box’ ; % title to be printed at top of dialog box DefaultAns=’25’;’33’;’1.378’ ; % Default values; user can change some, all or none LineNo=1; % Number of lines in each input box, always one to insert a number Answer = inputdlg(Prompt,Title,LineNo,DefaultAns); % The dialog box appears % The user can click on a given white box with a default number and type % to change it. When all editing of defaults is over, simply click “OK” NX=eval(Answer1) ; % eval converts the cell array (string) to a number NY=eval(Answer2); nu=eval(Answer3); % Floating point and integers are converted by identical means.
A list box does not request keyboard input, but instead offers a list of options, and asks the user to choose one (or click “cancel”). The syntax is [Selection, OK] = listdlg(’PromptString’,TitleofBox,’ListString’,S). ’PromptString’,TitleofBox are optional; TitleofBox is a string that serves as a title or prompt for the dialog box, such as ‘Choose a Case’. S is a cell array of strings that label the choices, such as S={’Choice One’;’Selection Two’; ’Option Three’}. (There are a lot of additional options; see the Matlab help for this function.) The strings in italics are names of promperties (i. e., ’ListString’ and ’PromptString’ and must not be changed.) If one hits “Cancel” when the list box appears, OK=0; if one selects something, then OK=1 and Selection=[], the empty set. (More good design; the main program can check OK before attempting to respond to the selections.) Selection is an integer which is the number of the selection — if the list offers four possibilities, Selection will be 1, 2, 3, or 4 — if only one selection is made. In the case of multiple selections, which can be done by Shift-clicking on a Macintosh, then Selection will be a vector of integers. The “question dialog box” questdlg is a variation on the list box in which (i) the number of choices is precisely three and (ii) the choices are offered as pushbuttons instead of text-to-be-clicked-and-highlighted. In contrast to the list box, which returns an integer, a question dialog box returns a string. The syntax is ButtonName = questdlg(’Question’,’TitleofBox’, ’StringforFirstChoice’,... ’StringforSecondChoice’, StringforThirdChoice’,’StringforDefaultChoice’). The ’TitleofBox’ string will appear as the title of the box. The ‘Question’ string will appear as a prompt inside the box, followed by a question mark. Clicking the second button will make the string ButtonName = ’StringforSecondChoice’.
15.4
Push-Button Menu
When a program can run in a number of standard modes or execute a number of standard cases, the user needs to be able to specify which mode or case. Of course, the user could edit the program file, but this requires accessing a main program with dozens or even hundreds of lines to modify only a single line. It is far better to have the program do it by GUI by displaying a pop-up menu of pushbuttons, each labeled with one of the modes or cases. In Matlab, the syntax is integer flag = menu(’Title of the menu’,’Case One’,’Case Two’,’Case Three’) There is no restriction on the number of pushbuttons. When a button is pushed, the variable integer flag is set equal to one if the first choice was pushed, two if the second choice was pushed and so on. This integer can be used in an if statement to switch to execute the user-chosen option. In scientific studies, it is common to run a hundred different cases or parameter combinations during the “exploratory” phase of the study. Most of these cases were
354
CHAPTER 15. GUIS FOR SCIENCE
run in haste and only partially analyzed, and in any event are far too numerous for any journal. The published version of a numerical study will normally discuss only four or five cases in detail. One can archive the published cases in a single main program with a popup menu. It is then easy to rerun these cases for further analysis, perhaps as part of a follow-up study years later, even if the programmer has graduated.
15.5
Example: An Initialization GUI, Such as That for a Fluid Mechanics Code
A time-dependent modelling code requires the specification of a large number of parameters. Some of these are discrete variables, such as the number of grid points in the spatial coordinates, the number of time steps, the strength of the viscosity coefficient and so on. Others are continuous functions. All can be specified through either by statements in the code or by user input through a GUI. A drawback of requester dialog boxes without defaults is that all input data must be completely specified each time the code is run. If a code contains 30 parameters, and one only changes one or two from run to run, the need to reenter the other twentyeight parameters each time is a ghastly time-waster. In the previous section, we showed that an input dialog box with defaults can avoid this problem. In this section, we will describe a different GUI, employing individual static and editable text boxes, that can allow the user to view all the parameters, and then selectively change only those that needed to be modified from the defaults. The text box GUI is more complicated to build, but gives the user more freedom, and in principle allows a larger number of input parameters to be displayed and edited on a single screen. One technical detail is that the initialization GUI must be informed when the user is satisfied. In Matlab, the easiest way to do this is to include (i) a function that creates a figure with all the initialization GUI elements and (ii) the statement waitfor(gcf), which pauses the program until the current figure disappears. One can therefore resume execution of the program merely by closely the figure window that displays the initialization GUI. The GUI needs two species of elements: “static” text boxes, which display the labels identifying and explaining each parameter and “editable” text boxes. The editable boxes initially display the default values of each parameter, which should be assigned before any of the GUI boxes are called. The user can then change any or all of the text in the editable boxes. The result of the change will be passed back as a string variable. However, a string variable is not the desired answer; we want to execute an assignment statement that uses the the editable text, converted into a number, as the right-hand side. One could add a bunch of conditional statements in the main program to convert each string into the proper assignment, but there are two problems: (i) the GUI pauses the main script so that it can’t execute anything and (ii) even if the main program is still alive, adding several statements to the main program for each assignment from the function would mix the code of the function and main program, which is poor programming practice. (The code that does the work of a function should be isolated in the function, not contribute 80 lines to the main program, too.) Fortunately, it is possible to work around these problems by using a “callback”.
15.6. CALLBACKS
15.6
355
Callbacks
In Matlab, when a GUI object is activated, it supplies an executable statement to the main program which is called the “callback” of the GUI object. If the callback string is ‘NX=5’, for example, then this assignment statement will be executed in the main program. The callback string is not limited to a single statement, however; it can be a whole list of statements separated by commas or semicolons. One annoying complication is that in the call to the GUI object, the sequence of statements must be defined as a string. This means that the callback string must begin and end with an apostrophe. However, strings-within-the-string must be bounded by double apostrophes so that the interpreter won’t be fooled into stopping prematurely before reading the entire callback. User-dependent data can be included in the callback by using the eval function: NXstring = uicontrol(qcf,... ’Style’,’edit’,... ’Units’,’normalized’,... ’Position’,[0.11 0.85 0.1 0.1],... ’String’,int2str(NX),... ’Callback’,’NX=eval(get(NXstring ,”String”))’ ); The uicontrol is the generic Matlab name for almost any GUI object that isn’t a menu. The ‘Style’ property specifies the type of GUI, in this case, an editable text box. The ‘Units’ and ‘Position’ control the placement of the editable text box on the figure window. When it first appears, the ‘String’ property of an editable text box displays the default value of the string. The default value of NX, which is defined by a standard assignment such as NX=20, is converted from an integer to a string by the built-in Matlab function int2str. When the figure window first appears, this integer-converted-to-string appears in the editable text box. When the text in the box is changed by moving the cursor into the box, deleting the existing numbers and then typing in new ones from the keyboard, the ‘String’ property is updated to its new value. This triggers an immediate updating of the ‘Callback’, which implies that the assignment statement is executed in the main workspace. The right-hand side of the assignment statement is computed by the eval function, which takes a string as its argument and then executes the string as if it were characters typed directly into the command window. The string for eval comes from executing a get command, which first finds the graphic object whose handle is NXstring and then returns the ‘String’ property of that object. One complication is that the callback must use get nested inside the eval to use the editable text as the right-hand side of the assignment statement. However, the real subtlety is that the eval and get functions are executed in the workspace of the main script. If the uicontrol statement is in a function, then the get function has no direct way to find the handle to the editable text box, NXstring , which is defined only in the subroutine. There are several ways to get around this problem. In our sample program, the string variable is declared global by including the statement global NXstring in both the function code and the main program. The main program can then find the editable text box’s handle to evaluate its updated ‘String’ property. Although this is probably the simplest and most effective strategy for an initialization window, which is onscreen just once and then disappears, most Matlab books including the manuals suggest instead storing information in the ‘UserData’ property of the figure window. The “global variable” strategy will fail if (i) the user types a clear statement in the Matlab command window or (ii) if the user makes a second call to
356
CHAPTER 15. GUIS FOR SCIENCE
the function that contains the uicontrol statement. Neither of these difficulties can arise for an initialization window since the main program is suspended (except for the execution of GUI callbacks). The “UserData” storage-of-GUI-handles is more robust than the global variable method for very complicated GUIs in which the GUI objects are persistent while the main program is running. Even if a clear global statement is executed, the figure keeps its ‘UserData’ intact until the figure window is closed. However, this method of storing handles is inappropriate for GUIs that are called only once. The reason is that the UserData strategy requires that one call the GUI-creating function twice, once to initialize the GUI-object and store the handle in the UserData, and the second time to retrieve the UserData.
15.7 Variation: Input Slider For a jazzier initialization screen, one can replace an editable text box by a slider. This is much more complicated because to be legible and flexbile, the slider needs four GUI elements: 1. Static text box to list the minimum of the slider. 2. Static text box to list the upper limit of the slider range. 3. Editable text box to (i) show the value of the slider as it changes. (ii) bypass the slider to allow a precise numerical value to be typed in. 4. Slider itself. Because there are four elements, and also because of the mutual dependence of the editable text box and the slider on each other, the code is much more complicated than for a simple editable text box. Why bother? The answer is: no compelling reason. However, once one has a prototype of a slider to work with, such as the Matlab code in the two tables here, it takes only a couple of minutes to edit the prototype to make a new slider to control a new variable. Sliders have become popular because it is easier, at least for some users, to click or drag the slider than to type in a precise numerical value in a text box. Sliders are never necessary, however, so the reader who is put off by the intricacy of slider coding can simply ignore sliders.
15.7. VARIATION: INPUT SLIDER
Table 15.2: Initialization GUI MAIN PROGRAM global NXstring ; % This global statement allows the editable % text box to find NXstring when executing callback. NX=GUI INIT waitfor(gcf); % suspends program until the figure is CLOSED. INITIALIZATION FUNCTION function NX=GUI INIT; % There are five statements: % (i) global declaration % (ii) creation of figure % (iii) default assignment % (iv) define static text box % (v) define editable text box % Sixth statement creates a pushbutton to CLOSE % the window and return control to the main program global NXstring ; % Zeroth, create a figure and store its figure handle fh=figure; % First, assign a DEFAULT value to NX NX=20; % The output of the function is ALWAYS assigned to this default. If the editable text box % is changed,then NX will change in the main program, but only because the text box callback % will cause NX= new value to be executed in the main workspace. % Second, create a STATIC TEXT BOX to label the editable text box. NXlabel= uicontrol(fh,... ’Style’,’text’,... ’Units’,’normalized’,... ’Position’,[0.01 0.85 0.1 0.1],... ’String’,’no. x grid pts.=’); % Create EDITABLE TEXT BOX; enter numbers in box to change NX % Default for NX is the string entered after the first ’STRING’ % in the NXstring call NXstring = uicontrol(fh,... ’Style’,’edit’,... ’Units’,’normalized’,... ’Position’,[0.11 0.85 0.1 0.1],... ’String’,int2str(NX),... ’Callback’,’NX=eval(get(NXstring ,”String”))’ ); % Editable textbox returns the box-handle NXstring . % In the callback, ”get” looks up the string property of % the object whose handle is NXstring . % eval(s) takes the string ’s’ as its argument, and % executes the string as a matlab statement; in this context, % it converts the string to a number. % The number which is output by eval is then assigned to NX closefighandle= uicontrol(gcf,... ’Style’,’pushbutton’,... ’Units’,’normalized’,... ’Position’,[0.9 0.1 0.1 0.1],... ’String’,’Close’,... ’CallBack’,’close’);
357
358
CHAPTER 15. GUIS FOR SCIENCE
Table 15.3: Matlab Main Program and First Function for a SLIDER global NYsliderhandle slidervalue ; % This global statement allows the editable % text box to find NYsliderhandle when executing callback. % The value of the slider is returned as the global variable slidervalue % when the figure window is closed. GUI sliderfather waitfor(gcf); % suspends program until the figure is CLOSED. NY=slidervalue function GUI sliderfather; global slidervalue % The obvious technique of setting slidervalue=GUI sliderfather doesn’t work unfortunately. %The output argument slidervalue is assigned when GUI sliderfather is first executed, that is, % when the figure window is created. Even though slidervalue is % changed by later slider movements, the output value of % GUI sliderfather, is not updated when the window is closed. figurehandle=figure; % Second step: define minimum and maximum values for the slider. slidermin=1; slidermax=100; % Next make the slider appear GUI sliderB(’initialize’,slidermin,slidermax) disp(’Slidervalue in GUI sliderfather just below’) slidervalue=slidervalue closefighandle= uicontrol(figurehandle,... ’Style’,’pushbutton’,... ’Units’,’normalized’,... ’Position’,[0.9 0.1 0.1 0.1],... ’String’,’Close’,... ’CallBack’,’slidervalue=slidervalue , close’);
15.7. VARIATION: INPUT SLIDER
359
Table 15.4: Second Function for a Slider, Called by Function in the Previous Table FUNCTION GUI SLIDERB function GUI sliderB(command str,slidermin,slidermax) % The value of the slider is returned as the global variable slidervalue % when the figure window is closed. % Input: command str is always the string ’initialize’ % slidermin, slidermax are the maximum and minimum values of the slider % The default value for the slider is the average of slidermin, slidermax. % The calling routine MUST create a figure window before GUI sliderB is called. % WARNING: this subroutine sets values in the ’UserData’ of the parent figure, gcf global slidervalue % The ’value’ property of the slider uicontrol whose handle is % h sldr is used to store the numerical value chosen in the slider. % If GUI sliderB is called with a command str other than ’initialize’, % it means it has been called recursively by itself, and the next % block of lines should be executed. if strcmp(command str,’initialize’) handles = get(gcf,’userdata’); h sldr = handles(1); h min = handles(2); h max = handles(3); h val = handles(4); slidermin=handles(5); % get minimum and maximum slider values slidermax=handles(6); % from userdata on non-initialization calls slidervalue = get(h sldr,’value’) end if strcmp(command str,’initialize’) % BEGINNING of INITIALIZATION h frame = uicontrol(gcf,’style’,’frame’,’Units’,’normalized’,... ’position’,[0.01 0.01 0.4 0.4]); h sldr = uicontrol(gcf,’callback’,’GUI sliderB(”Slider Moved”);’,... ’style’,’slider’,’min’,slidermin,’max’,slidermax,’Units’,’normalized’,... ’position’,[0.1 0.02 0.2 0.17]); set(h sldr,’Value’,0.5*(slidermin+slidermax)); % h min, h max are handles to two static text boxes that show % the minimum and maximum values of slider, defined by slidermin, slidermax h min = uicontrol(gcf,’style’,’text’,’string’,num2str(get(h sldr,’min’)),... ’Units’,’normalized’,... ’position’,[0.02 0.2 0.09 0.09]); h max = uicontrol(gcf,’style’,’text’,’string’,num2str(get(h sldr,’max’)),... ’Units’,’normalized’,’position’,[0.25 0.2 0.09 0.09]); % h val is the handle for an editable text box. The value it % displays is slaved by the callback to the ’Value’ property % of the slider. However, if the text box is edited on-screen, % this update will also change the value of slidervalue h val = uicontrol(gcf,’callback’,’GU sliderB(”Change Value”);’,... ’style’,’edit’,’string’,num2str(get(h sldr,’value’)),... ’Units’,’normalized’,’position’,[0.13 0.2 0.1 0.1]); % Next two lines insert the four figure handles plus the % values of slidermin, slidermax into the ’Userdata’ of the parent figure handles = [h sldr h min h max h val slidermin slidermax]; set(gcf,’userdata’,handles); slidervalue = get(h sldr,’value’) % END of INITIALIZATION elseif strcmp(command str,’Change Value’) user value = str2num(get(h val,’string’)); % The if statement sets user value equal to the default if % user value has not been previously defined (so its length is zero) if length(user value); user value = (get(h sldr,’max’)+get(h sldr,’min’))/2; % Next two lines ensure that user value cannot exceed slidermin and slidermax. user value = min([user value get(h sldr,’max’)]); user value = max([user value get(h sldr,’min’)]); set(h sldr,’value’,user value); % set slider’s ’Value’ property equal to user value set(h val,’string’,num2str(get(h sldr,’value’))); % Set editable box’s property equal to user value, too. slidervalue = get(h sldr,’value’) elseif strcmp(command str,’Slider Moved’) set(h val,’string’,num2str(get(h sldr,’value’))); slidervalue = get(h sldr,’value’) end
360
15.8
CHAPTER 15. GUIS FOR SCIENCE
Example Two: Post-Run Analysis (“Postvisualization”)
Programs often do complicated analysis, using many different species of graphs, after the completion of the calculation. It is rather tedious to type in all the subroutine calls, graph titles, axis limits, and so on to make nice graphs. If the graphs are somewhat standardized, then it may be helpful to associate some menus with an illustration program. Table 15.5 lists Matlab code for plotting a function y(x) and putting up some menus that allow the user to change the type of graph and the marker symbols very rapidly by clicking menus. When the uimenu command is used without a callback but specifying a figure handle as its first argument, uimenu creates a top-level menu that appears at either the top of the screen (Macintosh) or the top of the plotting figure window (other platforms) with a text label specified by its ‘Label’ property. When uimenu is called with a first argument that is the handle of a top-level menu item, the result is a submenu that appears when the top-level menu is dragged down. If the uimenu has a callback, it will be executed. For a post-run analysis, it is not necessary to include a waitfor command in the main program to suspend execution of the main program. Instead, the main program can be allowed to terminate. The menus and the plotting window remain alive, but the user can make further modifications to the graphs by typing command lines. Thus, the predictable tasks have been automated and can be done by menus, but the user is still free to do the unpredictable by typing on the keyboard. One generic problem with Matlab GUIs is that the callback strings can become very complicated and hard to read and debug. To avoid this, the function in Table 15.5 calls another function in its callbacks. This dependent function in the callbacks is listed in Table 15.6. The Matlab manuals and third-party texts consider it very sound practice to define new functions to serve as callbacks.
15.8. EXAMPLE TWO: POST-RUN ANALYSIS (“POSTVISUALIZATION”)
Table 15.5: Matlab Menu Interface for Post-Run Graphics function dummy=GUIgraphoptions(x,y) global GUIgraphoptionsPlotType GUIgraphoptionsMarkerType; % The callback assignment is always executed in the % base workspace rather than that of this function. % We must include a global statement in both this function % and in the calling program so that the % main program can pass the variables back to this function. % The callback that actually does the plot was done by % a function, GUIgraphoptions2.m, because trying to % put all the statements with conditions in the callback % itself was a mess. % This figure returns control to the command line % but the figure and its menus remain active. % One can modify the figure by typing commands from the keyboard. if size(x) = size(y), Hd error = errordlg(’Argument of GUIgraphoptions is zero’,... ’Error Dialog Box Example’); end figurehandle=figure(1); Hd help = helpdlg... ({’Graph of (x,y) will be plotted or updated (replotted)’; ... ’only when the Display Plot menu item is activated’},... ’GUIgraphoptions.m Dialog Box’); % Default values GUIgraphoptionsPlotType=1; GUIgraphoptionsMarkerType=1; handle menuone=uimenu(figurehandle,’Label’,’Plot Type’); handle menutwo=uimenu(figurehandle,’Label’,’Marker Type’); handle menuthree=uimenu(figurehandle,’Label’,’Display Plot’); menuitem11= uimenu(handle menuone,’Label’,’Line Graph’,... ’Callback’,’GUIgraphoptionsPlotType=1’); menuitem12= uimenu(handle menuone,’Label’,’Stem Plot’,... ’Callback’,’GUIgraphoptionsPlotType=2’); menuitem21= uimenu(handle menutwo,’Label’,’Open Disks’,... ’Callback’,’GUIgraphoptionsMarkerType=1’); menuitem22= uimenu(handle menutwo,’Label’,’x’,... ’Callback’,’GUIgraphoptionsMarkerType=2’); % The next menu item has a callback that calls a function % to actually display the plot menuitem31= uimenu(handle menuthree,’Label’,’Display Plot’,... ’Callback’,’GUIgraphoptions2(x,y)’);
361
362
CHAPTER 15. GUIS FOR SCIENCE
Table 15.6: Matlab Menu Interface: Dependent Function function GUIgraphoptions2(x,y) global GUIgraphoptionsPlotType GUIgraphoptionsMarkerType; if GUIgraphoptionsPlotType==1 & GUIgraphoptionsMarkerType==1 if GUIgraphoptionsPlotType==1 & GUIgraphoptionsMarkerType==2 if GUIgraphoptionsPlotType==2 & GUIgraphoptionsMarkerType==1 if GUIgraphoptionsPlotType==2 & GUIgraphoptionsMarkerType==2
15.9
plot(x,y,’k-o’); end % if plot(x,y,’k-x’); end % if stem(x,y,’k-o’); end % if stem(x,y,’k-x’); end % if
Interactive Control Through Menubar (Pulldown) Menus and Computational Steering
Pushbutton menus to initialize a calculation are easy to write because the menu is active only at the very beginning and the user is allowed to only make one choice. However, Matlab also supports menus attached to the menubar of a figure or the screen. These are much more powerful in the sense that they allow the user to interactively alter the run in the middle of execution. The uimenu command can be used to add menus both at top level, and at sublevels. On the Macintosh, top level menu items are added to the usual top-of-the-screen menu bar. (It is only possible to have a single top level menu; there is a bug on the Mac such that selecting any uimenu-added top level item simultaneously causes all the uimenutop level items to execute). On Unix and Windows machines, the top level menu items appear on top of the figure window. On any platform, one can add submenu items by using the handle of the top level uimenu command as the first argument for the uimenu command that creates the submenu. The advantage of a menubar menu is that the user can select the item at any time during the course of a run. This makes it possible — in the middle of execution, and without stopping the code — to • Display or plot variables • Pause execution • Exit a loop • Change variables • Load from or save to a file
A sample Matlab code is shown in Table 15.7. The loop factors a matrix and does two plots during each iteration merely as standins for the number-crunching of a typical code; in numerical applications, the loop would be over timestep or iteration number. While a long run is unfolding, it is common to watch graphs on the screen, and want more. Menus make it possible to call up additional printed output or additional graphs to confirm that the run is failing or to shed new light on interesting phenomena in the middle of execution. If a Newton iteration is failing to converge, or converging very slowly, one can use a pulldown menu to change the approximate root, and restart the iteration from a different number. Similarly, one can save interesting immediate results by pulling up a save-to-file dialog box.
15.10. SUMMARY
363
Table 15.7: Menus-to-Interrupt a Loop figure handle=figure; h uimenu=uimenu(figure handle,’Label’,’PauseLoop’) % One can display or plot variables in the middle of the loop through the next two sub-menus h1=uimenu(h uimenu,’Label’,’Display Egad!’,’Callback’,’display([”Egad!= ”,num2str(Egad)])’) h2=uimenu(h uimenu,’Label’,’Plot a Row’,’Callback’,[’plot(A(1:n));’ ’title’ ’drawnow;’ ’pause’]) % One can change a variable in the middle of the loop through either of the next two sub-menus h3=uimenu(h uimenu,’Label’,’Input Smoker’,’Callback’,... ’Smokercell=inputdlg(”Smoker=”,”Smoker inputdlg”);Smoker=eval(Smokercell1)’) h4=uimenu(h uimenu,’Label’,’Assign Boomer=3’,’Callback’,’Boomer=3’) % One can pause the loop h5=uimenu(h uimenu,’Label’,’Pause’,’Callback’,’display(”paused”);pause’) % One may also stop the loop without stopping execution of statements after the end of the loop. % The callback changes the value of a flag, which triggers an IF statement to skip the guts of the loop. h6=uimenu(h uimenu,’Label’,’Eject from Loop’,’Callback’,’myflag=0’) for j=1:jmax if myflag==1 B=inv(A); disp([’j=’,int2str(j)]); slurpy=mesh(A); drawnow; plot(A(5,1:4)); drawnow; iter=iter+1 end end
15.10
Summary
GUIs can be useful in scientific applications, especially for shared codes. The ease of coding a GUI varies tremendously with the active lifetime of the GUI object. In terms of increasing difficulty, the three categories are 1. “Individual dialog boxes and pushbuttons” 2. “Persistent-while-paused” 3. “Persistent throughout execution of the main program” Dialog boxes and pushbutton menus, last just long enough for the user to make a single choice. These are easy to write. “Persistent-while-paused” objects, such as window that displays editable text boxes that control initialization parameters, suspend the main program while the user can perform one or many inputs. The program resumes only after the window disappears, which minimizes side effects. GUIs that persist while the main program is running or while other GUI functions are called are very tricky to write because the main program and various GUIs, all simultaneously executing and/or displaying windows, can easily clobber each either. The best way to code a GUI is to copy a prototype, such as the Matlab examples in the table, and then lightly edit it to fit the user’s needs. Patrick Marchand’s Graphics and GUIs with Matlab, now in its second edition, is also a good source of sample code and ideas. A borrowed template insulates the user from most of the complexities of GUIwriting; the downside is that the user doesn’t understand the borrowed template very well. However, because the purpose of the GUI is merely to report or assign variables, there is little danger that the GUI will lead to errors. Mathworks, Inc., now provides a built-in GUI-maker called guide. Marchand’s book describes an alternative he dubbed guimaker. The reason that GUI-writing applications exist is that combining multiple GUIs on a single screen requires a lot of trial-and-error. One difficulty is interaction between different GUIS. Another is that each GUI has a specified size and position, and specifying new position and sizes until the boxes are aligned and do not overlap is very tedious. Unfortunately, neither guide nor guimaker
364
CHAPTER 15. GUIS FOR SCIENCE
is particularly easy to use. The best strategy is therefore to steal or build a template, and recycle it endlessly. Persistent GUIs with mouse-draggable objects and lots of different GUI objects on the screen are the ultimate in user-friendliness. They are also sufficiently complicated to write that they can consume vast amounts of programming time without materially advancing the science. Indeed, sometimes GUI-programming can be a way of evading the science when an investigation is blocked, an algorithm is unstable or error-prone, or a project lacks clear goals. A good scientist should use simple GUIs a lot and complicated GUIs not at all.
Chapter 16
Visualization as Fine Art 16.1
Introduction
The best way to learn graphic design is to do a lot of looking. Because of this, part of an education in scientific visualization is a course in fine arts. Instead of looking at paintings and sculpture in a museum or the slide show of a fine arts course, one needs to look at a lot of exemplars in scientific visualization. Merely looking is insufficient. We need to look actively rather than passively. That is to say, to learn from looking at graphs, we need to ask ourselves as we look: • What information is this graph trying to convey? • What aspects of the design enlighten? • What aspects of the design are confusing, or require the reader to work hard to
decode the message? • Would a different format of graph have been more informative? • What could be changed to improve this graph?
The second qualifier is that a scientific graph is only as good as the science. Many Nobel Prizes have been won by papers that did not contain a single chart or diagram. Conversely, pretty visuals can’t make a bad idea influential. However, they may disguise the smell of a stinky concept for a time. The third qualifier is that we have to look at visualization with the eye of a commercial illustrator. Most professional artists work at a mixture of advertising drawings and book illustration. The purpose of the former is sell toothpaste; the latter is to sell ideas. Scientific visualization is about selling ideas, too. We do not wish to imitate the dishonesty of much advertising. However, every parent has had the experience of being presented with a drawing of bright splashes of yellow, red, brown and black by a small child. “That’s a very nice, dog, Emma.” “It’s not a dog, Daddy, it’s a person!” (Indignantly, followed by a snort.) Metaphorically speaking, we want to design our scientific drawings so that one can tell the dog from the person. 367
368
16.2
CHAPTER 16. VISUALIZATION AS FINE ART
Gilbert: De Magnete(1600), Illustration of Experimental Method
Figure 16.1: A woodcut from William Gilbert’s treatise on magnetism (1600). It shows the manufacture of a magnetized bar. If the bar is heated and then placed on the anvil so that its ends are oriented towards magnetic north (septentrio) and south (auster), then after the bar cools, it is magnetized. This suggested to Gilbert (correctly!) that the earth itself was a magnet. Fig. 16.1 is taken from a Latin treatise by William Gilbert (1544-1603), personal physician to Queen Elizabeth I and King James I. This illustration shows technique rather than concept: by heating an iron bar and orienting it parallel to the earth’s magnetic field, one can magnetize the bar. A modern book would probably use a photograph instead of a woodcut. Still, Gilbert’s diagram requires choices that face modern illustrators, too. The first issue is that visualizations should always be stripped to the minimum; extraneous graphical elements merely distract without enlightening. In Gilbert’s picture, the essentials are the iron bar and the directions north and south. The table, windows, and other furnishings and the earnest man pounding away with a hammer are all irrelevant to the science per se. However, it is very important to always remember the background and experience of the readership. In Gilbert’s time, when there were no professional scientists, his readers were much less comfortable with abstract, minimalist graphics. Gilbert’s picture that shows an actual man banging a hammer on an anvil was probably quite appropriate for his audience.
16.3. COSMOLOGY MODELS OF THE SEVENTEENTH CENTURY
369
In our time, we can get away with more abstraction than was possible in 1600. However, the scientific literature is riddled with graphs which use esoteric terminology or graphical elements which are perfectly comprehensible to the author and her drinking buddies, but as cryptic as Etruscan to the other 99% of her readers. Another issue is that Gilbert’s figure is a pseudo-photograph: When are photos better than drawings and vice-versa? Alley (1996) writes “The major advantage of photographs is realism. For instance, once readers see a photograph of the eruption of Mount St. Helens, they know that the volcano has, in fact, erupted. ... This advantage of realism is also a disadvantage. A photograph not only shows a subject’s true textures and tones, but also its true shadows and scratches. These extraneous details can easily confuse the reader.” (pg. 153.) What Alley means is that a photograph of an experimental apparatus will inevitably pick up the rest of the room. A schematic drawing, in contrast, can be limited to just the essentials. Furthermore, the parts can be moved around (as in a so-called“exploded view”), shown in different sizes, and manipulated as needed for clarity. Alternatively, one could crop a photograph by cutting away the unessentials. This is very common in non-scientific graphics. For example, the children’s guides from Doris-Kindersely publishing contain pictures of many objects that are cropped to the irregular outline of the object itself. Unfortunately, most scientific authors and journals are not this skillful, so scientific readers expect rectangular photos. If one crops a photo to an irregular, one needs to explain what has been cut away, and its irrelevance, or the scientific reader may be become suspicious. Even if this is done, there is still the problem of showing all the “shadows and scratches” in Alley’s words. In short, photographs are for faith, drawings for concepts. One qualifier: Gilbert’s illustration is a depiction of method and apparatus. When the photo is of the phenomenon, as in an astronomical image, a whole set of additional issues arise.
16.3
Cosmology Models of the Seventeenth Century
Fig. 16.2 is not merely a graphical representation of a theory, but is a comparison between six theories. Since it is extremely difficult to compare six verbal descriptions, the graphical comparison — all the key ideas on a single page — is very valuable. The illustration is clearly labelled with the name of each system. This is a sound practice that too many authors forget, three-and-a-half centuries later. The sun and the earth are labelled as icons — the earth as a disk with the continents, the sun as a human face with rays. The solar face is false to the physics. However, such representations were common in seventeenth century art and thus familiar to the readers. The planets are labelled with the astrological signs for the planets; Venus, associated with the Roman Goddess of Love, is marked with a stylized mirror. Although most modern readers find them mystifying, these labels-by-icon were entirely appropriate for the readership of the maker’s time. One theme inherent in this graph is therefore: label everything, and label it using symbols appropriate to your readers. If you need to use symbols or abbreviations that may not be obvious to some of your readers, explain them clearly in the caption! If the reader enjoys decoding, he can buy a book of cryptogram puzzles at the supermarket. Don’t turn your graphs into an exercise in cryptography! The annoyed or disgusted reader may be reviewing your next grant proposal.
370
CHAPTER 16. VISUALIZATION AS FINE ART
Figure 16.2: An early seventeent century comparison of six models of the solar system. The first five are geocentric models with the rest of the universe revolving around the earth; the scheme in the lower right is the Copernican system with the sun at the center.
16.4
Nodal Patterns of the Vibrations of a Thin Metal Plate
Ernst Chladni(1756–1827) was educated as a lawyer, groomed to take over his father’s legal practice. He turned to science instead. Because he was also a very good amateur musician, he became especially interested in acoustics. Discovery of the Theory of Pitch was the first broad treatise on acoustics. He mapped the normal modes of a thin metal plate by sprinkling sand on top of the plate and then drawing a violin bow across different points on the edges of the plate. This excited various eigenfunctions of the plate. As the metal jiggled up and down, the sand was expelled from the moving parts of the plate. The sand collected in the nodal lines where the eigenfunction has no motion. Chladni then drew the patterns he observed to classify the structure of the oscillations. Fig. 16.3 shows a sample of his drawings. The first theme is that to make a great scientific visualization, do great science. The eigenfunctions of vibrating plates and membranes of various shapes is still a subject of intensive research two centuries after Chladni’s drawings were first published. The title of a paper by the late, great Mark Kac, “Can You Hear the Shape of a Drum?” was answered only in the early 1990’s; it has been proven that there are plates of different shapes that have exactly the same eigenfrequencies. Joyce McLaughlin has made a great reputation in mathematics by developing a general theory for the inverse theory of how different shapes of membrane or plate are associated with different patterns of frequencies and nodal curves. The second theme is that sometimes geometry = physics, as here. The nodal pat-
16.4. NODAL PATTERNS OF THE VIBRATIONS OF A THIN METAL PLATE
371
Figure 16.3: Nodal patterns, observed by sprinkling sand on an oscillating metal plate, from Chladni’s 1987 book on acoustics. Each graph illustrates the zero-curves of a different eigenfunction.
372
CHAPTER 16. VISUALIZATION AS FINE ART
terns and frequencies change in subtle ways as the shape of the vibrating membrane is altered. It is difficult to imagine a verbal description that could do justice to Chladni’s complicated patterns. The nodal patterns are very clear and each eigenmode is numerically labelled. However, the graph is incomplete as presented. In acoustics, the sound is the center of everything. The sound of a mode is its eigenfrequency, which is not given in the figure. It follows that this illustration needs to be accompanied by a caption or table which lists the frequencies or tones of each eigenfunction.
16.5
Darwin’s Flowers
Fig. 16.4 illustrates a major contribution of Charles Darwin’s which was unconnected with his more famous work on evolution. The mystery is that the common cowslip is a flower that occurs in two forms, one long-styled, and the other short-styled. (The “style” is part of a plant’s reproductive organ.) Darwin at first believed that the two physical forms were the male and female of the species. Later, he realized that actually both varieties were hermaphrodites, that is, possessed both male and female organs. One drawback of hermaphroditism is that it is easy for a plant to reproduce with itself, creating natural clones that defeat the whole purpose of sexual reproduction. Darwin showed that the peculiar geometry of these plants ensured that the long-styled variety could only be fertilized by a short-styled plant, and similarly a short-styled plant could only reproduce with a long-necked plant. The geometry prevented self-reproduction. The left figure shows what the discussion is all about: the cowswill has two forms. A photographic reproduction would hide the interior organs, so Darwin opts for a cutaway drawing to illustrate the all-important interior. The petals are extraneous to the discussion of sex organs. Still, it was not imprudent to include them because the petals remind a botanist which species is under discussion — a pictorial label at the top of the figure to reinforce the verbal label at the bottom. Also, the petals show the position of the styles, which are hidden from direct view, to the stem and petals that are directly visible. The right diagram is conceptual. It sums up in a single visual image the essence of Darwin’s theory about cowsill reproduction. Notice the profusion of labels. At the bottom, the long-styled and short-styled forms are labelled. But Darwin does not stop there; he labels each of the arrows, too. Lest we have any doubts, the direction of the arrows show how the pollen moves in reproduction — or tries to move — for what Darwin calls “illegitimate unions”. The only criticism is that “legitimate” and “illegitimate” are odd-sounding terms, reminiscent of lawyer-talk more than precise scientific lingo. “Impossible” and “possible” might have been better. Still, these are good figures, and remind us that Darwin was more than just the “Theory of Evolution” guy. But there is one final reason why these figures are good: they are excellent scientific visualizations because Darwin was an excellent scientist!
16.6
Hertzian’s Discovery of Electromagnetic Waves
Fig. 16.5 shows a milestone: the experimental verification of electromagnetic waves. Hertz could have made measurements only along one or two rays radiating away from two-ball antenna, and plotted the results as a line graph. However, he was trying to confirm James Clerk Maxwell’s theory, which made quite specific predicts about the
16.7. BYERLY (1893): INTEGRATING TEXT AND GRAPHICS
373
Figure 16.4: From Charles Darwin’s The Different Forms of Flowers(1862). The left figure shows the two forms of the cowslip, Primula veris. The right is a conceptual diagram: it illustrates Darwin’s thesis that the geometry prevents self-pollination, forcing the cowslip to always reproduce sexually. form of the wave. And so he made sufficient measurements to make a contour plot, which made his experiment much more convincing. Note that vertical axis running through the middle of the plot, carefully labelled. The units are not arbitrary metric or English units, but rather the tic marks are placed at integral or half-integral multiples of λ so the scale of the waves in measured in terms of physically relevant length scales. Maxwell’s theory predicts that the waves would be polarized. To what is otherwise a standard contour plot, Hertz added arrows to mark the directions of polarity. The graph is not flawless. Negative contours could be dashed or hachure lines added to distinguish between the troughs and peaks at a given time. The wave oscillates, of course, so that every portion of space has both positive and negative values. However, there are phase relationships such that one lobe is positive whenever the major feature on the other side of the antenna is negative and vice versa; Hertz has not attempted to indicate these, nor has he labelled any of the individual contours. Neverthess, the graph is sufficiently clear and detailed that the confirmation of Maxwell’s theory is plainly visible.
16.7 Byerly (1893): Integrating Text and Graphics Fig. 16.6 is an illustration from a treatise on Fourier series and spherical harmonics by Byerly which was first published in 1893. The graphical problem is that Gibbs’ Phenomenon occurs in a very narrow layer. Byerly therefore found it expedient to draw a graph with a very high aspect ratio to represent the narrowness of this layer of high error discovered by Gibbs. On a page by itself, the graph would look rather peculiar, surrounded by so much white space. The printer solved this problem by shifting the graph to the left and filling the rest with text. Unfortunately, it is rather difficult to imitate this 19th century piece of sound design with late 20th century computer technology. The usual LATEXstyle and class files, for example, force all figures to fill the entire width of the page. Some publishers, such as Kluwer, supply their own style files which allow captions to be set to the side of the figure, but not the main text. Allowing text to flow freely around the side of a figure is rather tricky although one can find user-contributed files on Web LATEXsites which purport to allow this.
374
CHAPTER 16. VISUALIZATION AS FINE ART
Figure 16.5: Heinrich Hertz’ discovery of electromagnetic waves. The two circles at the center are metal balls which radiate waves when a spark leaps between them. The curves are isolines of the electric field as measured by Hertz by repeating the experiment over and over and moving his detector to different parts of the room. The arrows denote the polarities of the waves.
16.8. THE DIFFERENCE BETWEEN TWO-DIMENSIONAL AND ONE-DIMENSIONAL WAVES375
Figure 16.6: Left: an illustration of Gibbs’ Phenomenon. Right: the text. Because the graph is very tall and narrow, the printer set it so as to fill the entire height of the page. Scientific visualization has not been monotonic progress from the old pre-computer days. Some tasks that were easy for old-fashioned metal type are difficult with modern technology.
16.8
The Difference Between Two-Dimensional and OneDimensional Waves
Fig. 16.7 is taken from a 1954 two-volume treatise of some 2000 pages by Philip Morse and Herman Feshbach, two physics professors who taught a legendary applied mathematics course at M. I. T., based on their text. Its goal is to illustrate the dimensioninduced differences between the solutions of the ordinary, nondispersive linear wave equation ∇2 u = utt
(16.1)
where ∇2 is the Laplace operator and the subscript t denotes time differentiation. In one space dimension, the wave front remains very sharp at all times. In two space dimensions, however, there is a ripply wake behind the rounded leading edge of the spreading wave disturbance. To translate this physics into pictures, Morse and Feshbach do several good things. First, the behavior of the wave equation in a given number of dimensions is illustrated by showing five snapshots of the solution. Each of the five graphs is consistently ordered (initial time at the top, time increasing downward) in a graph of identical format.
376
CHAPTER 16. VISUALIZATION AS FINE ART
Figure 16.7: Left side: mesh plots illustrating the outward radial spreading of solutions to the two-dimensional wave equation. Right side: the same but in one space dimension where the leading and trailing edges remain sharp and there is no oscillatory wake. Second, because the precise numerical values of the solution are irrelevant to the concept — for a linear equation, one can multiply the solution by an arbitrary constant without changing the shapes — the axes are not labelled. Third, the graph type is different for different dimensions. An ordinary line graph is employed in one space dimension, but a surface mesh plot is used in two dimensions. Lastly, because the wake is small and would be completely hidden in a standard mesh plot, Morse and Feshbach cut away one-quarter of the mesh. Even so, the graph is not completely successful. The problem is that the wake is so small compared to the leading edge that it is almost invisible in the cut-away mesh plot. A graph can hardly be a triumph if its most important graphical feature is invisible. This failure reminds us of another theme: good visualization is hard, even if you’re as clever and careful as Morse and Feshbach.
16.9
The Importance of Color Schemes
Pseudocolor images are simple in concept: fill each little square of the image with a color denoting the value of the plotted quantity in that square. Unfortunately, creating a really useful pseudocolor image is tricky because the human eye has only a limited
16.9. THE IMPORTANCE OF COLOR SCHEMES
377
Figure 16.8: Two pseudocolor or “image” plots of the same flow, a turbulent jet streaming into quiescent fluid. The top figure employs a standard color mapping in which values are associated with color through a linear relationship. The visualization is poor because most of the small scale features are invisible. Donna Cox, an arts professor who has been associated with the supercomputer center at the University of Illinois (NCSA) for many years, devised a nonlinear color mapping which makes an amazing variety of additional features visible.
378
CHAPTER 16. VISUALIZATION AS FINE ART
ability to distinguish fine shades of color. A little ingenuity in the color-coding scheme can greatly improve the result. Fig. 16.8 shows two images of the same turbulent jet. The top image is very bland and boring; one can identify the core of the jet and the surrounding quiescent fluid, but there is little detail. The bottom image, which employs a complicated, nonlinear color-coding, brings out a whole host of small details which are missing from the image at the top. Why are the two images so different? The answer is that most of the fine structure consists of variations in density of only a few percent of the mean density of the gas. In the color scheme at the top, these small variations translate into only slight, almost invisible variations of hue. The nonlinear color map has magnified these small variations so that these are easily visible. One issue is: Are such small variations important? Only the goals of the study, not graphic design per se, can provide an answer. For this investigation, the small features are indeed important. The nonlinear color mapping shows that the jet is flanked by lots of intersecting shock waves. Although small at the time shown, these are serious challenges to the numerical algorithm used to compute this jet flow. Furthermore, these small-scale features may be the seeds of much larger features that will develop from them as time increases. Invisibility of these features, while still small, implies that the early stages of this evolution from little-to-big are veiled from the modeller. Furthermore, the jet is turbulent. In the words of Lewis F. Richardson: “Big whirls have little whirls that feed and scratch and bite ’em, and little whirls have lesser whirls and so ad infinitum.” This parody of a couple of lines by Jonathan Swift is an apt description of a turbulent cascade; a turbulence modeller has to care about the role of the very small features as much as the very large because they are intimately connected. Although large scale features do form, new eddies of very small scale are constantly being born in turbulence, so that the coupling of disparate length scales continues throughout the entire life of the hydrodynamic turbulence. Fig. 16.9 is another example of the effectiveness of a nonlinear color map. The range of the plotted variable is split into ten pieces. Each of the ten parts of the interval was given its own color range, always ending in black. As a result, the pseudocolor image of the jet has ten contours of black plotted. In between, there are various shades of color. This makes it fairly easy to identify very fine features in this turbulent jet. This pseudocolor image could really be called a “color-filled contour plot”. However, the colors are not shaded, but are blended continously within each sector. Thus, the green sector shades smoothly from black to a very light green. This is less garish than using blocks of solid color.
16.9. THE IMPORTANCE OF COLOR SCHEMES
379
Figure 16.9: Pseudocolor image of a turbulent jet. The color-coding is shown in the colorbar. From an article by Long, Lyons and Lam, reprinted in Nielsen, Shriver and Rosenblum(1990)
380
16.10
CHAPTER 16. VISUALIZATION AS FINE ART
Repetition: Turbulence in the Sargasso Sea
In Fig. 16.10, the top plot is of temperature variability, dubbed “activity”, in the Sargasso Sea. A region of “high activity” region was targeted for transects by the oceanograhic research vessel. This region is delineated by the white contours that are superimposed on the lower three images. The point of the experiment is to understand the correlation between regions of high activity — probably patches of turbulence — and other physical variables. The white contours are very valuable to the reader because they make it much easier to identify the turbulent regions on the lower plots. The artifice of repeating a previous result on a later graph is often used with line graphs; this set of panels shows that the same can be done with pseudocolor plots. The same idea could be applied to a black-and-white contour plot by using a thick line for the repeated contours, for example. Matlab has a “hold on” command that allows the superposition of graphs, making it easy to combine a contour line from one figure with a contour plot of a completely different quantity. (One does have to use the Matlab “axis” command to be be sure that both figures use the same horizontal and vertical scales; “axis off” will suppress overprinting of the axis labels.) The artifice of combining multiple plots in a single figure is so common that most graphics libraries, like Matlab, provide subroutines to make this superposition easy.
16.10. REPETITION: TURBULENCE IN THE SARGASSO SEA
381
Figure 16.10: Oceanographic measurements in the Sargasso Sea as functions of depth and longitude, depicted by pseudocolor images. The panels show temperature variability, vertical temperature gradient, shear and Richardson number. The white contours which are superimposed on the lower three plots mark a region of high temperature variability (top image). Figure originally from an article by L. J. Rosenblum, reprinted in Nielson, Shriver & Rosenblum(1990), pg. 247
382
16.11
CHAPTER 16. VISUALIZATION AS FINE ART
Philander (1990): Equatorial Currents
The equatorial current system is complicated because it involves flow in all three dimensions coupled with both surface (North Equatorial Current, etc.) and subsurface (Equatorial Undercurrent) features. Fig. 16.11 is a very effective resolution of these difficulties. Currents are depicted in three different ways. First, the east-west surface horizontal currents are shown by thin, horizontal arrows with a smooth curve drawn through the tips of the arrows for greater clarity. The subsurface east-west currents are depicted by a combination of contour lines (“isotachs”, as lines of constant velocity are called) together with shading to distinguish eastward from westward flow. (Because the contour lines have to be crowded into a small space, shading is probably better than dashing negative contours for this application.) The “meridional” circulation, which to a geophysicist means the vertical and latitudinal velocities (closely connected by the physics), is marked by heavy solid arrows. To avoid obscuring the isotachs of east-west flow, the meridional arrows are marked on a different slice through the ocean. One enormous help to Philander is that velocities are approximately independent of longitude. Consequently, it is sufficient to show one cross-section at fixed longitude for the east-west flow and another for the meridional flow, and the reader can then apply those images to all cross-sections. Well, almost all. Near the coasts, the east-west flow has to turn towards or away from the equator. A few additional heavy arrows schematically denote this turning near the coasts. To orient the reader, the major continental land masses are delineated by thin curves on the surface and clearly labelled. To make it easier to distinguish land from water, thin vertical lines have been run downward along the sides of South America, but only for the land. A complex schematic illustrates why Matlab is not enough. A contour plot can be made through a blind process: after computing a two-dimensional array of values of a function, one can issue a one-line command and see contours appear on the screen. A schematic, however, has to be designed. The scientist has to make conscious decisions about what needs to be included and how to mix different graphical representations in a single diagram (contours, arrows-with-curve-at-tips, heavy solid arrows, shading, in this example) . Even once the design has been finalized, Matlab is inadequate. The schematic has to be drawn rather than computer-plotted.1
1 Of course, with sufficient ingenuity one can combine multiple Matlab routines to duplicate Philander’s diagram. This merely replaces individual brushstrokes with individual subroutines, and is legitimately labelled “drawing” rather than plotting, albeit drawing by computer rather than by the pen of a draftsman.
16.11. PHILANDER (1990): EQUATORIAL CURRENTS
383
Figure 16.11: A schematic diagram of the circulation in the tropical Pacific Ocean.
Chapter 17
Archetypes: D¨ urer’s Rhino and the Recycling of Images 17.1
Introduction: Aref’s Rule
Rule-of-Thumb 5 (Aref’s Rule) Never publish the same graph more than once. As we shall below, recycling images has been common practice for centuries. Hassan Aref, who is professor of mechanical engineering and chief scientist at the National Center for Supercomputing Applications at the University of Illinois, is clearly no fan of this practice. Why, then, has it continued? The first answer is that scientists are often lazy. The examples below show that often the price for this laziness is that errors in the original image are repeated over and over in its copies. Furthermore, the copies often degrade the accuracy of the original through a combination of poor reproduction, poor captions, and inappropriate, half-understood use of the image. The second answer is that it is silly to try to make a new graph when a visual masterpiece already exists, and says the same thing better. A brilliant visualization deserves to be reproduced. Aref’s Rule is sound advice that should only be followed sometimes. In this chapter, we shall to try illustrate when recycling of previously published images is good, and also when and how it can go disastrously wrong. We begin with a few important definitions. Definition 24 (Archetype: Dictionary) An original form, model or pattern; a prototype. From the Greek αρχι- “first” or “chief”, now used to mean “original” via τυπ τ ιν, “strike”, combined as αρχ τυπ oσ , “first-molded”. Definition 25 (Graphical Archetype) A graphical archetype is a picture which is widely copied, often with retouching or a change of medium, in later editions and publications. Graphical artists sometimes simply call it a “type” for short. Definition 26 (Graphical Lineage) A graphical archetype plus its copies.
17.2
Lineages
A culture of cancer cells, removed from a woman who died of ovarian cancer in 1953, became of great importance to cancer research. The reason is that these cells, called the 385
386
¨RER’S RHINO AND THE RECYCLING OF IMAGES CHAPTER 17. ARCHETYPES: DU
“HeLa lineage”, were unique in that they could flourish in the laboratory dish. (Ironically, most cancer cells, so virulent and unstoppable in the human body, perish rapidly without reproducing when transferred to a test-tube.) For thirty years, the HeLa lineage was distributed widely so that new cancer therapies could be tried upon it. Unfortunately, it was shown in the late 1980’s that the HeLa culture was the result of contamination and contained no cancer cells at all. Bibliographic lineages exist, too. Britz(1998) has amusingly documented the many citations of a 1950 paper on numerical analysis by O’Brien, Hyman and Kaplan. A year later, Leutert wrote a follow-up article and incorrectly listed the year of O’Brien et al. as 1951. Most later authors, apparently reading Leutert’s paper in lieu of the original, repeated his error. Britz showed that of 107 citations of O’Brien et al.(1950), 82 list the year incorrectly as 1951. Three papers incorrectly assigned Leutert’s paper to 1952. Graphical lineages also exist. The good news is: a really good visualization can have a life far beyond its original publication as it is reprinted again and again. The bad news is two-fold. First, errors and poor design decisions can be reproduced endlessly, too. Second, the availability of a reprintable graphic can stifle thinking. Recycling a previously-published diagram may be the easy way, but it may not be the best way.
17.3
Archetypes
An example will clarify the concept of a graphical archetype. Robert E. Lee, who was arguably the greatest general in American history, was photographed only twice before the start of the Civil War in which he became famous. His 1845 daguerrotype with his son Rooney was a private family picture which was never published until after Lee’s death in 1870. The other photograph, which was taken by Matthew Brady in the period 1850-1852, was used for a “carte de visite”. These were similar to modern business cards except that they were used primarily for social purposes (to be given to the maid or butler when making a social call) and they were printed with not only the name of the visitor, but also, after the development of photography, with a picture. Thus, a large number of people had copies of Lee’s “carte de visite”. When the Civil War began in 1861, this image was the only publicly available picture of Lee. As a result, this picture was copied and recopied. Fig. 17.1 shows the Brady original and ten copies. Some of the copies are steel engravings, others are wood engravings. In some, Lee faces to the right; in others, the image is reversed. Some show Lee in civilian clothes, as originally photographed, but many show him in military uniform. Some depict him from the waist up as he was photographed; others show only his face. Some are square-framed; others crop the image to fit in an oval. Yet the ten pictures are all just copies of a single archetype, the Brady photo. Some of the engravings are actually copies of a steel engraving by an artist named A. H. Ritchie so that these pictures are copies-of-a-copy. The irony with this oft-copied image is that it was a fraud. Not in the sense that the Brady photo was of someone other than Lee, but rather in the sense that Lee’s physical appearance had greatly changed from that depicted in all these images. At the start of the Civil War, he became too busy to shave, and grew the shaggy white beard that he wore for the remainder of his life. By 1861, his dark hair had also turned white. He never wore the dark-blue U. S. Army uniform after the start of the war, but only the grey coat of the Confederate States of America. One can hardly blame the long-dead artists for the defects of their pictures. Only one photograph of Lee was publicly available. As the most important military figure in America, newspapers and books about the war had to have his image, even a bad
17.3. ARCHETYPES
387
one. Unfortunately, this endless copying of an archetypical image — errors and all — happens in science and engineering, too, and with much less excuse.
Figure 17.1: Matthew Brady in 1850-1852, is the large picture in the upper left corner. Because this was used for Lee’s “carte de visite” [visiting card], most of Lee’s friends had a copy. This one picture became the basis for all ten of the other images seen here.
388
17.4
¨RER’S RHINO AND THE RECYCLING OF IMAGES CHAPTER 17. ARCHETYPES: DU
Graphical Lineages of the Renaissance
17.4.1 D¨ urer’s Rhino Albrecht D¨ urer (1471-1528) is one of the giants of world art. Like Leonardo da Vinci, he was an intensely curious man. Where Leonardo invented, D¨ urer observed. Although he became wealthy and famous for his engravings, his interest in biology was quite literally the death of him; journeying far from his native Nuremberg to see a stranded whale, he came down with a fever from which he never fully recovered. In 1515, he drew a rhinocerous. Unable to see the beast himself, he based his drawing on a sketch and a verbal description. It is remarkably accurate for a drawing-notfrom-life. However, it does contain an error: a small second horn set on the shoulder. His drawing was the archetype for a long graphical lineage. Indeed, Clarke (1986) is an entire volume of over 200 pages devoted to cataloguing all the plagiarisms of D¨ urer’s image. The copies of D¨ urer are easily recognized because they repeat his mistake of the phantom second horn. Fig. 17.2 shows both the original drawing and a copy-of-a-copy. The science essayist David Quammen in Boilerplate Rhino has partially rehabilitated D¨ urer: it is now thought that rhino observed by the artist’s friend was an unusual species, and D¨ urer’s drawing is actually more accurate than had been previously thought.
17.4. GRAPHICAL LINEAGES OF THE RENAISSANCE
389
Figure 17.2: Top: D¨ urer’s rhinoceros. He never saw the real animal, but based his diagram upon sketches and descriptions of eyewitnesses. Note that there is a small spurious second horn high on the back. Bottom: a copy of D¨ urer’s picture, published by Johnston (1657) which is copied from Gesner (1560).
390
¨RER’S RHINO AND THE RECYCLING OF IMAGES CHAPTER 17. ARCHETYPES: DU
17.4.2 Hooke’s Snowflakes Robert Hooke, the brilliant demonstrator for the Royal Society in the late 1600’s, was both plagiarist and plagiaree, graphically speaking. In his work on snowflakes, he accurately observed some images from nature, but apparently plagiarized other images from an earlier work by Thomas Bartholin (Fig. 17.3).
Bartholin(1661)
Hooke(1665)
Figure 17.3: Ford (1993, pg. 170) attributes three of the lower images, published in Robert Hooke’s Micrographia to plagiarism from Thomas Bartholin’s (1661) work, as indicated by the arrows. Top: a figure from Bartholin. Bottom: Hooke’s visual catalog of snowflake shapes.
17.4. GRAPHICAL LINEAGES OF THE RENAISSANCE
391
In spite of his unattributed “borrowing”, Hooke really was a superb observer. Like many of the great scientists of earlier centuries, he was a very gifted draftsman — “to draw is to understand”, one might say of the seventeenth century. His sketch of a mite was widely plagiarized by later authors (Fig. 17.4). No one gave a more accurate or detailed picture of a mite until the advent of microphotography.
Figure 17.4: Hookes original work was widely plagiarized. The left graph is superb picture of a mite, drawn by Hooke while looking through a simple microscope. The unattributed figure on the right is from Eleazar Albin’s Natural History of English Insects (1720).
392
¨RER’S RHINO AND THE RECYCLING OF IMAGES CHAPTER 17. ARCHETYPES: DU
17.4.3 The Isle of California A 1622 map of North America incorrectly depicted California as an island. This mistake was repeated 182 times, as late as 1745. One of these many erroneous repetitions is shown as Fig. 17.5.
Figure 17.5: This map of 1638 shows California as a giant island. In reality, the Gulf of California, although long and narrow as depicted, does not extend far enough to cut the peninsula now known as “Baja California” from the mainland. Joannes Janssonius, America Eptentrionales, (Amsterdam, 1638), copying a map of 1622.
´’S PEAR 17.5. POINCARE
17.5
393
Poincar´ e’s Pear
The shape of a rotating, self-gravitating mass of liquid has been the subject of active research for a couple of centuries. Not only is this the shape of stars, but also of solid bodies like the earth. Our planet is so large that if its shape deviated more than a fraction of a percent from that allowed to a same-sized mass of liquid, then gravity would crumble the mountains and make the stone flow as a very viscous fluid until the shape returned to the equilibrium shape. One remarkable fact is that as the rotation rate increases, the obvious shape, which is an ellipsoid of revolution, is no longer the only possible shape or even the stable shape. Instead, there is a branching or “bifurcation” in which a triaxial ellipsoidal with three unequal axes becomes the stable shape. At higher rotation rates, still more complex shapes are possible. One topic of intense interest: if the earth was born as a rapidly spinning mass, it might have become unstable and fissioned into the earth-moon system. The only way to test this hypothesis was to trace the different branches of equilibrium shapes. Bernard Riemann, Henri Poincar´ e and Sir George Darwin (son of Charles Darwin) were among the nineteenth century luminaries who pursued the figures-of-equilibrium problem. One advantage that scientists enjoyed a century ago was that instruction in drawing was an integral part of education. (In modern America, students receive “art” instruction at all levels from kindergarden through junior high school, but most receive no art instruction in high school.) For Henri Poincar´ e, the drawback was that to pass his school exams and continue to college, he had to gain a passing score in drawing as well as history, literature and mathematics. A person who can write or draw with both hands is usually called “ambidextrous”, meaning loosely “both-like-right-hand”. Poincar´ e could wield a pen with either hand, but it would perhaps be more accurate to label him as “ambisinistral”. He was totally incapable of producing a recognizable drawing with either hand. His school instructors passed him anyway, though he should have received a failing grade, because his other work was so brilliant. In 1885, Poincar´ e made one of his most influential discoveries: at a certain nondimensional rotation rate, the Jacobi triaxial ellipsoids bifurcated to a branch of unsymmetrical figures Unfortunately, Poincar´ e translated his formulas into a cross-sectional drawing (Fig. 17.6). His illustration bulged unsymmetrically like a pear, so his new branch became known as “Poincar´ e’s pear-shaped figure of equilibrium”. This caught the astrophysical imagination so much that a new term was coined for this family of shapes: “piriform”, which means “pear-shaped” in Latin. Poincar´ e showed that more complicated shapes would bifurcate at other parameter values. He conjectured, “that the bifurcation of the pear-shaped body leads onward stably and continuously to a planet attended by a satellite, the bifurcation into the fourth zonal harmonic probably leads unstably to a planet with a satellite on each side, that into the fifth harmonics to a planet with two satellites on one and one on the other and so on”. Sir George Darwin went on to conjecture himself that the pear-shaped figure eventually fissioned into two at a sufficiently high rotation rate, thus generating double stars and the Earth-Moon double planet. Chandrasekhar (1969) takes up the story: “The grand mental panorama that was thus created was so intoxicating that those who followed Poincar´ e were not to recover from its pursuit. In any event, Darwin, Liapounoff, and Jeans spent years of effort towards the substantiation of these conjectures; and so single-minded was the pursuit1 1 For
example, the question of whether along the Dedekind sequence a neutral point occurs similar to
394
¨RER’S RHINO AND THE RECYCLING OF IMAGES CHAPTER 17. ARCHETYPES: DU
that one did not even linger to investigate the stability of the Maclaurin spheroids and the Jacobi ellipsoids from a direct analysis of normal modes. Finally, in 1924 Cartan established that the Jacobi ellipsoid becomes unstable at its first point of bifurcation ... And at this point the subject went quietly into a coma.” (pgs. 11-12). One moral of this story: don’t become intoxicated with your own cleverness. Good graphics cannot redeem bad thinking. In this case, however, bad graphics seem to have contributed to the intoxication. Although Poincar´ e’s image was likely engraved by a professional artist, the engraver worked from a preliminary sketch by Poincar´ e, yes, the same ambisinistral lad who nearly flunked out of school because he couldn’t draw. Sir George Darwin redrew the piriform figures twenty years later (Fig. 17.7). As he dryly remarked, “Comparison with M. Poincar´ e’s sketch shows that the figure is considerably longer than he supposed.” Why did the error matter? Poincar´ e’s crime of visualization greatly exaggerated the bulge, and therefore implied that the piriform shape was much closer to fission than it actually was. The bad graph helped to fuel the delusion of double star and double planet theories.
the one along the congruent Jacobian sequence does not appear to have been considered or even raised.
´’S PEAR 17.5. POINCARE
395
Figure 17.6: Dashed curve: Jacobi ellipsoid. Solid/dotted curve: cross-section through the pear-shaped figure of equilibrium as drawn by Poincar´ e, “Figures d’Equilibre”, pg. 161, and reproduced in Lyttleton (1953), pg. 110.
Figure 17.7: Solid curves: the Jacobian triaxial ellipsoid at the bifurcation as seen in three different cross-sections, each through two of the three axes of the ellipsoid. Dotted curve: the pear-shaped figure that is also a figure of equilibrium at this set of parameter values. From Sir G. Darwin, Scientific Papers, vol. III, pg. 314.
396
17.6
¨RER’S RHINO AND THE RECYCLING OF IMAGES CHAPTER 17. ARCHETYPES: DU
Equatorial Waves
In the oceanic phenomenon known as El Nino and the atmospheric phenomenon known as the Southern Oscillation, which are a coupled air-sea quasi-periodic motion known as “ENSO”, so-called “equatorial waves” play a special role. These are planetary scale waves which are confined to low latitudes because of the refractive effects of the earth’s rotation. They occur in both the atmosphere and the ocean and were discovered in the early 1960’s. The earliest meteorological paper to give a general classification scheme with analytical solutions for these waves was by Taroh Matsuno in 1965. This discovery was so important that it is being honored with a special conference in Honolulu to celebrate the 1/3 of a century anniversary of his work! One of the reasons that Matsuno’s paper had a great impact was that it contained good diagrams — so good that some of them have been recycled almost as endlessly as the Matthew Brady carte de visite of Robert E. Lee.
17.6.1 Horizontal Plane
Figure 17.8: Horizontal velocity (arrows) and pressure (contours) for the equatoriallytrapped Yanai wave. This image was first published by T. Matsuno in 1966. It appeared again in a review by J. M. Wallace in 1973, in J. R. Holton’s 1975 monograph on the middle atmosphere, in the later middle atmosphere book by Andrews, Leovy and Leovy (1987), in all three editions of Holton’s Introduction to Dynamic Meteorology and in the second edition of Pedlosky’s Geophysical Fluid Dynamics.
17.6. EQUATORIAL WAVES
397
Adrian Gill’s Atmosphere/Ocean Dynamics is the only book or review in the last thirty years that has discussed equatorial waves but not recycled Matsuno’s diagram. This is a very good book in part because Gill resisting the temptation to copy blindly. He not only drew his own schematic for the Kelvin and mixed-Rossby gravity waves (Fig. 17.9), but also provides many novel analyses and illustrations which have no counterparts in other texts on geophysical fluid dynamics.
Figure 17.9: Resisting an archetype. Adrian Gill’s Atmosphere-Ocean Dynamics did not recycle Matsuno’s schematic diagram, but instead evaluated the analytical solution to make his own diagram. Left: Kelvin wave. Right: Yanai wave.
398
¨RER’S RHINO AND THE RECYCLING OF IMAGES CHAPTER 17. ARCHETYPES: DU
17.6.2 Vertical Cross-Section “A good scientist is one who knows enough to steal from the best people.” — James R. Holton Another archetype for equatorial waves is the vertical cross-section for each wave species. These simultaneously show pressure, temperature and all three velocity components through a mixture of shading, arrows, word-labels, and out-of-the-plane head/tail arrows. Because this diagram is complicated, and would require a considerable investment to duplicate, this figure has been recycled numerous times. Once again, Adrian Gill was the exception, preferring to draw his own figure. Unfortunately, his illustration is not as complete as the archetype. There are two conflicting precepts. One is that it is good to be original instead of slavishly copying prior visualizations. The other is that if a graph is really good, with carefully organized complexity, it may be very difficult to improve upon it, or even to do as well. The wise visualizer is pragmatic: sometimes a plagiarist, sometimes an innovator.
17.6. EQUATORIAL WAVES
399
Figure 17.10: A vertical cross-section through a Yanai wave. The labels “High” and “Low” mark the lines of maximum and minimum pressure. The arrows show the direction of the eastward and vertical velocities. The disks-with-central dot and the diskswith-x’s mark the nose and tail of arrows indicating the north-south velocity, which is out of or into the plane of the paper. (The vertical scale has been greatly exaggerated; in the real world, the horizontal scale is a couple of orders of magnitude larger than the vertical scale.) This diagram has appeared in Holton’s Introduction to Dynamic Meteorology and a wide variety of other sources.
400
¨RER’S RHINO AND THE RECYCLING OF IMAGES CHAPTER 17. ARCHETYPES: DU
Figure 17.11: Resisting an archetype. Adrian Gill’s Atmosphere-Ocean Dynamics did not copy the vertical cross-section diagram of Holton’s book, but drew his own.
17.7. A GOOD ARCHETYPE
17.7
401
A Good Archetype
The drawing below was originally made for the undergraduate textbook by Wallace and Hobbs(1977). It was reprinted in Holton (1992). This was probably a prudent decision. First, in accord with the quote from Holton given earlier, the diagram “steals from the best people”: J. M. Wallace has also been elected to the National Academy of Sciences and P. Hobbs is a very distinguished cloud physicist. Second, the diagram is a schematic, a conceptualization. It would be very difficult to reproduce this with graphing software; it needs to be drawn (or redrawn) by a professional artist using an illustration program. Third, the diagram is graphically intricate. Four different vertical levels are stacked in perspective. The bottom layer schematically shows the contients and oceans. The second and fourth layers are superimposed contour and quiver plots showing the horizontal flow and pressure. The third layer is a series of columns with arrows and labels “hot” and “cold” to depict the vertical circulation and the temperature of the air being carried up and down. One suspects that Wallace and Hobbs labored over their preliminary sketches to get it just right, and the professional artist labored too to combine all these elements into a clear illustration. Fourth, the diagram illustrates an important phenomenon in a clear way. To put it another way, if you recycle, reprint only the good stuff. ,
Figure 17.12: Summer monsoon circulation. First published in Wallace and Hobbs (1977); reprinted in the third edition of Holton (1992), pg. 379.
Chapter 18
Three Dimensions 18.1
Three-Dimensional Drawing
Three-dimensional illustration programs are rather like their two-dimensional counterparts except that the range of tools and options is necessarily broader. A low-end program like Dimensions employs a limited suite of strategies: 1. Fixed suite of “primitives”: cubes, spheres, cones, ellipsoids 2. Extrusion of 2D shape perpendicular to the drawing plane 3. Rotation of 2D shape about an axis 4. Bevel library Ray Dream Studio offers a wider range of options: 1. “Primitives”: (i) cubes, spheres, cones, ellipsoids (ii) exotics such as Fog, Fountain and Fire (iii) formula-objects [user-entered mathematical formula in terms of parameters p1 , ..., p4 , which are then controlled by sliders to allow one to rapidly adjust the shape. 2. Free form modeller: extrusion and rotation of 2D shapes 3. Editable extrusion curves 4. Scaled extrusion: a cylinder that is wide at one end and narrow at the other , for example. 5. Morphing between cross-sections so that an extruded object may have a circular cross-section at one end and a square or elliptical cross-section at another 6. Mesh modeller: network of vertices connected by segments The “primitives” are the shapes that can be drawn by clicking on a tool. Matlab is a powerful alternative to drawing programs because Matlab can draw “primitives” that are defined by very complicated mathematical expressions. Raydream Studio’s “formula” primitives are an acknowledgment of the need for user-defined tools. The bad news is that the expression-parser in Studio is rather simple, and cannot for example deal with Bessel functions or anything more exotic. However, the parser does recognize p1 , . . . , p4 as parameters to the curves, which must otherwise be expressed as polynomials, trigonemetric functions, exponentials or algebraic 403
404
CHAPTER 18. THREE DIMENSIONS
functions in the Cartesian coordinates (x, y, z). One can then vary these parameters by moving sliders to see how the shape changes when these parameters are varied. For complicated objects that arise in a scientific project, Studio can be combined with Matlab or Mpale. After a complicated shape has been computed in Matlab or Maple or Mathematica, one can do a polynomial curve-fit or the like to obtain a formula that can be used to recreate the shape in Studio as a “formula primitive”. Studio also supports some rather exotic primitives such as “Fog”, “Fire” and “Fountain”. These are not terribly useful in science, but are reminders that the simple primitives of most illustration programs are inadequate to create any but the simplest shapes. Illustrator allows the creation of exotic objects through clip art libraries. A skilled artist can draw three-dimensional shapes in a two-dimensional program like Illustrator. One can, for example, create a template of isometric lines to make it easier to draw shapes in perspective, then import the grid pattern into an illustration as a separate layer, and finally discard the layer from the final drawing. However, three-dimensional drawing programs rather strongly discourage this sort of direct three-dimensional drawing. The reason is that to be able to rotate, scale and manipulate a shape in three dimensions as a vector graphics object, the program must know the three-dimensional location of each vertex of a polygon (or whatever). An Illustrator drawing of a cube-in-perspective may look fine to the eye, but the program knows only how the figure projects onto the two-dimensional screen surface, not its true three-dimensional shape. Instead, tactic is draw a two-dimensional shape which is then “lifted” into three dimensions by extrusion and/or rotation. The word “extrusion” is borrowed from manufacturing where objects are often fashioned by forcing a viscous liquid through a die that forces the object to have the cross-sectional shape of the die when it hardens. One can also “extrude” by cutting many identical copies of a two-dimensional shape out of paper or cardboard; when the copies are stacked and glued together, the result is an object of finite thickness with the cross-section of the two-dimensional sheets from whence it came (Fig. 18.1. “Rotation” is called “lathing” in Studio. Whatever the name, a solid-of-revolution can be made by rotating a two-dimensional cross-section about an axis. Such solids are
Extrude
Figure 18.1: Left: two-dimensional shape. Right: the three-dimensional shape created by extruding the two-dimensional shape. The extruded figure can then be appropriately shaded or covered with a texture map.
18.1. THREE-DIMENSIONAL DRAWING
405
manufactured by putting a block of wood on a lathe where the block is turned rapidly at high speed, and then pressing a metal chisel into the wood as it rotates. Intricate patterns can be cut by pressing the chisel different depths at different points along the shaft of the lathe, but the result is always axisymmetric in cylindrical coordinates (Fig. 18.2). Extrusion and lathing are rather limited ways to make three-dimensional figures, so additional strategies are needed. A “bevel” in carpentry is a rounding off of a sharp corner. Dimensions employs a whole library of bevel shapes so that the corners of extruded objects can be rounded in different patterns. Studio allows very complicated extrusion or “sweep” paths. One can, for example, specify that the cross-section will shrink as the extrusion proceeds so as to obtain a cylinder which is wide at one end and narrow at the other. One can specify smooth variations between different beginning and ending cross-sections so that a shape can “morph” between a circle and a square. The axis of the area swept by the cross-section can be drawn on the sides of the three-dimensional grid box to inform the program that the sweep path should twist, zigzag or spiral. Such complicated extrusion paths would be almost impossible with a physical die-and-plastic, but are easy in the computer. The other option is draw vertices directly in three dimensions — in such a way that the computer knows the true three-dimensional location of each point — and then connect the vertices by lines to make polygons. The magic is that one must specify a “drawing plane” when moving the mouse to specify a new vertex. By moving the mouse a certain distance along one drawing plane, changing the plane, and moving again, one can reach any point in (x, y, z) space. Because the move is split into two steps, rather than a single move as in drawing isometrically in two dimensions, the program knows the three-dimensional location of the vertex. The Mesh Modeller in Studio is a vertex-based method for creating three-dimensional objects. Of course, drawing each vertex for a complicated object is very tiring and boring, so Mesh Modeller allows one to begin with primitives (such as cubes, spheres,
Rotate
Figure 18.2: Left: two-dimensional shape. Right: the three-dimensional shape created by rotating the two-dimensional shape about the vertical axis indicated by the dashed line.
406
CHAPTER 18. THREE DIMENSIONS
etc.), fuse different shapes together, and apply the extrusion and lathing concepts. The “Loft” command stretches shapes between two existing polygons to make a new, united complex surface. Drawing programs are much better than Matlab at aligning, rotating, scaling, and shading 3D objects. They are much inferior to Matlab at creating objects which are the outcome of a complicated scientific algorithm or numerical experiment. As in two dimensions, drawing and scientific graphics software are complementary with partially overlapping but also partially distinct regions of usefulness.
18.2
Three-Dimensional Plots
18.2.1 Isosurfaces The three-dimensional generalization of a contour plot is an isosurface graph, that is, a visualization of a two-dimensional surface in a three-dimensional space where q(x, y, z) = q0 where q0 is a constant. Matlab’s isosurface command will generate such plots, and most high-end scientific graphics packages can do the same. An ordinary contour plot is viewed from above so that many isolines can be seen simultaneously in the x − y plane. Unfortunately, the only way to see the entire x − y − z volume, and thus see a lot of nested isosurfaces, would be to view the plot from the four dimension. Consequently, it is usually possible to view only a single isosurface at a time, which is very annoying. Possible remedies include: 1. Multi-panel graph, each showing the isosurface for a different level q0 2. Slide show animation, such as a Quicktime image sequence, allowing the viewer to switch rapidly between different isosurfaces so as to “fly in” to an object. 3. Cutaway of one isosurface to reveal part of another. 4. Transparency. Another difficulty is that a given view reveals only one face of the isosurface while the other is hidden like the Dark Side of the Moon. Again, a two-panel graph, showing front and back, or a Quicktime or VRML movie that allows one to rotate around the isosurface at the click of a slider, can help.
18.2.2 Isocaps If an isosurface is, for example, an infinitely long cylinder, then the surface will be clipped by the edges of the viewing box. The isosurface then appears hollow with holes at the two caps where the surface touches the edge of the viewing box. Table 18.1: Three-Dimensional Equivalents of Two-Dimensional Plots 2D plot contour (isoline) pseudocolor quiver
3D equivalent isosurface, isosurface with caps contour slices mini-cubes [pseudocolor] slices coneplot
18.2. THREE-DIMENSIONAL PLOTS
407
These holes are rather distracting, and furthermore represent areas of non-information. It is therefore common to fill the holes or “isosurface caps” with contour plots or pseudocolor plots of the same quantity where these flat, two-dimensional graphs are parallel to the edges of the viewing box, and thus plug the holes completely.
These “isocap” plots do give an indication of interior isosurfaces, and therefore add information to the isosurface itself. Furthermore, the eye seems a closed volume, bounded at the ends by the isocaps, rather than a hollow surface, which tends to draw the eye out of the viewing box. Matlab has an isocaps command which adds caps to isosurfaces in a single line.
Figure 18.3: A cylindrical isosurface (red) with pseudocolor caps. The isosurface is q = 1/4 where q = exp(−x 2 − y 2 ).
408
CHAPTER 18. THREE DIMENSIONS
18.2.3 Glyphs, Arrows and Cones To go beyond isosurfaces, one needs to make use of glyphs, which are little icons whose shapes, size and/or color conveys additional information about the fields at the location of the glyph. The most familiar glyph is the arrow which is used in an ordinary twodimensional vector or quiver plot. The length of the arrow is magnitude of the vector while the orientation of the arrow indicates the direction of the vector field. Unfortunately, three-dimensional arrow plots, though an option quiver3 in Matlab, are not very effective. The problem is that an arrow is a two-dimensional shape, and it is difficult to perceive the three-dimensionality from a sea of arrows, even with a surrouding three-dimensional grid box to provide perceptual clues. It is therefore common to replace the arrow glyphs by cones. Matlab 6 has a coneplot option. It seems to be easier to visually decode the vector field from the pattern of cones, which are three-dimensional shapes, than from arrows. Hydrodynamicists have been especially clever in drawing more elaborate glyphs to simultaneously convey vector and scalar information. A simple instance is to use color on a code to visualize the pressure. However, much more elaborate glyph-schemes have been developed. Matlab allows a lot of creativity because one has a subroutine to draw a certain glyph in a unit box, one can then call this function from a glyph-plotting function that will lay down many copies of the glyph, each with the orientation, shape, color and size appropriate to that point in 3D space. The difficulty is that novel glyphs force the viewer to learn a new visual code or paradigm. This means that elaborate glyphs will only succeed in conveying useful information to viewers who are strongly motivated, and will to invest a lot of time learning the new visual metaphor.
18.2.4 Mini-cubes The direct analogue of a pseudocolor plot would be to color each volume (or “voxel”, in computer graphics jargon) with a color appropriate to q(x, y, z). Unfortunately, in the absence of transparency, only the colors of the outer wall would be visible. One remedy is to render a lot of non-continguous small cubes in color instead. If the gaps between the cubes are sufficiently large and the cube is shown in the proper perspective, one can get a feeling for how q(x, y, z) varies over the whole volume. Since the cubes must be rather small to allow sufficient viewing channels into the interior, this type of graph is called a “mini-cubes” plot.
18.2.5 Slices Another variation is to visualize three-dimensions through a stack of oriented, flat twodimensional slices, spaced so that one can view each member of the stack. Matlab uses the terminology of “slice” plots, but some others prefer “cut-planes”. Matlab allows the slices to have an arbitrary orientation; the cuts need not parallel a pair of coordinate axes. Matlab offers two routines, contourslice and slice. The former does what the name implies: it draws a fairly standard Matlab contour plot on the slice plane. The unusual feature is that the output of contourslice is a fully threedimensional object, so it can be rotated and viewed at an angle. (In this respect, it is really a contour3 plot computed along the slice plane.) The slice routine is really a pseudocolor plot of the function on the slice plane.
18.3. TOPOLOGY
409
Figure 18.4: A cone plot of a three-dimensional wind field.
18.3
Topology
In a fluid flow, certain “critical points” have place-of-honor. These include stagnation points, where the flow is zero, and the centers of vortices. Other linear features, such as the streamline between fields of two vortices and shocks or fronts, are important, too. One strategy for wrestling with three dimensions is to plot only these topologically-crucial points, curves, and surfaces rather than attempting to visualize the entire surface.
410
CHAPTER 18. THREE DIMENSIONS
20
15
10
5
0 20 15
20 15
10 10 5
5 0
0
Figure 18.5: A slice plot of the function q(x, y, z) = exp(−x 2 − y 2 − z2 ).
434
Glossary
GLOSSARY ADDITIVE COLORS: Red, green and blue (RGB), the three primary colors employed by computer and television monitors. ALIASING: In graphics, the approximation of a smooth curve by a flight of stairs where the steps are all one pixel high. Vertical and horizontal lines are never aliased, but diagonal lines must be. Also known as STAIRCASING and the JAGGIES. ALPHA CHANNEL: An eight-bit channel, supported by many hardware and software systems, which is used for masking, transparency and other modifications of a graph. AMBIENT LIGHT: Non-directional illumination that surrounds an object. In the real world, this is light that scatters off the walls and then bounces off the object to the eye. ANALOG (VIDEO): Videotapes (and TV) in which the record or displayed signal is simply the strength of the signal detected by the camera. This is opposed to DIGITAL VIDEO, in which the camera signal is converted to numbers. ANIMATION: A sequence of images which is intended to be played at many frames per second to create the illusion of continuous motion. ANTIALIASING: A jagged line is “antialiased” by filling in some of the stairsteps with a lighter shade of the color of the curve; the grey padding of a black line, for example, makes the curve look smoother. ARTIFACT: Visual errors or problems. BITMAP GRAPHICS: In this representation of an image, the color for each pixel is specified. This term is sometimes restricted to images in which each pixel is either black or white so that only a single bit is needed for each pixel. BIT BLT: See BLITTING. BLACK LETTER : Ornate typeface of the kind used in the Gutenberg Bible, and continuing in Germany until the 1930’s. Also called “Textura”, “Old English”, “SpireGothic”, “Gothic” or “Fraktur”. Used in science primarily for “symbol overloading” to distinguish a symbol indicated by a from the Roman a. BLITTING: Abbreviation for “bit block transfer”. A raster operation that moves data from the FRAME BUFFER to the screen or from one part of the FRAME BUFFER to another. BUMP MAPPING: Superposition of an imbossed pattern, created on a plane surface, onto a curved surface in three-dimensional space. CAMERA-READY COPY: Text and illustrations which can be printed by photolithography without the need for typesetting or paste-up by the publisher. CAPTION: Text that explains a figure and is set directly underneath it. CHARTJUNK: Unnecessary elements of a graph, such as baroque frames, redundant labels, heavy grid lines, and other non-data figurations, which clutter a graph without increasing the information it presents. (Neologism of Edward Tufte.)
Glossary
435
CLIPPING: This is the non-display (and often the non-computation) of parts of a data curve or other graphic object that extend beyond the frame of the graph or the field of view. CLIP: Movie jargon for a short section of an animation, typically containing one scene or a portion of a scene; a clip is a portion of the film bounded by two “cuts” where the viewpoint shifts to a different camera, viewing angle, etc. CLOSED SYMBOL: A symbol, such as a circle, triangle or square, which is filled with solid color. CMYK: Cyan-Magenta-Yellow-Black, the basic SUBTRACTIVE COLORS used in printing. CODEC: A protocol for compressing and then decompressing video files. Codecs are extremely important because all but the shortest video files require so much storage in uncompressed form as to be unmanageable; in addition, uncompressed files require too much processing to permit real-time display on older workstations. Video editors support several protocols each, which may be implemented either in software or on special hardware video cards inserted into the computer. COLORMAP: An N x 3 array in which each row stores the red, green and blue intensities of a color; the row number is an index to that color. COMPOSITE GRAPH: A single figure which is formed from several individual graphs, arranged side-by-side, one atop the other, or in a checkerboard or more elaborate pattern. Synonym: MULTIPANEL GRAPH. COMPOSITOR: One who sets type. Synonyms are TYPESETTER and KEYBOARDER. CROPPING: Cutting down a photograph or other image so to eliminate nonessential parts. Scanning software usually has the ability to crop an image to save computer storage. CURTAIN: A set of vertical lines from the surface of mesh plot to a reference plane; this sometimes make the shape of the plotted surface easier to visualize. DATA-INK: The non-erasable core of a graphic. data-ink DATA-INK RATIO: totalinkusedtopr intthegr aphic . or equivalently, the proportion of a graphic’s ink devoted to the non-redundant display of data-information, or equivalently, 1.0 - proportion of a graphic that can be erased without loss of datainformation. DATA-MINING: The process of digging understanding and essential information from a large data-base, such as the archives of a general circulation model of the atmosphere. DEPTH-CUEING: This is a systematic reduction in the color intensity or gray intensity of objects with increasing distance from the eye. This cues the viewer that paler objects are farther away, mimicing the effects of haze, etc. DESIGN VARIATION: Changes in the scale or other key elements of a graph or a series of graphs which create the spurious appearance of rises or falls in the data. DIGITAL (VIDEO): TV/video in which the input from the camera is converted immediately to numbers so that numbers, rather than undigitized pixel intensities, are recorded onto tape.
436
Glossary
DINGBATS: Small icons or pictorgraphs (letters, tiny boats or houses, crosses, stars, stop signs, etc.). Often organized into special dingbat fonts. Useful as clip art and stamps in scientific illustrations. Examples of dingbat fonts include Zapf Dingbats, Webdings, Wingdings, etc. Also called ORNAMENTS. DIRECTIONAL LIGHT SOURCE: Light emanating from a localized source, usually idealized as a point source infinitely far away so that all rays from the source are parallel. Often shorted to LIGHT SOURCE. DITHERING: In indexed color, where the index can identify only 256 shades of out of millions that the monitor is capable of displaying, appearance can be improved by ordering the hardware to average between these shades (“dither”) so as to reduce abrupt transitions in color. DOUBLE BUFFERING: A hardware trick for improving the speed and smoothness of animations. The contents of one part of the FRAME BUFFER are displayed onscreen while data is written to another section (“buffer”) of the FRAME BUFFER; the roles of the two buffers are reversed when the update is completed. Speed is increased because two different data transfers are happening simultaneously instead of sequentially: CPU/memory-to-buffer, buffer-to-screen. DOT GAIN: The amount by which a dot of printer’s ink will spread after being deposited on the page. This is a major complication in printing grayscale images because the halftone dots that make up the image are each a little wider on the printer page than specified by the software. DUB: Movie jargon for “copy”. When an audio track is added in the studio to a video track which has been photographed on location, the audio track is said to be “dubbed” into the movie. When a computer animation is copied onto a VHS videotape, the result is a “VHS dub”. DUCK, GRAPHICAL: A graphical atrocity, the moral equivalent of the convenience store in the shape of a duck. A neologism of Edward Tufte. DUOTONE: The printing of a grayscale image by using inks of two different colors, such as black and light gray, or black and light red. The reason is that offset lithography can only reproduce about 50 shades of gray using a single color of ink. To obtain finer shadings of gray in a photograph, designers therefore use DUOTONES and sometimes even TRITONES (three inks) and QUADTONES (four inks) to reproduce grayscale photographs at high resolution. [DYNAMIC RANGE:] The ratio of the largest intensity to the smallest intensity which can be detected by a scanner, photographic film, CCD or other image detector. EIGHT-BIT COLOR: Synonym for INDEXED COLOR, which normally uses an 8-bit number as the color index. ENCAPSULATED POSTSCRIPT (EPS): An image format which consists of two parts: a preview, which is a screen image for a particular class of computers, and a printer file, which is computed of Postscript vector graphics instructions. The Postscript language can also render bitmap images, albeit at the cost of a very large number of vector instructions, so EPS files may made from bitmap images. On a Macintosh, the preview is PICT, the default file class for Matlab images. On a Windows machine, a Macintosh EPS will display only a blank image, but will print correctly.
Glossary
437
FLAT SHADING: When a surface is approximated as a union of polygons, each polygon is the colored uniformly over its entire face so that the color changes only at edges where polygons meet. Also called FACETED SHADING. FLATTEN: In software that supports layers, FLATTENING refers to the combining of all the layers into a single layer. This is necessary, for example, to export a file from Photoshop or Illustrator, which both support layers, to the Encapsulated Postscript (EPS) format, which does not allow layers. FLIPBOOK: A collection of sketches, each differing slightly from its immediate neighbors, which create the illusion of continuous motion when the pages are rapidly riffled. Cartoon animators draw sketches on punched paper so that they can slip them onto binder posts and then flip the sketches to check the effectiveness of the drawings as animation. For static visualization, it is often useful to combine a set of flipbook-style illustrates into a single, multipanel composite figure. FONT: A complete assortment of letters, numbers and punctuation marks of one style and size. Fonts are usually specified by giving the font family name, point-size and style, as in Adobe Garamond 12-point Semi-Italic. FRAME BUFFER: Display memory that stores a full frame (or more) of picture data. The number of bits-per-pixel determines the range of colors and graphical tricks that can be performed. GAMMA CORRECTION: This a look-up table which is used to connect the desired, perceived brightness of a pixel to the strength of the electric signal fed to the Cathode Ray Tube. The reason that “gamma correction” is necessary is that the response of the screen phospors to electricity (and also the response of the human visual system to light) are both nonlinear. GOURAUD SHADING: A scheme in which the color of a polygon is not constant across the polygon, but rather is determined by interpolation from the vertices where the surface normals are computed. (Better but more expensive than FLAT (“FACETED”) shading but cheaper and not as good as PHONG shading.) GRAPHOS: Silly mistakes on a graph, analogous to typographical errors in text, such as mislabeling a curve or axis. GRAYSCALE: This is an image which uses only a single color (usually black), but in varying intensities. Grayscale is usually approximated by dividing the images into many small blocks and printing various numbers of black dots in each block. Both book and newspaper printers and also laser printers are not able to print in various shades of gray directly. GUI: Short for Graphical User Interface. This is a software package that allows the computer user to issue commands by clicking buttons, sliders and menus instead of typing in commands. INDEXED COLOR: A scheme in which an image is represented by storing 8-bit numbers that are indices into a palette of 256 colors. This is more economical of storage than TRUE-COLOR in which 24 bits are stored for each pixel. JAGGIES: See ALIASING.
438
Glossary
KEY: A “high-KEY” image is one which is composed mostly of light tones (“snow image”); a “low-key” or “night” image is one composed primarily of dark greys and black. KEYFRAME: In animation, a frame that is drawn or compressed very accurately; frames between keyframes are drawn by interpolating or “tweening” between the keyframes. (Used both in animation/drawing and also in video compression/decompression.) LAYER: Many drawing and image-processing programs such as Photoshop and Illustrator allow a single figure to be split into logically distinct layers. This makes it easy to edit the background (in a “background” layer) without accidentally altering other parts of the figure. LEGEND: A set of lines and symbols with labels which gives the relationship between a given line/marker style and the name of the quantity which is plotted using that line or marker style. The legend is often enclosed in a frame (“LEGEND BOX”) to set it off from the rest of the graph. Deprecated in favor of direct labelling of curves whenever possible. (Occasionally, this term is used as a synonym for CAPTION although this usage seems to be fading.) LIGHT SOURCE: See DIRECTIONAL LIGHT SOURCE. LINE ART: This is a graphic artist’s term for images which are drawn entirely in black lines, dashes, and curves of a single color (usually black!) and a single intensity (the darkest black the printer and screen can render). Woodcuts and copperplate engravings are line art. LINE STYLE: Solid, dashed, dotted and dot-dashed are the usual line styles. The term may also be applied to distinguishing lines by width, as in thin lines and thick lines. LOOKUP TABLE: See COLORMAP. LPI: Lines-Per-Inch, the resolution of the halftone screens used to print images in offset printing. (Laser printers, in contrast, lay down individual dots and usually described by dpi, Dots-Per-Inch.) [MATTE:] Adjective meaning “of dull luster”, “without finish”. More technically, an object has a “matte” finish if its light is reflected diffusely (Lambertian reflection) as opposed to specular or “mirror-like” reflection. MOIR´ E PATTERN: Having a wave-like pattern, as on silk or metal. Such wave-like patterns can be formed on silk by “watering” it, which is a treatment that uses water and pressure to produce the pattern. Such patterns also form naturally or artificially on metal, such as the Damascus steel finish of fine sword blades made in the city of Damascus. MOIR´ E VIBRATION: Areas shaded by dark, diagonal lines or wavy lines or other patterns that are distracting to the eye. Neologism of Edward Tufte. MORPHING: Blending one shape into another, very different shape by interpolating between the two extremes and showing all the intermediates. Almost a synonym for TWEENING except that the keyframes in the latter are usually separated only by a fraction of a second of playing time.
Glossary
439
MULTIPANEL GRAPH: A single figure which is formed from several individual graphs, arranged side-by-side, one atop the other, or in a checkerboard or more elaborate pattern. Synonym: COMPOSITE GRAPH. NOMOGRAM: Literally, a graph that embodies a law. From the Greek νoµos, “law”, ´ “something drawn or written”. Such diagrams are often designed and −γρ αµµα, to be graphical calculators. NORMAL (VECTOR): A vector which is perpendicular to a surface at a given point; identical with SURFACE NORMAL. OBJECT-ORIENTED GRAPHICS: In this representation, a set of instructions is specified for each element of the image, such as “draw a blue line of 3-point thickness from (0.1, 0.1) to (0.8, 0.5)”. A synonym for VECTOR-BASED IMAGE. This is the default mode of most scientific graphics programs and drawing programs, but not of painting and image-processing software. OPEN SYMBOL: A symbol, such as a circle, triangle or square, which is shown only in outline without a fill. ORNAMENTS: See DINGBATS. ORTHOGRAPHIC: A species of perspective in which the “vanishing points” are at infinity so that the top of a cube, for example, is delineated by pairs of parallel lines. In true perspective, the top of a cube would be a trapezoid OVERLAY PLANE: High-end FRAME BUFFERS not only store an image, but also have additional space to store graphics which can be overlaid on top of the primary image. OVERLAY PLANES can accelerate graphics because a complicated primary image does not have to redrawn to superimpose text labels or arrows, or to overlay an animated figure that occupies a small part of the screen onto a complicated background that fills the screen. PI CHARACTER/FONT: A character which is a symbol (“DINGBAT”) rather than a letter, or a font full of such symbols. PICTOGRAPH: Species of plot in which quantities are denoted by plotting various numbers of identical icons. For example, the rate of U-boat sinkings during different years of World War II could be shown by using say, 1 icon of a sinking ship for every ten ships sunk during a given year. Synonyms: VISUAL TABLE. PHONG SHADING: A surface composed of polygons is shaded by computing SURFACE NORMALS at many points both at the vertices and face of a polygon, and then interpolating colors between those computed at each of the SURFACE NORMALS. (Superior but also more computationally intensive than FLAT (“FACETED”) shading and PHONG shading. PHOTOREALISTIC: Very sophisticated computer graphics which strives to make the screen or printed display look as realistic as a photograph. Rare (and rarely needed) in scientific and engineering visualization. PICA: One-sixth of an inch, a typesetter’s/book designer’s unit of measurement. PIXEL: The smallest picture element of a display; a screen cannot manipulate smaller pieces of an image. For example, a 1280 x 1032 display contains 1280*1032 pixels. The number of pixels in a display depends on the hardware.
440
Glossary
PMT: “Photomechanical Transfer Print”, a high-quality glossy reproduction of a figure. Journals and books often print figures by pasting a PMT onto a page from a phototypsetter, then making a photolithography plate from the result. Synonym: “stat”. POINT (UNIT OF SIZE): 1/72 of an inch or about 1/28 of a centimeter. PROCESS COLORS: Cyan, magenta, yellow and black, the usual four colors of printing. Sometimes five or more inks are used for high-end printing; the extra inks are called SPOT COLORS. PSEUDOCOLOR: Two different meanings in different contexts. First, a type of graph for displaying a function z(x, y) by marking the location (x, y) with a color which is associated with values of z through a COLORMAP, for example, dark red for the peak, dark blue for the minimum, and green for intermediate values of z. Second, a synonym for INDEXED COLOR in which an image is represented by storing 8-bit numbers that are indices into a palette of 256 colors. RASTER GRAPHICS: A form of graphic representation in which the color each individual pixel is specified. (See also BITMAP GRAPHICS.) The conversion of an OBJECTORIENTED (alias VECTOR-BASED) image to a pixel-based representation is said to be “RASTERIZING”. RGB: Red-Green-Blue, the three ADDITIVE COLORS employed by computer and television monitors. RGB COLOR: See TRUE COLOR. RECTO: Right-hand page. Many book designs specify that certain elements, such as the title page (always) and the first page of a chapter (in many book styles) must always be “recto”. REFLECTION MAPPING: Similar to TEXTURE MAPPING except that the texture is the reflection of external objects. A display of an automobile in a driveway might have the image of the house, driveway and lawn reflection-mapped onto the shiny, highly reflective car. ROTOSCOPING: Drawing directly on invididual frames of film. Adobe Photoshop can import video in filmstrip format as a single file from Adobe Premiere, draw on individual frames, and then export the filmstrip back to Premiere for video rendering or export. SANS SERIF: A font lacking serifs, such as Helvetica or Futura. SCIAGRAPHY: The art of delineating shadows in drawing, or sketching objects with ´ “shadow”. the correct shading. From Greek “σ κιa”, SERIF: A small stroke or line segment used to finish off the main stroke of a letter. Times Roman is a font with serifs; Helvetica is a serif-free or SANS SERIF font. SEMIOLOGY: The science of signs; the branch of medicine dealing with symptoms and by extension, the science and study of graphs. From the Greek σ ηµ"ιoν “sign” and λoγια “discourse” or “doctrine”.
Glossary
441
SEPARATIONS, COLOR: The generation of four separate photolithography printing plates, one for each of the subtractive (CMYK) colors, in offset printing. Imageprocessing software usually has the capability to split an image into four separate files so that the separations can be controlled electronically. SMALL MULTIPLIERS: To quote Tufte (1990), pg. 67: “Illustrations of postage-stamp size are indexed by category or a label, sequenced over time like the frames of a movie, or ordered by a quantitative variable not used in the single image. Information slices are positioned within the eyespan, so that viewers make comparisons at a glance — uninterrupted visual reasoning. Constancy of design puts the emphasis on changes in data, not changes in data frame.” This type of multipanel composite illustration must also be called a “Flipbook-on-a-Page” graph or a “Quantitative Storyboard”. SPECULAR REFLECTION: Mirror-like reflection. SPOT COLOR: Special inks which are used for high-end printing to supplement the usual four PROCESS (CMYK) colors. SPRITE: Graphic objects which are stored once in a movie file, and then duplicated or moved as needed. Early personal computer sprites were bitmaps were moved, without making big demands on the CPU, by blitting the sprite to the frame buffer. Modern sprites may either bitmap, vector, or 3D. STAIRCASING: When a smooth curve passes diagonally across the pixels of the screen, the curve must be approximated by a flight of stairs, each step being one pixel high. Also known as the JAGGIES or ALIASING. STILL: A single image, often taken from an animation, as opposed to the ANIMATION itself, which is composed of many frames. STORYBOARD: A collection of sketches which narrate the plot, settings and characters of a movie. SUBTRACTIVE COLORS: Cyan, magenta, yellow and black (CMYK), the four colors used in printing. These are also called PROCESS colors. SURFACE NORMAL: A vector which is perpendicular to a surface at a given point. The surface normal of the vertex of a polygon is defined as the average of the normal vectors to each of the polygonal faces that meet at that vertex. TESSELATE: To divide a complicated geometric object into the union of simpler ones to simplify calculations. For example, many graphics programs tesselate quadrilaterals, which may not be planar, into a pair of triangles, which are always lie in the plane defined by the three vertices. TEXTURE MAPPING: Superimposing an image (“texture”) defined on a plane onto a curved surface in three-dimensional space. The advantage of this method is that it is much easier to create a complicated texture on a plane than it is to color a complicated surface directly. TRACK: Different components of a movie or animation, playing simultaneously, are “tracks”. Most movies have both a video track and an audio track, but with the use of transparency masks, it is possible to layer a larger number of tracks in a single animation. Different species of images which are played at different times
442
Glossary may also be identified as distinct tracks, such as a video track which is followed a still-image track that freezes a single picture on the screen for a couple of seconds.
TRUE COLOR: An imaging scheme in which at each pixel, 8 bits are stored to represent the intensity of red, 8 additional bits are stored as the intensity of green, and a further 8 bits are a number which is the intensity of blue. Also called “24-bit” color or RGB COLOR. TWEENING: In old-fashioned celluloid animation, a small subset of the cells were sketched by the animators; most of the drawings were produced by less-skilled artists called “tweeners”, who interpolated between the KEYFRAMES created by the animators. Computer animation programs, notably Flash, use similar strategies to reduce the workload on animators. TWENTY-FOUR-BIT COLOR: See TRUE COLOR. VECTOR-BASED IMAGE: In this representation, a set of instructions is specified for each element of the image, such as “draw a blue line of 3-point thickness from (0.1, 0.1) to (0.8, 0.5)”. Synonym for OBJECT-ORIENTED GRAPHICS. VERSO: The left-hand side of a page. Book designs often specify that some elements must appear only a verso page. The copyright page, for example, is almost always “verso”. VISUAL TABLE: Species of plot in which quantities are denoted by plotting various numbers of identical icons. For example, the rate of U-boat sinkings during different years of World War II could be shown by using say, 1 icon of a sinking ship for every ten ships sunk during a given year. Synonyms: PICTOGRAPH. VOXEL: The smallest resolvable box in three-dimensional graphics, analogous to PIXEL. WATERFALL PLOT: A surface mesh plot in which only lines parallel to a single coordinate are drawn. Synonym: MESH PLOT, HORIZONTAL-ONLY. WORD SLIDE: A slide or transparency that contains only words without figures.
Bibliography [1] M. Alley, The Craft of Scientific Writing, Springer-Verlag, New York, 3rd ed., 1996. Paperback, 3rd ed., 282 pp., $25. [2] H. Arkin and R. R. Colton, Graphs: How to Make Them and Use Them, Harper & Brothers Publishers, New York, 1936. [3] J. Bertin, Graphics and the Graphical Analysis of Data, De Gruyter, Berlin, 1980. Translation from the French by W. Berg and H. Wainer. [4]
, Semiology of Graphics, University of Wisconsin Press, Madison, Wisconsin, 1983. Translated by W. Berg and H. Wainer from the 1972 French edition.
[5] F. J. Bitz and N. J. Zabusky, David and visiometrics: visualizing and quantifying evolving amorphous objects, Computers in Physics, 4 (1991), pp. 603–613. Describes a scientific graphical anaysis system, written for Unix/X-windows, and its use in analyzing complicated vortical flows. [6] W. Blake and F. Petrie, Getting Started in Drawing, North Light Books, Cincinnati, Ohio, 1991. Very readable introduction to black-and-white drawing; shows that pencil and charcoal artists use a palette of only three or four grayscale shades. [7] T. Bounford, Digital Diagrams: Effective Design and Presentation of Statistical Information, Watson-Guptill, New York, 2000. Elemntary text with lavish color illusrations on every page. 190 pp. [8] P. D. Bourke, A contouring subroutine, BYTE, 12 (1987), pp. 143–150. Subdivides each rectangle into four triangles with interpolated q at the midpoint of the rectangle; then computes the line segment of the contour within each triangle. [9] W. C. Brinton, Graphic Methods for Presenting Facts, McGraw-Hill Book Company, New York, 1914. [10] M. H. Briscoe, Preparing Scientific Illustrations, A Guide to Better Posters, Presentations and Publications, Springer-Verlag, New York, 2d ed., 1996. Available in paperback, $30. [11] D. Britz, An error propagation in the numerical literature, BIT, 38 (1998), pp. 217– 218. [12] K. W. Brodie, L. A. Carpenter, R. A. Earnshaw, et al., eds., Springer-Verlag, New York, 19. 443
444
BIBLIOGRAPHY
[13] J. R. Brown, R. Earnshaw, M. Jern, and J. Vince, Visualization: Using Computer Graphics to Explore Data and Present Information, John Wiley, New York, 1995. Textbook with lots of color graphics and good discussion of computer methods for both still pictures and animations. [14] W. E. Byerly, An Elementary Treatise on Fourier’s Series and Spherical, Cylindrical, and Ellipsoidal Harmonics, Ginn and Company, Boston, 1902. First published in 1893; several instructive graphics. [15] S. Chandrasekhar, Ellipsoidal Figures of Equilibrium, Yale University Press, New Haven, 1969. Darwin’s illustration of Poincar´ e’s piriform equilibrium shape for a rotating, self-gravitating mass of liquid. [16] P. C.-H. Cheng and H. A. Simon, Scientific discovery and creative reasoning with diagrams, in The Creative Cognition Approach, S. Smith, T. Ward, and R. Finke, eds., MIT Press, Cambridge, Massachusetts, 1995. BF408.C7451, Graduate Library. [17] T. H. Clarke, The Rhinoceros from Durer to Stubbs, 1515–1799, Sotheby’s Publications, Longdon, 1986. Monograph devoted entirely to the many plagiarized copies of D¨ urer’s rhinoceros, complete with its spurious second horn. 219 pp. N 7668 .R45 C531 1986. [18] W. S. Cleveland, Visualizing Data, Hobart Press, Summit, New Jersey, 1993. [19]
, The Elements of Graphing Data, Hobart Press, Summit, New Jersey, 2d ed., 1994.
[20] N. H. Crowhurst, Graphical Calculators and Their Design, Hayden Book Company, New York, 1965. [21] M. Davis, Scientific Papers and Presentations, Academic Press, New York, 1997. [22] R. A. Day, How to Write and Publish a Scientific Paper, Oryx Press, New York, 3rd ed., 1988. One chapter on graphs. [23] T. Delmarcelle, , and L. Hesselink, Visualizing second-order tensor fields with hyperstreamlines, IEEE Comput. Graph. Appl., 13 (1993), pp. 25–33. [24] R. R. Dickinson, Interactive analysis of the topology of 4D vector fields, IBM J. Res. Develop., 35 (1991), pp. 59–66. Glyphs on streamlines and related techniques. [25] D. Djuri´ c, Weather Analysis, Prentice-Hall, New York, 1994. Appendix F shows how grayscale processing of satellite IR images is manipulated to ignore very high or very low temperatures, which are not diagnostically relevant. [26] R. A. Earnshaw and N. Wiseman, An Introduction Guide to Scientific Visualization, Springer-Verlag, New York, 1992. [27] A. B. (editor), Handbook of Image Video Processing, Academic Press, New York, 2000. Encyclopedia with articles by a variety of authors on a wide range of topics, 891 pp. [28] M. Emmer, The Visual Mind, M. I. T. Press, Cambridge, 1993. Essays on the relationship between mathematics and the visual arts, many coauthored by a mathematician and an artist.
BIBLIOGRAPHY
445
[29] V. M. Fernandez, D. Silver, and N. J. Zabusky, Visiometrics of complex physical processes: Diagnosing vortex-dominated flows, Computers in Physics, 10 (1996), pp. 463–470. [30] M. Field and M. Golubitsky, Symmetry in Chaos, Oxford University Press, Oxford, 1992. Spectacular fractal curves drawn by simple algorithms. [31] B. J. Ford, Images of Science: A History of Scientific Illustration, Oxford University Press, New York, 1993. [32] D. L. Foster and R. McManus, 3-d data, Macworld, (1986), pp. 97–99. A review of the MacSpin program for displaying and rotating three-dimensional data plots to manually identify patterns in the scatterplot. [33] A. E. Gill, Atmosphere-Ocean Dynamics, vol. 30 of International Geophysics Series, Academic Press, New York, 1982. Many good graphs not duplicated elsewhere in the geophysical literature. [34] A. Globus and E. Raible, Fourteen ways to say nothing with visualization, IEEE Comput. Graph. Appl., 27 (1994), pp. 86–. [35] M. Goosens, S. Rahtz, and F. Mittelbach, The Latex Graphics Companion: Illustrating Documents with TeX and Postscript, Addison Wesley, Reading, Massachusetts, 1997. [36] R. L. Harris, Information Graphics: A Comprehensive Illustrated Reference, Management Graphics, Atlanta, Georgia, 1996. Comprehensive visual dictionary of graphs; 448 pp. [37] R. W. Hazen, Comment on ‘competitive interactions between neotropical pollinators and Africanized honey bees’, Science, 202 (1978), p. 823. Satirizes a parabola fitted to a very scattered scatterplot by fitting his own curve through the data, which is the loopy trajectory of a honeybee, complete with a little picture of the bee. [38] H. Hege and K. Polthier, eds., Visualization and Mathematics: Experiments, Simulations and Environments, Springer-Verlag, New York, 1997. [39] W. Herdeg, ed., The Artist in the Service of Science, Graphis Press Corporation, Zurich, 1973. [40]
, ed., The Graphic Visualization of Abstract Data, Graphis Press Corporation, Zurich, 1974. Hundreds of exemplars of scientific and information graphics by professional artists.
[41] L. Hesselink, T. Delmarcelle, and J. L. Helman, Topology of second-order tensor fields, Computers in Physics, 9 (1995), pp. 304–311. Visualization by hyperstreamlines, graphs of topological singularities and critical points, and tensor streategies. [42] K. G. Hjerter, Doubly Gifted: The Author as Visual Artist, Harry N. Abrams, Inc., New York, 1986. [43] E. R. S. Hodges, Scientific Illustration (Handbook), Van Nostrand Reinhold, New York, 1989. Guide for professional scientific illustrators, emphasizing botany and zoology.
446
BIBLIOGRAPHY
[44] N. Holmes, Designer’s Guide to Creating Charts and Diagrams, Watson-Guptill Publications, New York, 1984. Very readable but oriented towards commercial artists who draw illustrations for newspapers. [45] J. R. Holton, Introduction to Dynamic Meteorology, vol. 48 of International Geophysics, Academic Press, New York, third ed., 1992. [46] Houry, Dombrowsky, De Mey, and Minster, ???, J. Phys. Oceangr., 17 (1987), p. 1621. Fig. 2 is a graph with 384 separate line graphs, each in a separate box. [47] C. Hurley and A. Buja, Analyzing high-dimensional data with motion graphics, SIAM J. Sci. Stat. Comp., 11 (1990), pp. 1193–1211. [48] Z. Jastrzebski, Scientific Illustration: A Guide for the Beginning Artist, PrenticeHall, Englewood Cliffs, New Jersey, 1985. [49] J. R. Jensen, Introductory Digital Image Processing: A Remote Sensing Perspective, Prentice-Hall, 2d ed., 1996. Very readable and elementary introduction to image processing, focused on analysis and detection of features in satellite images. Call number G70.4.J461. [50] P. R. Keller and M. M. Keller, Visual Clues: Practical Data Visualization, IEEE Computer Society Press, New York, 1993. [51] G. V. Kelvin, Illustrating for Science: A Problem-Solving Approach to Rendering Subjects in Biology, Chemistry, Physics, Astronomy, Space Technology, Medicine, Geology and Architecture, Watson-Guptill, New York, 1992. Part memoir, part how-to, part coffee-table art book by an artist who has contributed many airbrush paintings to Scientific American. [52] G. D. Kerlick, Four lectures on computer graphics and data visualization, in Relativity and Scientific Computing, F. W. Hehl, R. A. Puntigam, and H. Ruder, eds., Springer-Verlag, New York, 1996, pp. 287–313. Review. [53] S. M. Kosslyn, Elements of graph design, W. H. Freeman, New York, 1994. Good how-to for black-and-white line graphs, based on current theories of psychology of perception and cognition. [54] B. Latour, Science in Action: How to Follow Scientists and Engineers Through Society, Harvard University, Cambridge, Massachusetts, 1987. [55] H. Lefkowitz and G. T. Herman, Color scales for image data, IEEE Comput. Graphics Appl., 12 (1992), pp. 72–80. Difficulties with standard color maps. [56] J. A. Lohne, The increasing corruption of Newton’s diagrams, History of Science, 6 (1967), pp. 71–73. [57] W. E. Lorensen and H. E. Cline, Marching cubes: A high resolution 3D surface construction algorithm, Computer Graphics, 21 (1987), pp. 163–169. Computing isosurfaces in three-dimensional data. [58] M. Lynch and S. Woolgar, eds., MIT Press, Cambridge, Massachusetts, 1990. Collection of papers from a special issue of the journal Human Studies; visualization from the perspective of sociologists of science.
BIBLIOGRAPHY
447
[59] R. A. Lyttleton, Rotating Figures of Equilibrium, Cambridge University Press, Cambridge, 1953. Darwin’s and Poincar´ e’s illustrations of piriform equilibrium shape for a rotating, self-gravitating mass of liquid. [60] B. B. Mandelbrot, Fractal curves osculated by sigma-discs and construction of self-inverse limit sets, Mathematical Intelligencer, 5 (1983), pp. 9–17. Shows that Fig. 156 of the 1897 book of Klein and Fricke, “endlessly reproduced, and for better or worse have affected the intuition of countless mathematicians”, have errors which are fixed in Mandelbrot’s versions of these. See also his forward to Peitgen and Saupe (1988). [61] P. Marchand, Graphics and GUIs with MATLAB, CRC Press, Boca Raton, Florida, 1996. [62] W. J. Mitchell, The Reconfigured Eye: Visual Truth in the Post-Photographic Error, MIT Press (?), Cambridge, 1992. [63] M. Monmonier, Air Apparent: How Meteorologists Learned to Map, Predict, and Dramatize Weather, University of Chicago Press, Chicago, 1999. Good discussion of visualization in meteorology. [64] C. Montani, R. Scateni, and R. Scopigno, A modified look-up table for implicit disambiguation of marching cubes, The Visual Computer, 10 (1994), pp. 353–355. Computing isosurfaces in three-dimensional data. [65] F. Mosteller, S. E. Fienberg, and R. E. K. Rourke, Beginning Statistics with Data Analysis, Addison-Wesley, Reading, Massachusetts, 1983. [66] S. Nakamura, Numerical Analysis and Graphic Visualization with MATLAB, Prentice-Hall, Upper Saddle River, New Jersey, 1996. [67] G. M. Nielsen, H. Hagen, and H. M¨ uller, eds., Scientific Visualization: Overviews, Methodologies, and Techniques, IEEE Computer Society, Los Alamitos, California, 1997. Q175.N4381 1997. [68] G. M. Nielsen, B. Shriver, and L. J. Rosenblum, eds., Visualization in Scientific Computing, IEEE Computer Society Press, Los Alamitos, California, 1990. [69] A. Noels, R. Papy, and F. Remy, Visualizing the evolution of a star on a graphic workstation, Computers in Physics, 7 (1993), pp. 202–207. Animation of evolution of axisymmetric stars with a three-way cutaway of a sphere and three line graphs plus a time label on each frame of the film. [70] M. Nyman, Photoshop in 4 Colors, Peachpit Press, Berkeley, California, 1995. [71] S. Peach, Technical Drawing Including Technical Design and Illustration, Usborne Guides, Usborne Publishing, London, 1987. Written for children, but very readable introduction to basic technical drawing including isometric drawing, perspective, and orthographic views. [72] H. Peitgen and D. Saupe, eds., The Science of Fractal Images, Springer-Verlag, New York, 1988. [73] S. G. Philander, El Ni˜ no and La Ni˜ na, and the Southern Oscillation, Academic Press, Boston, 1990. Some interesting graphics.
448
BIBLIOGRAPHY
[74] F. H. Post and A. J. S. Hin, eds., Advances in Scientific Visualization, SpringerVerlag, New York, 1992. Collection of how-to articles from a workshop in Delft on Visualization in Scientific Computing in 1991 ncluding computation of isosurfaces, visualization of stream surfaces through marker particles and other topics. [75] M. L. Pruett, Art and the Computer, McGraw-Hil, New York, 1984. Coffee-table books, a gallery of colored pictures generated by computer. Many were created by mathematical algorithms; the author is at Los Alamos. [76] D. Quammen, Boilerplate Rhino: Nature in the Eye of the Beholder, Scribner, New York, 2000. The title essay is a very good description of the history of Durer’s rhino, perhaps the most famous depiction of a beast in all of literature. [77] L. Revenga, ed., Science Through the Ages, Biblioteca National, Madrid, 1986. Catalogue of an exhibition of scientific manuscripts and drawings at the Bodleian Library, April to May, 1986. [78] L. Reynolds and D. Simmonds, Presentation of Data in Science: Publications, Slides, Posters, Overhead Projections, Tape-Slides, Television: Principles and Practices for Authors and Teachers, Martinus Nijhoff Publishers, The Hague, Netherlands, 1981. Readable, but restricted to black-and-white graphics as prepared by hand. [79] P. K. Robertson, Visualizing color gamuts: A user interface for the effective use of perceptual color spaces in data displays, IEEE Comput. Graphics Appl., 8 (1988), pp. 50–63. Difficulties with standard color maps. [80] H. Robin, The Scientific Image: From Cave to Computer, Harry N. Abrams, Inc., New York, 1992. Paperback edition by W. H. Freeman Company. [81] A. C. Rogers, Graphic Charts Handbook, Public Affairs Press, Washington, D. C., 1961. [82] B. E. Rogowitz and L. A. Treinish, How not to lie with visualization, Computers in Physics, 10 (1996), pp. 268–273. [83] R. S. Root-Bernstein, Visual thinking, Trans. Amer. Phil. Soc., 75 (1985), pp. 50– 67. AS36.A352, Grad Library. [84] D. W. Roubik, Competitive interactions between neotropical pollinators and Africanized honey bees, Science, 201 (1978), p. 1030. Shows a quadratic curve fit through a scatterplot where the data is so scattered that randomness is as good an explanation as the fitted curve. Amusingly satirized in Hazen(1978). [85] R. P. Runyon, How Numbers Lie: A Consumer’s Guide to the Fine Art of Numerical Deception, Lewis Publishing Company, Lexington, Massachusetts, 1981. [86] C. F. Schmid, Handbook of Graphic Presentation, Ronald, New York, 1954. [87] C. F. Schmid and S. E. Schmid, Handbook of Graphical Presentation, Wiley, New York, 2d ed., 1979. [88] Serial, Information design journal, tech. rep. NK1160.I43, Media Union. , Leonardo, tech. rep. Theme is the relationship between mathematics and
[89] art.
BIBLIOGRAPHY
449
[90] S. L. Simons, Jr., Make fast and simple contour plots on a microcomputer, BYTE, 8 (1983), pp. 487–492. Draws contours by performing piecewise interpolation on many line segments. [91] B. M. Stafford, Artful Science: Enlightment Entertainment and the Eclipse of Visual Education, MIT Press, Cambridge, Massachusetts, 1994. Study of the visual component of the “mathematical recreations” and “philosophical entertainments” that became popular in the 18th century; many 18th century scientific illustrations. [92] M. J. Stefik, D. G. Bobrow, and K. M. Kahn, Integrating access-oriented programming into a multiparadigm environment, IEEE Software, (1986), pp. 10–18. [93] P. S. Stevens, Patterns in Nature, Atlantic Monthly Press (Little, Brown, Inc)., Boston, 1974. Visual patterns and forms in the natural world, written by an architect. He notes,“In matters of visual form ... nature plays favoritis. Among her darlings are spirals, meanders, branching patterns and 120 degree joints”. “When we see how the branching of trees resembles the branching of arteries and the branching of rivers, how crystal grains look like soap bubbles and the plates of a tortoise’s shell, how the fiddleheads of ferns, stellar galaxies and water emptying from the bathtub spiral in a similar manner, then we cannot help but wonder why nature uses only a few kindred forms in so many different contexts. Why do meandering snakes, meandering rivers, and loops of string adopt the same pattern, and why do cracks in mud and markings on a giraffe arrange themselves like films in a froth of bubbles? [pg. 3]. [94] W. Steward and M. C. Brown, Scanner Solutions:, Muska and Lipman Publishing, Cincinnati, Ohio, 2000. [95] C. Strothotte and T. Strothotte, Seeing Between the Pixels: Pictures in Interactive Systems, Springer-Verlag, New York, 1997. Design of interactive computer systems for the presentation of scientific andbusines graphics, written from a computer science perspective. [96] M. J. Sullivan, Make Your Scanner a Great Design & Production Tool, North Light Books, Cincinnati, Ohio, 1995. Very readable, elementary introduction to scanning, written by a graphic design professional. [97] L. Tilling, Early experimental graphs, British Journal of Historical Science, 8 (1975), pp. 193–213. [98] E. R. Tufte, The Visual Display of Quantitative Information, Graphics Press, Cheshire, Connecticut, 1983. [99] [100]
, Envisioning Information, Graphics Press, Cheshire, Connecticut, 1990. , Graphical Explanations, Graphics Press, Cheshire, Connecticut, 1997.
[101] H. Wainer, Visual Revelations: Graphical Tales of Fate and Deception from Napoleon Bonaparte to Ross Perot, Springer-Verlag, New York, 1997. 180 pp. [102] H. Wainer and D. Thissen, Graphical data analysis, Annual Review of Psychology, 32 (1981), pp. 191–241. [103] G. Walker, Eccentric Books, Yale University Library, New Haven, 1988.
450
BIBLIOGRAPHY
[104] J. M. Wallace and P. V. Hobbs, Atmospheric Science: An Introductory Survey, Academic Press, New York, 1977. [105] J. Wechsler, ed., On Aesthetics in Science, MIT Press, Cambridge, 1987. [106] E. Weinmann and P. Lourekas, Illustrator for Macintosh, Visual Quickstart Guide, Peachpit Press, Addison Wesley Longman, Berkeley, California, 1996. [107] T. G. West, In the Mind’s Eye, Prometheus, 1991. Author is presided of the Visualization Research Institute. Published in Japan under a title that translates as Genuises Who Hated School. [108]
, Playing with images — a return to thinking in pictures, Computers in Physics, 10 (1996), p. 413. Commentary whose theme is that many great scientists have had strongly visual imaginations, but visual thinking has been deprecated in favor of analytical/symbolical thinking. Perhaps in the new era of computer graphics, respect for visual thinking will return.
[109] T. Williams and J. Underwood, The Science of Hitting, Simon and Schuter, 1968. The cover, duplicated on pg. 37, is a photograph of Williams in batting stance with a pseudocolor plot floating over home plate which shows the batting averages for pitches in that location; instead of the usual squares, the circles (representing baseballs) carry the lumps of colors, each numerically labelled. [110] K. B. Wolf, Integral Transforms in Science and Engineering, Plenum, New York, 1979. Very good black-and-white graphics including mesh plots coded with fine mesh for positive-valued parts of the surface, coarse mesh for negative-valued parts. [111] R. S. Wolf and L. Yaeger, Visualization of Natural Phenomena, Springer-Verlag, New York, 1993. [112] D. M. Young and R. T. Gregory, A Survey of Numerical Mathematics, Vol. 1, Addison-Wesley, Reading, MA, 1972. pg. 329–339; not spectral. [113] N. J. Zabusky, D. Silver, R. Pelz, and V. ’93, Visiometrics, juxtaposition and modeling, Physics Today, 46 (1993), pp. 24–31.