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