Skip to content

Commit a48d84b

Browse files
authored
Merge pull request #500 from nschloe/tables-fix-2
external tables fix
2 parents b27364c + a4f2e05 commit a48d84b

File tree

80 files changed

+435
-9093
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+435
-9093
lines changed

.github/workflows/ci.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: ci
33
on:
44
push:
55
branches:
6-
- main
6+
- main
77
pull_request:
88
branches:
9-
- main
9+
- main
1010

1111
jobs:
1212
lint:
@@ -25,15 +25,15 @@ jobs:
2525
matrix:
2626
python-version: [3.6, 3.7, 3.8, 3.9]
2727
steps:
28-
- uses: actions/setup-python@v2
29-
with:
30-
python-version: ${{ matrix.python-version }}
31-
- uses: actions/checkout@v2
32-
# - name: Install system dependencies
33-
# run: sudo apt-get install -y texlive-latex-base texlive-latex-extra context python3-tk
34-
- name: Test with tox
35-
run: |
36-
pip install tox
37-
tox -- --cov tikzplotlib --cov-report xml --cov-report term
38-
- uses: codecov/codecov-action@v1
39-
if: ${{ matrix.python-version == '3.9' }}
28+
- uses: actions/setup-python@v2
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
- uses: actions/checkout@v2
32+
# - name: Install system dependencies
33+
# run: sudo apt-get install -y texlive-latex-base texlive-latex-extra context python3-tk
34+
- name: Test with tox
35+
run: |
36+
pip install tox
37+
tox -- --cov tikzplotlib --cov-report xml --cov-report term
38+
- uses: codecov/codecov-action@v1
39+
if: ${{ matrix.python-version == '3.9' }}

Makefile

-33
This file was deleted.

README.md

