Skip to content

Commit 8b4bfb3

Browse files
committed
Issue #298; "table_row_sep" option was not working properly; the separator was used generating the table,
but the table setting itself was not adjusted to include the updated setting because the code to do so was nested in an (unrelated) conditional. Further, the code in that unrelated conditional used the wrong key value anyway. Resolved by moving check outside unrelated conditional, fixed broken key, strip trailing newline in table declaration. Added test cases to check both with and without the separator (note there are test failures, but they were failing before I made any changes; failures remain the same after my change).
1 parent aee7a4f commit 8b4bfb3

File tree

4 files changed

+96
-3
lines changed

4 files changed

+96
-3
lines changed

test/test_table_row_sep.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import matplotlib.pyplot as plt
2+
3+
from helpers import assert_equality
4+
5+
6+
def plot():
7+
a = [pow(10, i) for i in range(10)]
8+
fig = plt.figure()
9+
ax = fig.add_subplot(1, 1, 1)
10+
ax.semilogy(a, color="blue", lw=0.25)
11+
12+
plt.grid(b=True, which="major", color="g", linestyle="-", linewidth=0.25)
13+
plt.grid(b=True, which="minor", color="r", linestyle="--", linewidth=0.5)
14+
return fig
15+
16+
17+
def test():
18+
assert_equality(plot, __file__[:-3] + "_reference.tex", table_row_sep='\\\\\n')
19+
assert_equality(plot, __file__[:-3] + "_reference2.tex")
20+
return

test/test_table_row_sep_reference.tex

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
\begin{tikzpicture}
2+
3+
\begin{axis}[
4+
log basis y={10},
5+
tick align=outside,
6+
tick pos=left,
7+
x grid style={green!50.0!black},
8+
xmajorgrids,
9+
xmin=-0.45, xmax=9.45,
10+
xminorgrids,
11+
xtick style={color=black},
12+
y grid style={green!50.0!black},
13+
ymajorgrids,
14+
ymin=0.354813389233575, ymax=2818382931.26445,
15+
yminorgrids,
16+
ymode=log,
17+
ytick style={color=black}
18+
]
19+
\addplot [ultra thin, blue]
20+
table [row sep=\\] {%
21+
0 1\\
22+
1 10\\
23+
2 100\\
24+
3 1000\\
25+
4 10000\\
26+
5 100000\\
27+
6 1000000\\
28+
7 10000000\\
29+
8 100000000\\
30+
9 1000000000\\
31+
};
32+
\end{axis}
33+
34+
\end{tikzpicture}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
\begin{tikzpicture}
2+
3+
\begin{axis}[
4+
log basis y={10},
5+
tick align=outside,
6+
tick pos=left,
7+
x grid style={green!50.0!black},
8+
xmajorgrids,
9+
xmin=-0.45, xmax=9.45,
10+
xminorgrids,
11+
xtick style={color=black},
12+
y grid style={green!50.0!black},
13+
ymajorgrids,
14+
ymin=0.354813389233575, ymax=2818382931.26445,
15+
yminorgrids,
16+
ymode=log,
17+
ytick style={color=black}
18+
]
19+
\addplot [ultra thin, blue]
20+
table {%
21+
0 1
22+
1 10
23+
2 100
24+
3 1000
25+
4 10000
26+
5 100000
27+
6 1000000
28+
7 10000000
29+
8 100000000
30+
9 1000000000
31+
};
32+
\end{axis}
33+
34+
\end{tikzpicture}

tikzplotlib/line2d.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,6 @@ def _table(obj, data):
303303
xformat = "{}"
304304
col_sep = ","
305305
opts = ["header=false", "col sep=comma"]
306-
if data["table_row_sep"] != "\n":
307-
opts.append("row sep=" + data["table row sep"])
308-
content.append("table [{}] {{%\n".format(",".join(opts)))
309306
data["current axes"].axis_options.append("date coordinates in=x")
310307
# Replace float xmin/xmax by datetime
311308
# <https://github.com/matplotlib/matplotlib/issues/13727>.
@@ -322,8 +319,16 @@ def _table(obj, data):
322319
)
323320
)
324321
else:
322+
opts = []
325323
xformat = ff
326324
col_sep = " "
325+
326+
if data["table_row_sep"] != "\n":
327+
# don't want the \n in the table definition, just in the data (below)
328+
opts.append("row sep=" + data["table_row_sep"].strip())
329+
if len(opts) > 0:
330+
content.append("table [{}] {{%\n".format(",".join(opts)))
331+
else:
327332
content.append("table {%\n")
328333

329334
plot_table = []

0 commit comments

Comments
 (0)