Skip to content

Commit 538e1c0

Browse files
authored
Merge pull request #494 from nschloe/redudant-semicolon
Redundant semicolon
2 parents e30740a + de9dd4f commit 538e1c0

File tree

6 files changed

+24
-28
lines changed

6 files changed

+24
-28
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.8
3+
version = 0.9.9
44
author = Nico Schlömer
55
author_email = [email protected]
66
description = Convert matplotlib figures into TikZ/PGFPlots

src/tikzplotlib/_line2d.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ def draw_line2d(data, obj):
9393
# process options
9494
content.append("\\addplot ")
9595
if addplot_options:
96-
content.append("[{}]\n".format(", ".join(addplot_options)))
96+
opts = ", ".join(addplot_options)
97+
content.append(f"[{opts}]\n")
9798

9899
c, axis_options = _table(obj, data)
99100
content += c
@@ -182,9 +183,8 @@ def _marker(
182183
data, draw_xcolor, _ = mycol.mpl_color2xcolor(data, marker_edge_color)
183184
if draw_xcolor != line_xcolor:
184185
mark_options.append("draw=" + draw_xcolor)
185-
addplot_options.append("mark options={{{}}}".format(",".join(mark_options)))
186-
187-
return
186+
opts = ",".join(mark_options)
187+
addplot_options.append(f"mark options={{{opts}}}")
188188

189189

190190
def _table(obj, data): # noqa: C901

src/tikzplotlib/_patch.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ def _patch_legend(obj, draw_options, legend_type):
5555
if _is_in_legend(obj):
5656
# Unfortunately, patch legend entries need \addlegendimage in Pgfplots.
5757
do = ", ".join([legend_type] + draw_options) if draw_options else ""
58-
legend += "\\addlegendimage{{{}}}\n\\addlegendentry{{{}}}\n\n".format(
59-
do, obj.get_label()
60-
)
58+
label = obj.get_label()
59+
legend += f"\\addlegendimage{{{do}}}\n\\addlegendentry{{{label}}}\n\n"
6160

6261
return legend
6362

@@ -145,9 +144,8 @@ def _draw_rectangle(data, obj, draw_options):
145144

146145
if label != "_nolegend_" and label not in data["rectangle_legends"]:
147146
data["rectangle_legends"].add(label)
148-
cont += "\\addlegendimage{{ybar,ybar legend,{}}};\n".format(
149-
",".join(draw_options)
150-
)
147+
draw_opts = ",".join(draw_options)
148+
cont += f"\\addlegendimage{{ybar,ybar legend,{draw_opts}}}\n"
151149
cont += f"\\addlegendentry{{{label}}}\n\n"
152150
return data, cont
153151

src/tikzplotlib/_text.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,9 @@ def draw_text(data, obj):
118118
# We might want to remove this here in the future.
119119
text = text.replace("\n ", "\\\\")
120120

121-
content.append(
122-
"\\draw {pos} node[\n {props}\n]{{{text}}};\n".format(
123-
pos=tikz_pos, props=",\n ".join(properties), text=" ".join(style + [text])
124-
)
125-
)
121+
props = ",\n ".join(properties)
122+
text = " ".join(style + [text])
123+
content.append(f"\\draw {tikz_pos} node[\n {props}\n]{{{text}}};\n")
126124
return data, content
127125

128126

@@ -139,7 +137,8 @@ def _transform_positioning(ha, va):
139137
"center": "",
140138
"baseline": "base",
141139
}
142-
return "anchor={} {}".format(va_mpl_to_tikz[va], ha_mpl_to_tikz[ha]).strip()
140+
anchor = " ".join([va_mpl_to_tikz[va], ha_mpl_to_tikz[ha]]).strip()
141+
return f"anchor={anchor}"
143142

144143

145144
def _parse_annotation_coords(ff, coords, xy):
@@ -229,7 +228,7 @@ def _annotation(obj, data, content):
229228

230229
if obj.arrow_patch:
231230
style = ",".join(_get_arrow_style(obj.arrow_patch, data))
232-
the_arrow = ("\\draw[{}] {} -- {};\n").format(style, text_pos, xy_pos)
231+
the_arrow = f"\\draw[{style}] {text_pos} -- {xy_pos};\n"
233232
content.append(the_arrow)
234233
return text_pos
235234