+26-11
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ The output of tikzplotlib is in
3131
top of [PGF/TikZ](https://en.wikipedia.org/wiki/PGF/TikZ) and describes graphs in terms
3232
of axes, data etc. Consequently, the output of tikzplotlib
3333

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
3737

3838
than [raw TikZ output](https://matplotlib.org/users/whats_new.html#pgf-tikz-backend).
3939
For example, the matplotlib figure
40+
4041
```python
4142
import matplotlib.pyplot as plt
4243
import numpy as np
@@ -67,6 +68,7 @@ mpl.rcParams.update(mpl.rcParamsDefault)
6768
```
6869
-->
6970
(see above) gives
71+
7072
```latex
7173
\begin{tikzpicture}
7274
@@ -108,6 +110,7 @@ table {%
108110
109111
\end{tikzpicture}
110112
```
113+
111114
(Use `get_tikz_code()` instead of `save()` if you want the code as a string.)
112115

113116
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
121124

122125
tikzplotlib is [available from the Python Package
123126
Index](https://pypi.org/project/tikzplotlib/), so simply do
127+
124128
```
125129
pip install tikzplotlib
126130
```
127-
to install.
128131

132+
to install.
129133

130134
### Usage
131135

132136
1. Generate your matplotlib plot as usual.
133137

134138
2. Instead of `pyplot.show()`, invoke tikzplotlib by
139+
135140
```python
136141
import tikzplotlib
137142

138143
tikzplotlib.save("mytikz.tex")
139144
# or
140145
tikzplotlib.save("mytikz.tex", flavor="context")
141146
```
142-
to store the TikZ file as `mytikz.tex`.
147+
148+
to store the TikZ file as `mytikz.tex`.
143149

144150
3. Add the contents of `mytikz.tex` into your TeX source code. A convenient way of
145151
doing so is via
152+
146153
```latex
147154
\input{/path/to/mytikz.tex}
148155
```
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+
151160
```latex
152161
\usepackage[utf8]{inputenc}
153162
\usepackage{pgfplots}
@@ -156,7 +165,9 @@ to install.
156165
\usetikzlibrary{patterns,shapes.arrows}
157166
\pgfplotsset{compat=newest}
158167
```
159-
or:
168+
169+
or:
170+
160171
```latex
161172
\setupcolors[state=start]
162173
\usemodule[tikz]
@@ -167,7 +178,9 @@ to install.
167178
\unexpanded\def\startgroupplot{\groupplot}
168179
\unexpanded\def\stopgroupplot{\endgroupplot}
169180
```
170-
You can also get the code via:
181+
182+
You can also get the code via:
183+
171184
```python
172185
import tikzplotlib
173186

@@ -177,6 +190,7 @@ to install.
177190
```
178191

179192
4. Optional: clean up the figure before exporting to tikz using the `clean_figure` command.
193+
180194
```python
181195
import matplotlib.pyplot as plt
182196
import numpy as np
@@ -188,9 +202,10 @@ to install.
188202
tikzplotlib.clean_figure()
189203
tikzplotlib.save("test.tex")
190204
```
205+
191206
The command will remove points that are outside the axes limits, simplify curves and
192207
reduce point density for the specified target resolution.
193-
208+
194209
The feature originated from the
195210
[matlab2tikz](https://github.com./matlab2tikz/matlab2tikz) project and is adapted to
196211
matplotlib.
@@ -201,7 +216,6 @@ If you experience bugs, would like to contribute, have nice examples of what
201216
tikzplotlib can do, or if you are just looking for more information, then please
202217
visit [tikzplotlib's GitHub page](https://github.com./nschloe/tikzplotlib).
203218

204-
205219
### Testing
206220

207221
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
210224
reference TeX file.
211225

212226
To run the tests, just check out this repository and type
227+
213228
```
214229
pytest
215230
```

justfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version := `python3 -c "from configparser import ConfigParser; p = ConfigParser(); p.read('setup.cfg'); print(p['metadata']['version'])"`
2+
name := `python3 -c "from configparser import ConfigParser; p = ConfigParser(); p.read('setup.cfg'); print(p['metadata']['name'])"`
3+
4+
5+
default:
6+
@echo "\"just publish\"?"
7+
8+
tag:
9+
@if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then exit 1; fi
10+
curl -H "Authorization: token `cat ~/.github-access-token`" -d '{"tag_name": "{{version}}"}' https://api.github.com./repos/nschloe/{{name}}/releases
11+
12+
upload: clean
13+
@if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then exit 1; fi
14+
# https://stackoverflow.com/a/58756491/353337
15+
python3 -m build --sdist --wheel .
16+
twine upload dist/*
17+
18+
publish: tag upload
19+
20+
clean:
21+
@find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
22+
@rm -rf src/*.egg-info/ build/ dist/ .tox/
23+
24+
format:
25+
isort .
26+
black .
27+
blacken-docs README.md
28+
29+
lint:
30+
black --check .
31+
flake8 .

setup.cfg

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = tikzplotlib
3-
version = 0.9.9
3+
version = 0.9.10
44
author = Nico Schlömer
55
author_email = [email protected]
66
description = Convert matplotlib figures into TikZ/PGFPlots
@@ -15,6 +15,7 @@ license = MIT
1515
license_file = LICENSE
1616
classifiers =
1717
Development Status :: 4 - Beta
18+
Framework :: Matplotlib
1819
License :: OSI Approved :: MIT License
1920
Operating System :: OS Independent
2021
Programming Language :: Python

src/tikzplotlib/_axes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ def __init__(self, data, obj): # noqa: C901
8080
if obj.get_xscale() == "log":
8181
self.axis_options.append("xmode=log")
8282
self.axis_options.append(
83-
"log basis x={{{}}}".format(_try_f2i(obj.xaxis._scale.base))
83+
f"log basis x={{{_try_f2i(obj.xaxis._scale.base)}}}"
8484
)
8585
if obj.get_yscale() == "log":
8686
self.axis_options.append("ymode=log")
8787
self.axis_options.append(
88-
"log basis y={{{}}}".format(_try_f2i(obj.yaxis._scale.base))
88+
f"log basis y={{{_try_f2i(obj.yaxis._scale.base)}}}"
8989
)
9090

9191
# Possible values for get_axisbelow():
@@ -771,7 +771,7 @@ def _handle_listed_color_map(cmap, data):
771771
reps = int(float(cmap.N) / len(cmap.colors) - 0.5) + 1
772772
repeated_cols = reps * cmap.colors
773773
colors = [
774-
"rgb({k}{unit})=({rgb[0]:{ff}},{rgb[1]:{ff}},{rgb[2]:{ff}})"
774+
f"rgb({k}{unit})=({rgb[0]:{ff}},{rgb[1]:{ff}},{rgb[2]:{ff}})"
775775
for k, rgb in enumerate(repeated_cols[: cmap.N])
776776
]
777777
colormap_string = "{{mymap}}{{[1{}]\n {}\n}}".format(unit, ";\n ".join(colors))

src/tikzplotlib/_cleanfigure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def _get_collection_data(collection):
584584
if is3D:
585585
# https://stackoverflow.com/questions/51716696/extracting-data-from-a-3d-scatter-plot-in-matplotlib
586586
offsets = collection._offsets3d
587-
xData, yData, zData = [o.data for o in offsets]
587+
xData, yData, zData = (o.data for o in offsets)
588588
data = _stack_data_3D(xData, yData, zData)
589589
else:
590590
offsets = collection.get_offsets()

src/tikzplotlib/_hatches.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
r"""
2-
Map matplotlib hatches to tikz patterns
2+
Map matplotlib hatches to tikz patterns
33
4-
For matplotlib hatches, see:
5-
https://matplotlib.org/3.1.1/gallery/shapes_and_collections/hatch_demo.html
4+
For matplotlib hatches, see:
5+
https://matplotlib.org/3.1.1/gallery/shapes_and_collections/hatch_demo.html
66
7-
For patterns in tikzpgf:
8-
Ch 26 Pattern Lbrary in the manual
9-
Requires \usetikzlibrary{patterns}
7+
For patterns in tikzpgf:
8+
Ch 26 Pattern Lbrary in the manual
9+
Requires \usetikzlibrary{patterns}
1010
"""
1111

1212
# These methods exist, and might be relevant (in the future?):
@@ -93,7 +93,7 @@ def _mpl_hatch2pgfp_pattern(data, hatch, color_name, color_rgba):
9393
try:
9494
pgfplots_pattern = _MP_HATCH2PGF_PATTERN[hatch]
9595
except KeyError:
96-
warnings.warn("tikzplotlib: The hatch", hatch, "is ignored.")
96+
warnings.warn(f"tikzplotlib: The hatch {hatch} is ignored.")
9797
return data, []
9898

9999
data["tikz libs"].add("patterns")

src/tikzplotlib/_line2d.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,16 @@ def _table(obj, data): # noqa: C901
266266
if data["table_row_sep"] != "\n":
267267
# don't want the \n in the table definition, just in the data (below)
268268
opts.append("row sep=" + data["table_row_sep"].strip())
269+
270+
if data["externals search path"] is not None:
271+
esp = data["externals search path"]
272+
opts.append(f"search path={{{esp}}}")
273+
269274
if len(opts) > 0:
270-
content.append("table [{}] {{%\n".format(",".join(opts)))
275+
opts_str = ",".join(opts)
276+
content.append(f"table [{opts_str}] {{")
271277
else:
272-
content.append("table {%\n")
278+
content.append("table {")
273279

274280
plot_table = []
275281
table_row_sep = data["table_row_sep"]
@@ -284,12 +290,13 @@ def _table(obj, data): # noqa: C901
284290
plot_table.append(f"{x:{xformat}}{col_sep}{y:{ff}}{table_row_sep}")
285291

286292
if data["externalize tables"]:
287-
filepath, rel_filepath = _files.new_filepath(data, "table", ".tsv")
293+
filepath, rel_filepath = _files.new_filepath(data, "table", ".dat")
288294
with open(filepath, "w") as f:
289295
# No encoding handling required: plot_table is only ASCII
290296
f.write("".join(plot_table))
291297
content.append(str(rel_filepath))
292298
else:
299+
content.append("%\n")
293300
content.extend(plot_table)
294301

295302
content.append("};\n")

0 commit comments

Comments
 (0)