Skip to content

Commit 95459b9

Browse files
authored
Merge pull request #504 from nschloe/tables-fixes
Tables fixes
2 parents b02c60a + f03c83d commit 95459b9

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = tikzplotlib
3-
version = 0.9.11
3+
version = 0.9.12
44
author = Nico Schlömer
55
author_email = [email protected]
66
description = Convert matplotlib figures into TikZ/PGFPlots

src/tikzplotlib/_line2d.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,6 @@ def _table(obj, data): # noqa: C901
263263
# don't want the \n in the table definition, just in the data (below)
264264
opts.append("row sep=" + data["table_row_sep"].strip())
265265

266-
if data["externalize tables"] and data["externals search path"] is not None:
267-
esp = data["externals search path"]
268-
opts.append(f"search path={{{esp}}}")
269-
270-
if len(opts) > 0:
271-
opts_str = ",".join(opts)
272-
content.append(f"table [{opts_str}] {{")
273-
else:
274-
content.append("table {")
275-
276-
plot_table = []
277266
table_row_sep = data["table_row_sep"]
278267
ydata[ydata_mask] = np.nan
279268
if np.any(ydata_mask) or ~np.all(np.isfinite(ydata)):
@@ -283,18 +272,34 @@ def _table(obj, data): # noqa: C901
283272
if "unbounded coords=jump" not in data["current axes"].axis_options:
284273
data["current axes"].axis_options.append("unbounded coords=jump")
285274

286-
for x, y in zip(xdata, ydata):
287-
plot_table.append(f"{x:{xformat}}{col_sep}{y:{ff}}{table_row_sep}")
275+
plot_table = [
276+
f"{x:{xformat}}{col_sep}{y:{ff}}{table_row_sep}" for x, y in zip(xdata, ydata)
277+
]
278+
279+
min_extern_length = 3
288280

289-
if data["externalize tables"]:
281+
if data["externalize tables"] and len(xdata) >= min_extern_length:
290282
filepath, rel_filepath = _files.new_filepath(data, "table", ".dat")
291283
with open(filepath, "w") as f:
292284
# No encoding handling required: plot_table is only ASCII
293285
f.write("".join(plot_table))
294-
content.append(str(rel_filepath))
286+
287+
if data["externals search path"] is not None:
288+
esp = data["externals search path"]
289+
opts.append(f"search path={{{esp}}}")
290+
291+
if len(opts) > 0:
292+
opts_str = ",".join(opts)
293+
content.append(f"table [{opts_str}] {{{rel_filepath}}};\n")
294+
else:
295+
content.append(f"table {{{rel_filepath}}};\n")
295296
else:
296-
content.append("%\n")
297+
if len(opts) > 0:
298+
opts_str = ",".join(opts)
299+
content.append(f"table [{opts_str}] {{%\n")
300+
else:
301+
content.append("table {%\n")
297302
content.extend(plot_table)
303+
content.append("};\n")
298304

299-
content.append("};\n")
300305
return content, axis_options

src/tikzplotlib/_save.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def get_tikz_code(
218218
code = """"""
219219

220220
if include_disclaimer:
221-
disclaimer = f"This file was created by tikzplotlib v{__version__}."
221+
disclaimer = f"This file was created with tikzplotlib v{__version__}."
222222
code += _tex_comment(disclaimer)
223223

224224
# write the contents

0 commit comments

Comments
 (0)