@@ -31,13 +31,12 @@ The output of tikzplotlib is in
31
31
top of [ PGF/TikZ] ( https://en.wikipedia.org/wiki/PGF/TikZ ) and describes graphs in terms
32
32
of axes, data etc. Consequently, the output of tikzplotlib
33
33
34
- - retains more information,
35
- - can be more easily understood, and
36
- - is more easily editable
34
+ * retains more information,
35
+ * can be more easily understood, and
36
+ * is more easily editable
37
37
38
38
than [ raw TikZ output] ( https://matplotlib.org/users/whats_new.html#pgf-tikz-backend ) .
39
39
For example, the matplotlib figure
40
-
41
40
``` python
42
41
import matplotlib.pyplot as plt
43
42
import numpy as np
@@ -58,20 +57,16 @@ import tikzplotlib
58
57
59
58
tikzplotlib.save(" test.tex" )
60
59
```
61
-
62
60
<!-- close the figure and reset defaults
63
61
<!--pytest-codeblocks:cont-->
64
-
65
62
``` python
66
63
import matplotlib as mpl
67
64
68
65
plt.close()
69
66
mpl.rcParams.update(mpl.rcParamsDefault)
70
67
```
71
-
72
68
-->
73
69
(see above) gives
74
-
75
70
``` latex
76
71
\begin{tikzpicture}
77
72
@@ -113,7 +108,6 @@ table {%
113
108
114
109
\end{tikzpicture}
115
110
```
116
-
117
111
(Use ` get_tikz_code() ` instead of ` save() ` if you want the code as a string.)
118
112
119
113
Tweaking the plot is straightforward and can be done as part of your TeX work flow.
@@ -127,39 +121,33 @@ Notably, [3D plots don't work](https://github.com/matplotlib/matplotlib/issues/7
127
121
128
122
tikzplotlib is [ available from the Python Package
129
123
Index] ( https://pypi.org/project/tikzplotlib/ ) , so simply do
130
-
131
124
```
132
125
pip install tikzplotlib
133
126
```
134
-
135
127
to install.
136
128
129
+
137
130
### Usage
138
131
139
132
1 . Generate your matplotlib plot as usual.
140
133
141
134
2 . Instead of ` pyplot.show() ` , invoke tikzplotlib by
142
-
143
135
``` python
144
136
import tikzplotlib
145
137
146
138
tikzplotlib.save(" mytikz.tex" )
147
139
# or
148
140
tikzplotlib.save(" mytikz.tex" , flavor = " context" )
149
141
```
150
-
151
- to store the TikZ file as `mytikz.tex` .
142
+ to store the TikZ file as `mytikz.tex` .
152
143
153
144
3 . Add the contents of `mytikz.tex` into your TeX source code. A convenient way of
154
145
doing so is via
155
-
156
146
```latex
157
147
\input{/path/to/mytikz.tex}
158
148
```
159
-
160
- Also make sure that the packages for PGFPlots and proper Unicode support and are
161
- included in the header of your document:
162
-
149
+ Also make sure that the packages for PGFPlots and proper Unicode support and are
150
+ included in the header of your document:
163
151
```latex
164
152
\usepackage[utf8]{inputenc}
165
153
\usepackage{pgfplots}
@@ -168,9 +156,7 @@ to install.
168
156
\usetikzlibrary{patterns,shapes.arrows}
169
157
\pgfplotsset{compat=newest}
170
158
```
171
-
172
- or :
173
-
159
+ or :
174
160
```latex
175
161
\setupcolors[state=start]
176
162
\usemodule[tikz]
@@ -181,9 +167,7 @@ to install.
181
167
\unexpanded\def\startgroupplot{\groupplot}
182
168
\unexpanded\def\stopgroupplot{\endgroupplot}
183
169
```
184
-
185
- You can also get the code via:
186
-
170
+ You can also get the code via:
187
171
```python
188
172
import tikzplotlib
189
173
@@ -193,7 +177,6 @@ to install.
193
177
```
194
178
195
179
4 . Optional: clean up the figure before exporting to tikz using the `clean_figure` command.
196
-
197
180
```python
198
181
import matplotlib.pyplot as plt
199
182
import numpy as np
@@ -205,10 +188,9 @@ to install.
205
188
tikzplotlib.clean_figure()
206
189
tikzplotlib.save(" test.tex" )
207
190
```
208
-
209
191
The command will remove points that are outside the axes limits, simplify curves and
210
192
reduce point density for the specified target resolution.
211
-
193
+
212
194
The feature originated from the
213
195
[matlab2tikz](https:// github.com/ matlab2tikz/ matlab2tikz) project and is adapted to
214
196
matplotlib.
@@ -219,6 +201,7 @@ If you experience bugs, would like to contribute, have nice examples of what
219
201
tikzplotlib can do, or if you are just looking for more information, then please
220
202
visit [tikzplotlib' s GitHub page](https://github.com/nschloe/tikzplotlib).
221
203
204
+
222
205
# ## Testing
223
206
224
207
tikzplotlib has automatic unit testing to make sure that the software doesn' t
@@ -227,7 +210,6 @@ Those run through tikzplotlib and compare the output with a previously stored
227
210
reference TeX file .
228
211
229
212
To run the tests, just check out this repository and type
230
-
231
213
```
232
214
pytest
233
215
```
0 commit comments