Skip to content

Commit f7f1044

Browse files
committed
more f-strings
1 parent 01d3725 commit f7f1044

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

tikzplotlib/_axes.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,14 @@ def __init__(self, data, obj): # noqa: C901
5353
xlabel = _common_texification(xlabel)
5454
self.axis_options.append(f"xlabel={{{xlabel}}}")
5555
if xrotation != 0:
56-
self.axis_options.append(
57-
"xlabel style={{rotate={}}}".format(xrotation - 90)
58-
)
56+
self.axis_options.append("xlabel style={{rotate={xrotation - 90)}}}")
5957
ylabel = obj.get_ylabel()
6058
yrotation = obj.yaxis.get_label().get_rotation()
6159
if ylabel:
6260
ylabel = _common_texification(ylabel)
6361
self.axis_options.append(f"ylabel={{{ylabel}}}")
6462
if yrotation != 90:
65-
self.axis_options.append(
66-
"ylabel style={{rotate={}}}".format(yrotation - 90)
67-
)
63+
self.axis_options.append("ylabel style={{rotate={yrotation - 90}}}")
6864

6965
# Axes limits.
7066
ff = data["float format"]
@@ -419,7 +415,7 @@ def _subplot(self, obj, data):
419415
# subplotspec geometry positioning is 0-based
420416
self.subplot_index = geom[2] + 1
421417
if "is_in_groupplot_env" not in data or not data["is_in_groupplot_env"]:
422-
group_style = ["group size={} by {}".format(geom[1], geom[0])]
418+
group_style = [f"group size={geom[1]} by {geom[0]}"]
423419
group_style.extend(data["extra groupstyle options [base]"])
424420
options = ["group style={{{}}}".format(", ".join(group_style))]
425421
self.content.append(
@@ -462,12 +458,12 @@ def _get_label_rotation_and_horizontal_alignment(self, obj, data, x_or_y):
462458
values = []
463459

464460
if any(tick_labels_rotation) != 0:
465-
values.append("rotate={}".format(tick_labels_rotation[0]))
461+
values.append(f"rotate={tick_labels_rotation[0]}")
466462

467463
# Horizontal alignment will be ignored if no 'x/y tick label text width' has
468464
# been passed in the 'extra' parameter
469465
if tick_label_text_width:
470-
values.append("align={}".format(tick_labels_horizontal_alignment[0]))
466+
values.append(f"align={tick_labels_horizontal_alignment[0]}")
471467
values.append(f"text width={tick_label_text_width}")
472468

473469
if values:
@@ -478,7 +474,7 @@ def _get_label_rotation_and_horizontal_alignment(self, obj, data, x_or_y):
478474
values = []
479475

480476
if tick_labels_rotation_same_value:
481-
values.append("rotate={}".format(tick_labels_rotation[0]))
477+
values.append("rotate={tick_labels_rotation[0]}")
482478
else:
483479
values.append(
484480
"rotate={{{},0}}[\\ticknum]".format(
@@ -490,20 +486,14 @@ def _get_label_rotation_and_horizontal_alignment(self, obj, data, x_or_y):
490486
# passed in the 'extra' parameter
491487
if tick_label_text_width:
492488
if tick_labels_horizontal_alignment_same_value:
493-
values.append(
494-
"align={}".format(tick_labels_horizontal_alignment[0])
495-
)
489+
values.append(f"align={tick_labels_horizontal_alignment[0]}")
496490
values.append(f"text width={tick_label_text_width}")
497491
else:
498492
for idx, x in enumerate(tick_labels_horizontal_alignment):
499-
label_style += "{}_tick_label_ha_{}/.initial = {}".format(
500-
x_or_y, idx, x
501-
)
493+
label_style += f"{x_or_y}_tick_label_ha_{idx}/.initial = {x}"
502494

503495
values.append(
504-
"align=\\pgfkeysvalueof{{/pgfplots/{}_tick_label_ha_\\ticknum}}".format(
505-
x_or_y
506-
)
496+
f"align=\\pgfkeysvalueof{{/pgfplots/{x_or_y}_tick_label_ha_\\ticknum}}"
507497
)
508498
values.append(f"text width={tick_label_text_width}")
509499

@@ -777,10 +767,8 @@ def _handle_listed_color_map(cmap, data):
777767
reps = int(float(cmap.N) / len(cmap.colors) - 0.5) + 1
778768
repeated_cols = reps * cmap.colors
779769
colors = [
780-
("rgb({}{})=(" + ff + "," + ff + "," + ff + ")").format(
781-
k, unit, rgb[0], rgb[1], rgb[2]
782-
)
783-
for (k, rgb) in enumerate(repeated_cols[: cmap.N])
770+
"rgb({k}{unit})=({rgb[0]:{ff}},{rgb[1]:{ff}},{rgb[2]:{ff}})"
771+
for k, rgb in enumerate(repeated_cols[: cmap.N])
784772
]
785773
colormap_string = "{{mymap}}{{[1{}]\n {}\n}}".format(unit, ";\n ".join(colors))
786774
is_custom_colormap = True

tikzplotlib/_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
def _gen_filename(data, nb_key, ext):
6-
name = data["base name"] + "-{:03d}{}".format(data[nb_key], ext)
6+
name = data["base name"] + f"-{data[nb_key]:03d}{ext}"
77
return os.path.join(data["output dir"], name), name
88

99

0 commit comments

Comments
 (0)