@@ -285,12 +284,11 @@ def _bbox(bbox, data, properties, scaling):
285284
# pattern from matplotlib instead of hardcoding
286285
# an approximation?
287286
elif bbox.get_ls() == "dashdot":
287+
s1 = 1.0 / scaling
288+
s3 = 3.0 / scaling
289+
s6 = 6.0 / scaling
288290
properties.append(
289-
"dash pattern=on {:.3g}pt off {:.3g}pt on {:.3g}pt off {:.3g}pt".format(
290-
1.0 / scaling, 3.0 / scaling, 6.0 / scaling, 3.0 / scaling
291-
)
291+
f"dash pattern=on {s1:.3g}pt off {s3:.3g}pt on {s6:.3g}pt off {s3:.3g}pt"
292292
)
293293
else:
294294
assert bbox.get_ls() == "solid"
295-
296-
return

tests/test_barchart_legend_reference.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
ytick style={color=black}
1414
]
1515
\draw[draw=none,fill=blue] (axis cs:-0.375,0) rectangle (axis cs:-0.125,1);
16-
\addlegendimage{ybar,ybar legend,draw=none,fill=blue};
16+
\addlegendimage{ybar,ybar legend,draw=none,fill=blue}
1717
\addlegendentry{Data 1}
1818

1919
\draw[draw=none,fill=blue] (axis cs:0.625,0) rectangle (axis cs:0.875,2);
2020
\draw[draw=none,fill=blue] (axis cs:1.625,0) rectangle (axis cs:1.875,3);
2121
\draw[draw=none,fill=green!50!black] (axis cs:-0.125,0) rectangle (axis cs:0.125,3);
22-
\addlegendimage{ybar,ybar legend,draw=none,fill=green!50!black};
22+
\addlegendimage{ybar,ybar legend,draw=none,fill=green!50!black}
2323
\addlegendentry{Data 2}
2424

2525
\draw[draw=none,fill=green!50!black] (axis cs:0.875,0) rectangle (axis cs:1.125,2);
2626
\draw[draw=none,fill=green!50!black] (axis cs:1.875,0) rectangle (axis cs:2.125,4);
2727
\draw[draw=none,fill=red] (axis cs:0.125,0) rectangle (axis cs:0.375,5);
28-
\addlegendimage{ybar,ybar legend,draw=none,fill=red};
28+
\addlegendimage{ybar,ybar legend,draw=none,fill=red}
2929
\addlegendentry{Data 3}
3030

3131
\draw[draw=none,fill=red] (axis cs:1.125,0) rectangle (axis cs:1.375,3);

tests/test_histogram_reference.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
ytick style={color=black}
1717
]
1818
\draw[draw=none,fill=color0] (axis cs:3.53789,0) rectangle (axis cs:4.8984168,7);
19-
\addlegendimage{ybar,ybar legend,draw=none,fill=color0};
19+
\addlegendimage{ybar,ybar legend,draw=none,fill=color0}
2020
\addlegendentry{men}
2121

2222
\draw[draw=none,fill=color0] (axis cs:4.8984168,0) rectangle (axis cs:6.2589437,27);
@@ -29,7 +29,7 @@
2929
\draw[draw=none,fill=color0] (axis cs:14.422105,0) rectangle (axis cs:15.782632,7);
3030
\draw[draw=none,fill=color0] (axis cs:15.782632,0) rectangle (axis cs:17.143158,2);
3131
\draw[draw=none,fill=color1,fill opacity=0.5] (axis cs:0.59586541,0) rectangle (axis cs:2.5914912,2);
32-
\addlegendimage{ybar,ybar legend,draw=none,fill=color1,fill opacity=0.5};
32+
\addlegendimage{ybar,ybar legend,draw=none,fill=color1,fill opacity=0.5}
3333
\addlegendentry{women}
3434

3535
\draw[draw=none,fill=color1,fill opacity=0.5] (axis cs:2.5914912,0) rectangle (axis cs:4.587117,6);

0 commit comments

Comments
 (0)