Skip to content

Commit

Permalink
small fixes for tables
Browse files Browse the repository at this point in the history
  • Loading branch information
nschloe committed Aug 11, 2021
1 parent b02c60a commit dd6b9ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
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 dd6b9ee

Please sign in to comment.