Skip to content

Commit c7129c3

Browse files
committed
use f-strings, require python 3.6
1 parent 73018a8 commit c7129c3

File tree

9 files changed

+44
-44
lines changed

9 files changed

+44
-44
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
long_description=open("README.md").read(),
2222
long_description_content_type="text/markdown",
2323
license=about["__license__"],
24-
python_requires=">=3",
24+
python_requires=">=3.6",
2525
classifiers=[
2626
about["__status__"],
2727
about["__license__"],

tikzplotlib/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__author__ = "Nico Schlömer"
22
__email__ = "[email protected]"
3-
__copyright__ = "Copyright (c) 2010-2020, {} <{}>".format(__author__, __email__)
3+
__copyright__ = f"Copyright (c) 2010-2020, {__author__} <{__email__}>"
44
__license__ = "License :: OSI Approved :: MIT License"
55
__version__ = "0.8.7"
66
__status__ = "Development Status :: 5 - Production/Stable"

tikzplotlib/_axes.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ def __init__(self, data, obj): # noqa: C901
4444
data["current axis title"] = title
4545
if title:
4646
title = _common_texification(title)
47-
self.axis_options.append("title={{{}}}".format(title))
47+
self.axis_options.append(f"title={{{title}}}")
4848

4949
# get axes titles
5050
xlabel = obj.get_xlabel()
5151
xrotation = obj.xaxis.get_label().get_rotation()
5252
if xlabel:
5353
xlabel = _common_texification(xlabel)
54-
self.axis_options.append("xlabel={{{}}}".format(xlabel))
54+
self.axis_options.append(f"xlabel={{{xlabel}}}")
5555
if xrotation != 0:
5656
self.axis_options.append(
5757
"xlabel style={{rotate={}}}".format(xrotation - 90)
@@ -60,7 +60,7 @@ def __init__(self, data, obj): # noqa: C901
6060
yrotation = obj.yaxis.get_label().get_rotation()
6161
if ylabel:
6262
ylabel = _common_texification(ylabel)
63-
self.axis_options.append("ylabel={{{}}}".format(ylabel))
63+
self.axis_options.append(f"ylabel={{{ylabel}}}")
6464
if yrotation != 90:
6565
self.axis_options.append(
6666
"ylabel style={{rotate={}}}".format(yrotation - 90)
@@ -131,14 +131,14 @@ def __init__(self, data, obj): # noqa: C901
131131
axcol = obj.spines["bottom"].get_edgecolor()
132132
data, col, _ = _color.mpl_color2xcolor(data, axcol)
133133
if col != "black":
134-
self.axis_options.append("axis line style={{{}}}".format(col))
134+
self.axis_options.append(f"axis line style={{{col}}}")
135135

136136
# background color
137137
bgcolor = obj.get_facecolor()
138138

139139
data, col, _ = _color.mpl_color2xcolor(data, bgcolor)
140140
if col != "white":
141-
self.axis_options.append("axis background/.style={{fill={}}}".format(col))
141+
self.axis_options.append(f"axis background/.style={{fill={col}}}")
142142

143143
# find color bar
144144
colorbar = _find_associated_colorbar(obj)
@@ -229,7 +229,7 @@ def _ticks(self, data, obj):
229229
else:
230230
c0 = l0.get_color()
231231
data, xtickcolor, _ = _color.mpl_color2xcolor(data, c0)
232-
self.axis_options.append("xtick style={{color={}}}".format(xtickcolor))
232+
self.axis_options.append(f"xtick style={{color={xtickcolor}}}")
233233

234234
try:
235235
l0 = obj.get_yticklines()[0]
@@ -238,7 +238,7 @@ def _ticks(self, data, obj):
238238
else:
239239
c0 = l0.get_color()
240240
data, ytickcolor, _ = _color.mpl_color2xcolor(data, c0)
241-
self.axis_options.append("ytick style={{color={}}}".format(ytickcolor))
241+
self.axis_options.append(f"ytick style={{color={ytickcolor}}}")
242242

243243
# Find tick direction
244244
# For new matplotlib versions, we could replace the direction getter by
@@ -286,7 +286,7 @@ def _ticks(self, data, obj):
286286
y_tick_position_string, y_tick_position = _get_tick_position(obj, "y")
287287

288288
if x_tick_position == y_tick_position and x_tick_position is not None:
289-
self.axis_options.append("tick pos={}".format(x_tick_position))
289+
self.axis_options.append(f"tick pos={x_tick_position}")
290290
else:
291291
self.axis_options.append(x_tick_position_string)
292292
self.axis_options.append(y_tick_position_string)
@@ -307,7 +307,7 @@ def _grid(self, obj, data):
307307
xgridcolor = xlines[0].get_color()
308308
data, col, _ = _color.mpl_color2xcolor(data, xgridcolor)
309309
if col != "black":
310-
self.axis_options.append("x grid style={{{}}}".format(col))
310+
self.axis_options.append(f"x grid style={{{col}}}")
311311

312312
if obj.yaxis._gridOnMajor:
313313
self.axis_options.append("ymajorgrids")
@@ -319,7 +319,7 @@ def _grid(self, obj, data):
319319
ygridcolor = ylines[0].get_color()
320320
data, col, _ = _color.mpl_color2xcolor(data, ygridcolor)
321321
if col != "black":
322-
self.axis_options.append("y grid style={{{}}}".format(col))
322+
self.axis_options.append(f"y grid style={{{col}}}")
323323

324324
return
325325

@@ -435,7 +435,7 @@ def _subplot(self, obj, data):
435435

436436
def _get_label_rotation_and_horizontal_alignment(self, obj, data, x_or_y):
437437
tick_label_text_width = None
438-
tick_label_text_width_identifier = "{} tick label text width".format(x_or_y)
438+
tick_label_text_width_identifier = f"{x_or_y} tick label text width"
439439
if tick_label_text_width_identifier in self.axis_options:
440440
self.axis_options.remove(tick_label_text_width_identifier)
441441

@@ -473,7 +473,7 @@ def _get_label_rotation_and_horizontal_alignment(self, obj, data, x_or_y):
473473
# been passed in the 'extra' parameter
474474
if tick_label_text_width:
475475
values.append("align={}".format(tick_labels_horizontal_alignment[0]))
476-
values.append("text width={}".format(tick_label_text_width))
476+
values.append(f"text width={tick_label_text_width}")
477477

478478
if values:
479479
label_style = "{}ticklabel style = {{{}}}".format(
@@ -498,7 +498,7 @@ def _get_label_rotation_and_horizontal_alignment(self, obj, data, x_or_y):
498498
values.append(
499499
"align={}".format(tick_labels_horizontal_alignment[0])
500500
)
501-
values.append("text width={}".format(tick_label_text_width))
501+
values.append(f"text width={tick_label_text_width}")
502502
else:
503503
for idx, x in enumerate(tick_labels_horizontal_alignment):
504504
label_style += "{}_tick_label_ha_{}/.initial = {}".format(
@@ -510,7 +510,7 @@ def _get_label_rotation_and_horizontal_alignment(self, obj, data, x_or_y):
510510
x_or_y
511511
)
512512
)
513-
values.append("text width={}".format(tick_label_text_width))
513+
values.append(f"text width={tick_label_text_width}")
514514

515515
label_style = (
516516
"every {} tick label/.style = {{\n"
@@ -537,7 +537,7 @@ def _get_tick_position(obj, axes_obj):
537537

538538
major_ticks_position = None
539539
if not major_ticks_bottom_show_all and not major_ticks_top_show_all:
540-
position_string = "{}majorticks=false".format(axes_obj)
540+
position_string = f"{axes_obj}majorticks=false"
541541
elif major_ticks_bottom_show_all and major_ticks_top_show_all:
542542
major_ticks_position = "both"
543543
elif major_ticks_bottom_show_all:
@@ -546,7 +546,7 @@ def _get_tick_position(obj, axes_obj):
546546
major_ticks_position = "right"
547547

548548
if major_ticks_position:
549-
position_string = "{}tick pos={}".format(axes_obj, major_ticks_position)
549+
position_string = f"{axes_obj}tick pos={major_ticks_position}"
550550

551551
return position_string, major_ticks_position
552552

@@ -593,7 +593,7 @@ def _get_ticks(data, xy, ticks, ticklabels):
593593
)
594594
else:
595595
val = "{}" if "minor" in xy else "\\empty"
596-
axis_options.append("{}tick={}".format(xy, val))
596+
axis_options.append(f"{xy}tick={val}")
597597

598598
if is_label_required:
599599
axis_options.append(

tikzplotlib/_legend.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ def draw_legend(data, obj):
4949
("at={{(" + ff + "," + ff + ")}}").format(position[0], position[1])
5050
)
5151
if anchor:
52-
legend_style.append("anchor={}".format(anchor))
52+
legend_style.append(f"anchor={anchor}")
5353

5454
# Get the edgecolor of the box
5555
if obj.get_frame_on():
5656
edgecolor = obj.get_frame().get_edgecolor()
5757
data, frame_xcolor, _ = mycol.mpl_color2xcolor(data, edgecolor)
5858
if frame_xcolor != "black": # black is default
59-
legend_style.append("draw={}".format(frame_xcolor))
59+
legend_style.append(f"draw={frame_xcolor}")
6060
else:
6161
legend_style.append("draw=none")
6262

6363
# Get the facecolor of the box
6464
facecolor = obj.get_frame().get_facecolor()
6565
data, fill_xcolor, _ = mycol.mpl_color2xcolor(data, facecolor)
6666
if fill_xcolor != "white": # white is default
67-
legend_style.append("fill={}".format(fill_xcolor))
67+
legend_style.append(f"fill={fill_xcolor}")
6868

6969
# Get the horizontal alignment
7070
try:
@@ -80,11 +80,11 @@ def draw_legend(data, obj):
8080

8181
if alignment:
8282
data["current axes"].axis_options.append(
83-
"legend cell align={{{}}}".format(alignment)
83+
f"legend cell align={{{alignment}}}"
8484
)
8585

8686
if obj._ncol != 1:
87-
data["current axes"].axis_options.append("legend columns={}".format(obj._ncol))
87+
data["current axes"].axis_options.append(f"legend columns={obj._ncol}")
8888

8989
# Write styles to data
9090
if legend_style:

tikzplotlib/_line2d.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ def draw_line2d(data, obj):
4848
style = "const plot mark right"
4949
elif drawstyle == "steps-post":
5050
style = "const plot mark left"
51-
addplot_options.append("{}".format(style))
51+
addplot_options.append(f"{style}")
5252

5353
alpha = obj.get_alpha()
5454
if alpha is not None:
55-
addplot_options.append("opacity={}".format(alpha))
55+
addplot_options.append(f"opacity={alpha}")
5656

5757
linestyle = mypath.mpl_linestyle2pgfplots_linestyle(obj.get_linestyle(), line=obj)
5858
if linestyle is not None and linestyle != "solid":
@@ -93,7 +93,7 @@ def draw_line2d(data, obj):
9393
content += c
9494

9595
if legend_text is not None:
96-
content.append("\\addlegendentry{{{}}}\n".format(legend_text))
96+
content.append(f"\\addlegendentry{{{legend_text}}}\n")
9797

9898
return data, content
9999

@@ -143,12 +143,12 @@ def _marker(
143143
# make sure we didn't round off to zero by accident
144144
if pgf_size == 0 and mark_size != 0:
145145
pgf_size = 1
146-
addplot_options.append("mark size={:d}".format(pgf_size))
146+
addplot_options.append(f"mark size={pgf_size:d}")
147147

148148
mark_every = obj.get_markevery()
149149
if mark_every:
150150
if type(mark_every) is int:
151-
addplot_options.append("mark repeat={:d}".format(mark_every))
151+
addplot_options.append(f"mark repeat={mark_every:d}")
152152
else:
153153
# python starts at index 0, pgfplots at index 1
154154
pgf_marker = [1 + m for m in mark_every]

tikzplotlib/_patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _draw_rectangle(data, obj, draw_options):
149149
cont += "\\addlegendimage{{ybar,ybar legend,{}}};\n".format(
150150
",".join(draw_options)
151151
)
152-
cont += "\\addlegendentry{{{}}}\n\n".format(label)
152+
cont += f"\\addlegendentry{{{label}}}\n\n"
153153
return data, cont
154154

155155

tikzplotlib/_path.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def draw_pathcollection(data, obj):
202202
data, pgfplots_marker, marker_options = _mpl_marker2pgfp_marker(
203203
data, marker0, fc
204204
)
205-
draw_options += ["marker={}".format(pgfplots_marker)] + marker_options
205+
draw_options += [f"marker={pgfplots_marker}"] + marker_options
206206

207207
# `only mark` plots don't need linewidth
208208
data, extra_draw_options = get_draw_options(data, obj, ec, fc, ls, None)
@@ -236,10 +236,10 @@ def draw_pathcollection(data, obj):
236236
)
237237

238238
do = " [{}]".format(", ".join(draw_options)) if draw_options else ""
239-
content.append("\\addplot{}\n".format(do))
239+
content.append(f"\\addplot{do}\n")
240240

241241
to = " [{}]".format(", ".join(table_options)) if table_options else ""
242-
content.append("table{}{{%\n".format(to))
242+
content.append(f"table{to}{{%\n")
243243

244244
content.append((" ".join(labels)).strip() + "\n")
245245
ff = data["float format"]
@@ -249,7 +249,7 @@ def draw_pathcollection(data, obj):
249249
content.append("};\n")
250250

251251
if legend_text is not None:
252-
content.append("\\addlegendentry{{{}}}\n".format(legend_text))
252+
content.append(f"\\addlegendentry{{{legend_text}}}\n")
253253

254254
return data, content
255255

@@ -274,15 +274,15 @@ def get_draw_options(data, obj, ec, fc, ls, lw, hatch=None):
274274
if ec is not None:
275275
data, ec_col, ec_rgba = _color.mpl_color2xcolor(data, ec)
276276
if ec_rgba[3] > 0:
277-
draw_options.append("draw={}".format(ec_col))
277+
draw_options.append(f"draw={ec_col}")
278278
else:
279279
draw_options.append("draw=none")
280280

281281
if fc is not None:
282282
data, fc_col, fc_rgba = _color.mpl_color2xcolor(data, fc)
283283
if fc_rgba[3] > 0.0:
284284
# Don't draw if it's invisible anyways.
285-
draw_options.append("fill={}".format(fc_col))
285+
draw_options.append(f"fill={fc_col}")
286286

287287
# handle transparency
288288
ff = data["float format"]
@@ -352,7 +352,7 @@ def mpl_linewidth2pgfp_linewidth(data, line_width):
352352
}[line_width]
353353
except KeyError:
354354
# explicit line width
355-
return "line width={}pt".format(line_width)
355+
return f"line width={line_width}pt"
356356

357357
# The following is an alternative approach to line widths.
358358
# The default line width in matplotlib is 1.0pt, in PGFPlots 0.4pt
@@ -415,7 +415,7 @@ def mpl_linestyle2pgfplots_linestyle(line_style, line=None):
415415
lst.append("dash pattern=" + format_string.format(*dashSeq))
416416

417417
if dashOffset != default_dashOffset:
418-
lst.append("dash phase={}pt".format(dashOffset))
418+
lst.append(f"dash phase={dashOffset}pt")
419419

420420
if len(lst) > 0:
421421
return ", ".join(lst)

tikzplotlib/_save.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def get_tikz_code(
202202
code = """"""
203203

204204
if include_disclaimer:
205-
disclaimer = "This file was created by tikzplotlib v{}.".format(__version__)
205+
disclaimer = f"This file was created by tikzplotlib v{__version__}."
206206
code += _tex_comment(disclaimer)
207207

208208
# write the contents

tikzplotlib/_text.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def draw_text(data, obj):
6262
if anchor is not None:
6363
properties.append(anchor)
6464
data, col, _ = _color.mpl_color2xcolor(data, converter.to_rgb(obj.get_color()))
65-
properties.append("text={}".format(col))
65+
properties.append(f"text={col}")
6666
properties.append("rotate={:.1f}".format(obj.get_rotation()))
6767

6868
if obj.get_style() == "italic":
@@ -108,7 +108,7 @@ def draw_text(data, obj):
108108

109109
if "\n" in text:
110110
# http://tex.stackexchange.com/a/124114/13262
111-
properties.append("align={}".format(ha))
111+
properties.append(f"align={ha}")
112112
# Manipulating the text here is actually against mpl2tikz's policy not
113113
# to do that. On the other hand, newlines should translate into
114114
# newlines.
@@ -187,7 +187,7 @@ def _get_arrow_style(obj, data):
187187
try:
188188
style = arrow_translate[style_cls]
189189
except KeyError:
190-
raise NotImplementedError("Unknown arrow style {}".format(style_cls))
190+
raise NotImplementedError(f"Unknown arrow style {style_cls}")
191191
else:
192192
data, col, _ = _color.mpl_color2xcolor(data, obj.get_ec())
193193
return style + ["draw=" + col]
@@ -231,10 +231,10 @@ def _bbox(bbox, data, properties, scaling):
231231
if bbox.get_fill():
232232
data, fc, _ = _color.mpl_color2xcolor(data, bbox.get_facecolor())
233233
if fc:
234-
properties.append("fill={}".format(fc))
234+
properties.append(f"fill={fc}")
235235
data, ec, _ = _color.mpl_color2xcolor(data, bbox.get_edgecolor())
236236
if ec:
237-
properties.append("draw={}".format(ec))
237+
properties.append(f"draw={ec}")
238238
# XXX: This is ugly, too
239239
ff = data["float format"]
240240
properties.append(("line width=" + ff + "pt").format(bbox.get_lw() * 0.4))

0 commit comments

Comments
 (0)