Debian Codegraph @

docs/examples.rst

raw
1 ========
2 Examples
3 ========
4
5 Data series
6 ===========
7
8 Simple pairs
9 ------------
10
11 .. literalinclude:: ../examples/simple_pairs.py
12 :language: python
13
14 .. figure:: ../examples/charts/simple_pairs.svg
15
16 Table from csv.reader
17 ---------------------
18
19 Sequence row data, such as is returned by :func:`csv.reader` can be accessed by specifying the indices of the columns containing the :code:`x` and :code:`y` values.
20
21 Note that leather does not automatically convert numerical strings, such as those stored in a CSV. If you want that you'll need to use a smarter table reader, such as `agate <https://agate.rtfd.io/>`_
22
23 .. literalinclude:: ../examples/csv_reader.py
24 :language: python
25
26 .. figure:: ../examples/charts/csv_reader.svg
27
28 Table from csv.DictReader
29 -------------------------
30
31 Dict row data, such as is returned by :class:`csv.DictReader` can be accessed by specifying the indices of the columns containing the :code:`x` and :code:`y` values.
32
33 See previous example for note on strings from CSVs.
34
35 .. literalinclude:: ../examples/csv_dict_reader.py
36 :language: python
37
38 .. figure:: ../examples/charts/csv_dict_reader.svg
39
40 Custom data
41 -----------
42
43 Completely custom data formats are also supported via accessor functions.
44
45 .. literalinclude:: ../examples/custom_data.py
46 :language: python
47
48 .. figure:: ../examples/charts/custom_data.svg
49
50 Multiple series
51 ---------------
52
53 Multiple data series can be displayed on a single chart so long as they all use the same type of :class:`.Scale`.
54
55 .. literalinclude:: ../examples/multiple_series.py
56 :language: python
57
58 .. figure:: ../examples/charts/multiple_series.svg
59
60 Shapes
61 ======
62
63 Bars
64 ----
65
66 .. literalinclude:: ../examples/bars.py
67 :language: python
68
69 .. figure:: ../examples/charts/bars.svg
70
71 Columns
72 -------
73
74 .. literalinclude:: ../examples/columns.py
75 :language: python
76
77 .. figure:: ../examples/charts/columns.svg
78
79 Dots
80 ----
81
82 .. literalinclude:: ../examples/dots.py
83 :language: python
84
85 .. figure:: ../examples/charts/dots.svg
86
87 Lines
88 -----
89
90 .. literalinclude:: ../examples/lines.py
91 :language: python
92
93 .. figure:: ../examples/charts/lines.svg
94
95 Mixing shapes
96 -------------
97
98 You can mix different shapes for different series on the same chart.
99
100 .. literalinclude:: ../examples/mixed_shapes.py
101 :language: python
102
103 .. figure:: ../examples/charts/mixed_shapes.svg
104
105 Scales
106 ======
107
108 Linear
109 ------
110
111 When using numerical data :class:`.Linear` scales are created automatically and by default. You may override the domain by adding a scale manually.
112
113 .. literalinclude:: ../examples/linear.py
114 :language: python
115
116 .. figure:: ../examples/charts/linear.svg
117
118 Ordinal
119 -------
120
121 When using text data :class:`.Ordinal` scales are created automatically and by default. It is generally not useful to override these defaults.
122
123 .. literalinclude:: ../examples/ordinal.py
124 :language: python
125
126 .. figure:: ../examples/charts/ordinal.svg
127
128 Temporal
129 --------
130
131 When using date/time data :class:`.Temporal` scales are created automatically and by default. You may override the domain by adding a scale manually.
132
133 .. literalinclude:: ../examples/temporal.py
134 :language: python
135
136 .. figure:: ../examples/charts/temporal.svg
137
138 Axes
139 ====
140
141 Changing tick values
142 --------------------
143
144 You can change the list of ticks that are displayed using :meth:`.Chart.add_x_axis` and :meth:`.Chart.add_y_axis` methods. This will not adjust automatically adjust the scale, so it is possible to pick tick values that are not displayed.
145
146 .. literalinclude:: ../examples/ticks.py
147 :language: python
148
149 .. figure:: ../examples/charts/ticks.svg
150
151 Customizing tick format
152 -----------------------
153
154 You can provide a tick formatter method to change how ticks are displayed using the :meth:`.Chart.add_x_axis` and :meth:`.Chart.add_y_axis` methods.
155
156 .. literalinclude:: ../examples/tick_format.py
157 :language: python
158
159 .. figure:: ../examples/charts/tick_format.svg
160
161 Styling
162 =======
163
164 Changing theme values
165 ---------------------
166
167 Chart styles are set using a dead simple :mod:`.theme` system. Leather is meant for making quick and dirty charts. It is neither expected nor recommended for user's to customize these styles.
168
169 .. literalinclude:: ../examples/theme.py
170 :language: python
171
172 .. figure:: ../examples/charts/theme.svg
173
174 Changing series colors
175 ----------------------
176
177 More practically, individual default :class:`.Series` colors can be overridden when they are created.
178
179 .. literalinclude:: ../examples/series_color.py
180 :language: python
181
182 .. figure:: ../examples/charts/series_color.svg
183
184
185 Styling data based on value
186 ---------------------------
187
188 Style attributes of individual data points can be set by value using a :func:`.style_function`.
189
190 .. literalinclude:: ../examples/colorized_dots.py
191 :language: python
192
193 .. figure:: ../examples/charts/colorized_dots.svg
194
195 Creating dashed lines
196 ---------------------
197
198 When using :meth:`.Chart.add_line`, you can set the `stroke_dasharray property <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray>`_.
199
200 .. literalinclude:: ../examples/lines_dashes.py
201 :language: python
202
203 .. figure:: ../examples/charts/lines_dashes.svg
204
205
206 Chart grids
207 ===========
208
209 With mixed scales
210 -----------------
211
212 You can add charts of completely different types to a single graphic by using :class:`.Grid`.
213
214 .. literalinclude:: ../examples/grid.py
215 :language: python
216
217 .. figure:: ../examples/charts/grid.svg
218
219 With consistent scales
220 ----------------------
221
222 A grid of charts can automatically be synchronized to a consistent view using :class:`.Lattice`.
223
224 .. literalinclude:: ../examples/lattice.py
225 :language: python
226
227 .. figure:: ../examples/charts/lattice.svg