Skip to content

Commit eaaccdf

Browse files
committed
more f-strings
1 parent 036bf7d commit eaaccdf

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

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/_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

0 commit comments

Comments
 (0)