Debian Codegraph @

texmf-dist/doc/generic/pgf/pgfmanual-en-dv-introduction.tex

raw
1 % Copyright 2019 by Till Tantau
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Free Documentation License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10
11 \section{Introduction to Data Visualization}
12
13 \emph{Data visualization} is the process of converting \emph{data points,}
14 which typically consist of multiple numerical values, into a graphical
15 representation. Examples include the well-known function plots, but pie charts,
16 bar diagrams, box plots, or vector fields are also examples of data
17 visualizations.
18
19 The data visualization subsystem of \pgfname\ takes a general, open approach to
20 data visualization. Like everything else in \pgfname, there is a powerful, but
21 not-so-easy-to-use basic layer in the data visualization system and a less
22 flexible, but much simpler-to-use frontend layer. The present section gives an
23 overview of the basic ideas behind the data visualization system.
24
25
26 \subsection{Concept: Data Points}
27 \label{section-dv-intro-data-points}
28
29 The most important input for a data visualization is always raw data. This data
30 is typically present in different formats and the data visualization subsystem
31 provides methods for reading such formats and also for defining new input
32 formats. However, independently of the input format, we may ask what kind of
33 data the data visualization subsystem should be able to process. For
34 two-dimensional plots we need lists of pairs of real numbers. For a bar plot we
35 usually need a list of numbers, possibly together with some colors and labels.
36 For a surface plot we need a matrix of triples of real numbers. For a vector
37 field we need even more complex data.
38
39 The data visualization subsystem makes no assumption concerning which kind of
40 data is being processed. Instead, the whole ``rendering pipeline'' is centered
41 around a concept called the \emph{data point}. Conceptually, a data point is an
42 arbitrarily complex record that represents one piece of data that should be
43 visualized. Data points are \emph{not} just coordinates in the plane or the
44 numerical values that need to be visualized. Rather, they represent the basic
45 units of the data that needs to be visualized.
46
47 Consider the following example: In an experiment we drive a car along a road
48 and have different measurement instruments installed. We measure the position
49 of the car, the time, the speed, the direction the car is heading, the
50 acceleration, and perhaps some further values. A data point would consist of a
51 record consisting of a timestamp together with the current position of the car
52 (presumably two or three numbers), the speed vector (another two or three
53 numbers), the acceleration (another two or three numbers), and perhaps the
54 label text of the current experiment.
55
56 Data points should be ``information rich''. They might even contain more
57 information than what will actually be visualized. It is the job of the
58 rendering pipeline to pick out the information relevant to one particular data
59 visualization -- another visualization of the same data might pick different
60 aspects of the data points, thereby hopefully allowing new insights into the
61 data.
62
63 Technically, there is no special data structure for data points. Rather, when a
64 special macro called |\pgfdatapoint| is called, the ``totality'' of all
65 currently set keys with the |/data point/| prefix in the current scope forms
66 the data point. This is both a very general approach and quite fast since no
67 extra data structures need to be created.
68
69
70 \subsection{Concept: Visualization Pipeline}
71
72 The \emph{visualization pipeline} is a series of actions that are performed on
73 the to-be-visualized data. The data is presented to the visualization pipeline
74 in the form of a long stream of complex data points. The visualization
75 pipeline makes several passes over this stream of data points. During the first
76 pass(es), called the \emph{survey phase(s)}, information is gathered about the
77 data points such as minimal and maximal values, which can be useful for
78 automatic fitting of the data into a given area. In the main pass over the
79 data, called the \emph{visualization phase}, the data points are actually
80 visualized, for instance in the form of lines or points.
81
82 Like as for data points, the visualization pipeline makes no assumptions
83 concerning what kind of visualization is desired. Indeed, one could even use it
84 to produce a plain-text table. This flexibility is achieved by extensive use of
85 objects and signals: When a data visualization starts, a number of signals (see
86 Section~\ref{section-signals} for an introduction to signals) are initialized.
87 Then, numerous ``visualization objects'' are created that listen to these
88 signals. These objects are all involved in processing the data points. For
89 instance, the job of an |interval mapper| object is to map one attribute of a
90 data point, such as a car's velocity, to another, such as the $y$-axis of a
91 plot. For each data point the different signals are raised in a certain order
92 and the different visualization objects now have a chance of preparing the data
93 point for the actual visualization. Continuing the above example, there might
94 be a second |interval mapper| that takes the computed $y$-position and applies
95 a logarithm to it, because a log-plot was requested. Then another mapper, this
96 time a |polar mapper| might be used to map everything to polar coordinates.
97 Following this, a |plot mark visualizer| might actually draw something at the
98 computed position.
99
100 The whole idea behind the rendering pipeline is that new kinds of data
101 visualizations can be implemented, ideally, just by adding one or two new
102 objects to the visualization pipeline. Furthermore, different kinds of plots
103 can be combined in novel ways in this manner, which is usually very
104 hard to do otherwise.
105 For instance, the visualization pipeline makes it easy to create, say,
106 polar-semilog-box-plots. At first sight, such new kinds of plots may seem
107 frivolous, but data visualization is all about gaining insights into the data
108 from as many different angles as possible.
109
110 Naturally, creating new classes and objects for the rendering pipeline is not
111 trivial, so most users will just use the existing classes, which should, thus,
112 be as flexible as possible. But even when one only intends to use existing
113 classes, it is still tricky to setup the pipeline correctly since the ordering
114 is obviously important and since things like axes and ticks need to be
115 configured and taken care of. For this reason, the frontend libraries provide
116 preconfigured rendering pipelines so that one can simply say that a data
117 visualization should look like a |line plot| with |school book axes| or with
118 |scientific axes|, which selects a certain visualization pipeline that is
119 appropriate for this kind of plot:
120 %
121 \begin{codeexample}[preamble={\usetikzlibrary{datavisualization.formats.functions}}]
122 \begin{tikzpicture}[scale=.7]
123 \datavisualization [school book axes, visualize as smooth line]
124 data [format=function] {
125 var x : interval [-2:2];
126 func y = \value x*\value x + 1;
127 };
128 \end{tikzpicture}
129 \end{codeexample}
130 %
131 \begin{codeexample}[preamble={\usetikzlibrary{datavisualization.formats.functions}}]
132 \begin{tikzpicture}[scale=.7]
133 \datavisualization [scientific axes, visualize as smooth line]
134 data [format=function] {
135 var x : interval [-2:2];
136 func y = \value x*\value x + 1;
137 };
138 \end{tikzpicture}
139 \end{codeexample}
140 %
141 One must still configure such a plot (choose styles and themes and also specify
142 which attributes of a data point should be used), but on the whole the plot is
143 quite simple to specify.
144
145
146 %%% Local Variables:
147 %%% mode: latex
148 %%% TeX-master: "pgfmanual"
149 %%% End: