Skip to content

Commit

Permalink
Merge pull request #504 from nschloe/tables-fixes
Browse files Browse the repository at this point in the history
Tables fixes
  • Loading branch information
nschloe authored Aug 11, 2021
2 parents b02c60a + f03c83d commit 95459b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = tikzplotlib
version = 0.9.11
version = 0.9.12
author = Nico Schlömer
author_email = [email protected]
description = Convert matplotlib figures into TikZ/PGFPlots
Expand Down
39 changes: 22 additions & 17 deletions src/tikzplotlib/_line2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,6 @@ def _table(obj, data): # noqa: C901
# don't want the \n in the table definition, just in the data (below)
opts.append("row sep=" + data["table_row_sep"].strip())

if data["externalize tables"] and data["externals search path"] is not None:
esp = data["externals search path"]
opts.append(f"search path={{{esp}}}")

if len(opts) > 0:
opts_str = ",".join(opts)
content.append(f"table [{opts_str}] {{")
else:
content.append("table {")

plot_table = []
table_row_sep = data["table_row_sep"]
ydata[ydata_mask] = np.nan
if np.any(ydata_mask) or ~np.all(np.isfinite(ydata)):
Expand All @@ -283,18 +272,34 @@ def _table(obj, data): # noqa: C901
if "unbounded coords=jump" not in data["current axes"].axis_options:
data["current axes"].axis_options.append("unbounded coords=jump")

for x, y in zip(xdata, ydata):
plot_table.append(f"{x:{xformat}}{col_sep}{y:{ff}}{table_row_sep}")
plot_table = [
f"{x:{xformat}}{col_sep}{y:{ff}}{table_row_sep}" for x, y in zip(xdata, ydata)
]

min_extern_length = 3

if data["externalize tables"]:
if data["externalize tables"] and len(xdata) >= min_extern_length:
filepath, rel_filepath = _files.new_filepath(data, "table", ".dat")
with open(filepath, "w") as f:
# No encoding handling required: plot_table is only ASCII
f.write("".join(plot_table))
content.append(str(rel_filepath))

if data["externals search path"] is not None:
esp = data["externals search path"]
opts.append(f"search path={{{esp}}}")

if len(opts) > 0:
opts_str = ",".join(opts)
content.append(f"table [{opts_str}] {{{rel_filepath}}};\n")
else:
content.append(f"table {{{rel_filepath}}};\n")
else:
content.append("%\n")
if len(opts) > 0:
opts_str = ",".join(opts)
content.append(f"table [{opts_str}] {{%\n")
else:
content.append("table {%\n")
content.extend(plot_table)
content.append("};\n")

content.append("};\n")
return content, axis_options
2 changes: 1 addition & 1 deletion src/tikzplotlib/_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def get_tikz_code(
code = """"""

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

# write the contents
Expand Down

0 comments on commit 95459b9

Please sign in to comment.