Skip to content

Commit 78b01c8

Browse files
committed
easier-to-read tables
1 parent e661bb7 commit 78b01c8

29 files changed

+1786
-1792
lines changed

matplotlib2tikz/line2d.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -383,22 +383,17 @@ def _marker(
383383

384384

385385
def _table(obj, content, data):
386-
if data["externalize tables"]:
387-
content.append("table {%\n")
388-
row_sep = ""
389-
else:
390-
content.append("table [row sep=\\\\]{%\n")
391-
row_sep = "\\\\"
386+
content.append("table {%\n")
392387

393-
# nschloe, Oct 2, 2015:
388+
# TODO nschloe, Oct 2, 2015:
394389
# The transform call yields warnings and it is unclear why. Perhaps
395390
# the input data is not suitable? Anyhow, this should not happen.
396391
# Comment out for now.
397392
# xdata, ydata = _transform_to_data_coordinates(obj, *obj.get_data())
398393
xdata, ydata = obj.get_data()
399394

400-
# matplotlib allows plotting of data containing `astropy.units`, but they will
401-
# break the formatted string here. Try to strip the units from the data.
395+
# matplotlib allows plotting of data containing `astropy.units`, but they will break
396+
# the formatted string here. Try to strip the units from the data.
402397
try:
403398
xdata = xdata.value
404399
except AttributeError:
@@ -415,18 +410,17 @@ def _table(obj, content, data):
415410

416411
plot_table = []
417412
if has_mask:
418-
# matplotlib jumps at masked images, while PGFPlots by default
419-
# interpolates. Hence, if we have a masked plot, make sure that
420-
# PGFPlots jumps as well.
413+
# matplotlib jumps at masked images, while PGFPlots by default interpolates.
414+
# Hence, if we have a masked plot, make sure that PGFPlots jumps as well.
421415
data["extra axis options"].add("unbounded coords=jump")
422416
for (x, y, is_masked) in zip(xdata, ydata, ydata.mask):
423417
if is_masked:
424-
plot_table.append("%.15g\tnan %s\n" % (x, row_sep))
418+
plot_table.append("{:.15g} nan\n".format(x))
425419
else:
426-
plot_table.append("%.15g\t%.15g %s\n" % (x, y, row_sep))
420+
plot_table.append("{:.15g} {:.15g}\n".format(x, y))
427421
else:
428422
for (x, y) in zip(xdata, ydata):
429-
plot_table.append("%.15g\t%.15g %s\n" % (x, y, row_sep))
423+
plot_table.append("{:.15g} {:.15g}\n".format(x, y))
430424

431425
if data["externalize tables"]:
432426
filename, rel_filepath = files.new_filename(data, "table", ".tsv")

matplotlib2tikz/path.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def draw_pathcollection(data, obj):
100100
dd = obj.get_offsets()
101101

102102
draw_options = ["only marks"]
103-
table_options = ["row sep=\\\\"]
103+
table_options = []
104104

105105
if obj.get_array() is not None:
106106
draw_options.append("scatter")
@@ -164,10 +164,10 @@ def draw_pathcollection(data, obj):
164164
to = " [{}]".format(", ".join(table_options)) if table_options else ""
165165
content.append("table{}{{%\n".format(to))
166166

167-
content.append((" ".join(labels)).strip() + "\\\\ \n")
168-
fmt = (" ".join(dd.shape[1] * ["%+.15e"])) + "\\\\ \n"
167+
content.append((" ".join(labels)).strip() + "\n")
168+
fmt = (" ".join(dd.shape[1] * ["{:+.15e}"])) + "\n"
169169
for d in dd:
170-
content.append(fmt % tuple(d))
170+
content.append(fmt.format(*tuple(d)))
171171
content.append("};\n")
172172

173173
return data, content
@@ -182,13 +182,13 @@ def get_draw_options(data, ec, fc):
182182
data, col, ec_rgba = color.mpl_color2xcolor(data, ec)
183183
if ec_rgba[3] != 0.0:
184184
# Don't draw if it's invisible anyways.
185-
draw_options.append("draw=%s" % col)
185+
draw_options.append("draw={}".format(col))
186186

187187
if fc is not None:
188188
data, col, fc_rgba = color.mpl_color2xcolor(data, fc)
189189
if fc_rgba[3] != 0.0:
190190
# Don't draw if it's invisible anyways.
191-
draw_options.append("fill=%s" % col)
191+
draw_options.append("fill={}".format(col))
192192

193193
# handle transparency
194194
if (
@@ -200,9 +200,9 @@ def get_draw_options(data, ec, fc):
200200
draw_options.append("opacity=%.15g" % ec[3])
201201
else:
202202
if ec is not None and ec_rgba[3] != 1.0:
203-
draw_options.append("draw opacity=%.15g" % ec_rgba[3])
203+
draw_options.append("draw opacity={:.15g}".format(ec_rgba[3]))
204204
if fc is not None and fc_rgba[3] != 1.0:
205-
draw_options.append("fill opacity=%.15g" % fc_rgba[3])
205+
draw_options.append("fill opacity={:.15g}".format(fc_rgba[3]))
206206
# TODO Use those properties
207207
# linewidths = obj.get_linewidths()
208208

test/test_annotate_reference.tex

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@
99
ymin=-4, ymax=3
1010
]
1111
\addplot [semithick, blue, forget plot]
12-
table [row sep=\\]{%
13-
0 1 \\
14-
0.2 0.309016994374947 \\
15-
0.4 -0.809016994374947 \\
16-
0.6 -0.809016994374947 \\
17-
0.8 0.309016994374947 \\
18-
1 1 \\
19-
1.2 0.309016994374947 \\
20-
1.4 -0.809016994374947 \\
21-
1.6 -0.809016994374948 \\
22-
1.8 0.309016994374947 \\
23-
2 1 \\
24-
2.2 0.309016994374946 \\
25-
2.4 -0.809016994374948 \\
26-
2.6 -0.809016994374948 \\
27-
2.8 0.309016994374947 \\
28-
3 1 \\
29-
3.2 0.309016994374948 \\
30-
3.4 -0.809016994374949 \\
31-
3.6 -0.809016994374948 \\
32-
3.8 0.309016994374947 \\
33-
4 1 \\
34-
4.2 0.309016994374948 \\
35-
4.4 -0.809016994374949 \\
36-
4.6 -0.809016994374946 \\
37-
4.8 0.30901699437495 \\
12+
table {%
13+
0 1
14+
0.2 0.309016994374947
15+
0.4 -0.809016994374947
16+
0.6 -0.809016994374947
17+
0.8 0.309016994374947
18+
1 1
19+
1.2 0.309016994374947
20+
1.4 -0.809016994374947
21+
1.6 -0.809016994374948
22+
1.8 0.309016994374947
23+
2 1
24+
2.2 0.309016994374946
25+
2.4 -0.809016994374948
26+
2.6 -0.809016994374948
27+
2.8 0.309016994374947
28+
3 1
29+
3.2 0.309016994374948
30+
3.4 -0.809016994374949
31+
3.6 -0.809016994374948
32+
3.8 0.309016994374947
33+
4 1
34+
4.2 0.309016994374948
35+
4.4 -0.809016994374949
36+
4.6 -0.809016994374946
37+
4.8 0.30901699437495
3838
};
3939
\draw[->,red] (axis cs:4.5,1.5) -- (axis cs:4,1);
4040
\node at (axis cs:4.5,1.5)[

test/test_barchart_errorbars_reference.tex

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,40 +45,40 @@
4545
--(axis cs:2.25,1.1);
4646

4747
\addplot [semithick, black, mark=-, mark size=8, mark options={solid}, only marks, forget plot]
48-
table [row sep=\\]{%
49-
-0.25 0.9 \\
50-
0.75 1.8 \\
51-
1.75 2.5 \\
48+
table {%
49+
-0.25 0.9
50+
0.75 1.8
51+
1.75 2.5
5252
};
5353
\addplot [semithick, black, mark=-, mark size=8, mark options={solid}, only marks, forget plot]
54-
table [row sep=\\]{%
55-
-0.25 1.1 \\
56-
0.75 2.2 \\
57-
1.75 3.5 \\
54+
table {%
55+
-0.25 1.1
56+
0.75 2.2
57+
1.75 3.5
5858
};
5959
\addplot [semithick, black, mark=-, mark size=8, mark options={solid}, only marks, forget plot]
60-
table [row sep=\\]{%
61-
0 2.6 \\
62-
1 1.8 \\
63-
2 3.5 \\
60+
table {%
61+
0 2.6
62+
1 1.8
63+
2 3.5
6464
};
6565
\addplot [semithick, black, mark=-, mark size=8, mark options={solid}, only marks, forget plot]
66-
table [row sep=\\]{%
67-
0 3.4 \\
68-
1 2.2 \\
69-
2 4.5 \\
66+
table {%
67+
0 3.4
68+
1 2.2
69+
2 4.5
7070
};
7171
\addplot [semithick, black, mark=-, mark size=8, mark options={solid}, only marks, forget plot]
72-
table [row sep=\\]{%
73-
0.25 4.9 \\
74-
1.25 2.8 \\
75-
2.25 0.9 \\
72+
table {%
73+
0.25 4.9
74+
1.25 2.8
75+
2.25 0.9
7676
};
7777
\addplot [semithick, black, mark=-, mark size=8, mark options={solid}, only marks, forget plot]
78-
table [row sep=\\]{%
79-
0.25 5.1 \\
80-
1.25 3.2 \\
81-
2.25 1.1 \\
78+
table {%
79+
0.25 5.1
80+
1.25 3.2
81+
2.25 1.1
8282
};
8383
\end{axis}
8484

test/test_basic_sin_reference.tex

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,50 @@
1919
ymin=-1.1, ymax=1.1
2020
]
2121
\addplot [semithick, color0, mark=*, mark size=3, mark options={solid}, forget plot]
22-
table [row sep=\\]{%
23-
0 0 \\
24-
0.1 0.587785252292473 \\
25-
0.2 0.951056516295154 \\
26-
0.3 0.951056516295154 \\
27-
0.4 0.587785252292473 \\
28-
0.5 1.22464679914735e-16 \\
29-
0.6 -0.587785252292473 \\
30-
0.7 -0.951056516295154 \\
31-
0.8 -0.951056516295154 \\
32-
0.9 -0.587785252292473 \\
33-
1 -2.44929359829471e-16 \\
34-
1.1 0.587785252292474 \\
35-
1.2 0.951056516295154 \\
36-
1.3 0.951056516295154 \\
37-
1.4 0.587785252292473 \\
38-
1.5 3.67394039744206e-16 \\
39-
1.6 -0.587785252292473 \\
40-
1.7 -0.951056516295154 \\
41-
1.8 -0.951056516295154 \\
42-
1.9 -0.587785252292473 \\
22+
table {%
23+
0 0
24+
0.1 0.587785252292473
25+
0.2 0.951056516295154
26+
0.3 0.951056516295154
27+
0.4 0.587785252292473
28+
0.5 1.22464679914735e-16
29+
0.6 -0.587785252292473
30+
0.7 -0.951056516295154
31+
0.8 -0.951056516295154
32+
0.9 -0.587785252292473
33+
1 -2.44929359829471e-16
34+
1.1 0.587785252292474
35+
1.2 0.951056516295154
36+
1.3 0.951056516295154
37+
1.4 0.587785252292473
38+
1.5 3.67394039744206e-16
39+
1.6 -0.587785252292473
40+
1.7 -0.951056516295154
41+
1.8 -0.951056516295154
42+
1.9 -0.587785252292473
4343
};
4444
\addplot [very thick, color1, opacity=0.3, mark=*, mark size=3, mark options={solid}, forget plot]
45-
table [row sep=\\]{%
46-
0 1 \\
47-
0.1 0.809016994374947 \\
48-
0.2 0.309016994374947 \\
49-
0.3 -0.309016994374948 \\
50-
0.4 -0.809016994374947 \\
51-
0.5 -1 \\
52-
0.6 -0.809016994374947 \\
53-
0.7 -0.309016994374948 \\
54-
0.8 0.309016994374947 \\
55-
0.9 0.809016994374947 \\
56-
1 1 \\
57-
1.1 0.809016994374947 \\
58-
1.2 0.309016994374947 \\
59-
1.3 -0.309016994374947 \\
60-
1.4 -0.809016994374947 \\
61-
1.5 -1 \\
62-
1.6 -0.809016994374948 \\
63-
1.7 -0.309016994374946 \\
64-
1.8 0.309016994374947 \\
65-
1.9 0.809016994374947 \\
45+
table {%
46+
0 1
47+
0.1 0.809016994374947
48+
0.2 0.309016994374947
49+
0.3 -0.309016994374948
50+
0.4 -0.809016994374947
51+
0.5 -1
52+
0.6 -0.809016994374947
53+
0.7 -0.309016994374948
54+
0.8 0.309016994374947
55+
0.9 0.809016994374947
56+
1 1
57+
1.1 0.809016994374947
58+
1.2 0.309016994374947
59+
1.3 -0.309016994374947
60+
1.4 -0.809016994374947
61+
1.5 -1
62+
1.6 -0.809016994374948
63+
1.7 -0.309016994374946
64+
1.8 0.309016994374947
65+
1.9 0.809016994374947
6666
};
6767
\end{axis}
6868

0 commit comments

Comments
 (0)