Skip to content

Commit 433b649

Browse files
committed
respect float format everywhere
1 parent 8f0b708 commit 433b649

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

tikzplotlib/_color.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def mpl_color2xcolor(data, matplotlib_color):
6767
# The cases 0.0 (my_col == black) and 1.0 (my_col == rgb) are
6868
# already accounted for by checking in available_colors above.
6969
if all(my_col[:3] == alpha * rgb) and 0.0 < alpha < 1.0:
70-
xcol = name + ("!{}!black".format(alpha * 100))
70+
ff = data["float format"]
71+
xcol = name + (f"!{ff}!black".format(alpha * 100))
7172
return data, xcol, my_col
7273

7374
# Lookup failed, add it to the custom list.

tikzplotlib/_line2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def draw_line2d(data, obj):
5454
if alpha is not None:
5555
addplot_options.append(f"opacity={alpha}")
5656

57-
linestyle = mypath.mpl_linestyle2pgfplots_linestyle(obj.get_linestyle(), line=obj)
57+
linestyle = mypath.mpl_linestyle2pgfplots_linestyle(data, obj.get_linestyle(), line=obj)
5858
if linestyle is not None and linestyle != "solid":
5959
addplot_options.append(linestyle)
6060

tikzplotlib/_path.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def get_draw_options(data, obj, ec, fc, ls, lw, hatch=None):
305305
draw_options.append(lw_)
306306

307307
if ls is not None:
308-
ls_ = mpl_linestyle2pgfplots_linestyle(ls)
308+
ls_ = mpl_linestyle2pgfplots_linestyle(data, ls)
309309
if ls_ is not None and ls_ != "solid":
310310
draw_options.append(ls_)
311311

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

357358
# The following is an alternative approach to line widths.
358359
# The default line width in matplotlib is 1.0pt, in PGFPlots 0.4pt
@@ -371,12 +372,13 @@ def mpl_linewidth2pgfp_linewidth(data, line_width):
371372
}[scaled_line_width]
372373
except KeyError:
373374
# explicit line width
374-
out = "line width={}pt".format(0.4 * line_width)
375+
ff = data["float format"]
376+
out = f"line width={ff}pt".format(0.4 * line_width)
375377

376378
return out
377379

378380

379-
def mpl_linestyle2pgfplots_linestyle(line_style, line=None):
381+
def mpl_linestyle2pgfplots_linestyle(data, line_style, line=None):
380382
"""Translates a line style of matplotlib to the corresponding style
381383
in PGFPlots.
382384
"""
@@ -388,15 +390,19 @@ def mpl_linestyle2pgfplots_linestyle(line_style, line=None):
388390
# dashed: (0, (6.0, 6.0))
389391
# dotted: (0, (1.0, 3.0))
390392
# dashdot: (0, (3.0, 5.0, 1.0, 5.0))
393+
ff = data["float format"]
391394
if isinstance(line_style, tuple):
392395
if line_style[0] is None:
393396
return None
394397

395398
if len(line_style[1]) == 2:
396-
return "dash pattern=on {}pt off {}pt".format(*line_style[1])
399+
fmt = f"dash pattern=on {ff}pt off {ff}pt"
400+
print(fmt, type(fmt))
401+
return fmt.format(*line_style[1])
397402

398403
assert len(line_style[1]) == 4
399-
return "dash pattern=on {}pt off {}pt on {}pt off {}pt".format(*line_style[1])
404+
fmt = f"dash pattern=on {ff}pt off {ff}pt on {ff}pt off {ff}pt"
405+
return fmt.format(*line_style[1])
400406

401407
if isinstance(line, mpl.lines.Line2D) and line.is_dashed():
402408
# see matplotlib.lines.Line2D.set_dashes
@@ -411,7 +417,7 @@ def mpl_linestyle2pgfplots_linestyle(line_style, line=None):
411417
lst = list()
412418
if dashSeq != default_dashSeq:
413419
# generate own dash sequence
414-
format_string = " ".join(len(dashSeq) // 2 * ["on {}pt off {}pt"])
420+
format_string = " ".join(len(dashSeq) // 2 * [f"on {ff}pt off {ff}pt"])
415421
lst.append("dash pattern=" + format_string.format(*dashSeq))
416422

417423
if dashOffset != default_dashOffset:

0 commit comments

Comments
 (0)