Skip to content

Commit 6a3f6bf

Browse files
committed
better line widths
1 parent 89137bc commit 6a3f6bf

File tree

1 file changed

+17
-34
lines changed

1 file changed

+17
-34
lines changed

src/tikzplotlib/_path.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -407,44 +407,27 @@ def get_draw_options(data, obj, ec, fc, ls, lw, hatch=None):
407407

408408

409409
def mpl_linewidth2pgfp_linewidth(data, line_width):
410-
if data["strict"]:
411-
# Takes the matplotlib linewidths, and just translate them into PGFPlots.
412-
try:
413-
return {
414-
0.1: "ultra thin",
415-
0.2: "very thin",
416-
0.4: "thin",
417-
0.6: "semithick",
418-
0.8: "thick",
419-
1.2: "very thick",
420-
1.6: "ultra thick",
421-
}[line_width]
422-
except KeyError:
423-
# explicit line width
424-
ff = data["float format"]
425-
return f"line width={line_width:{ff}}pt"
426-
427-
# The following is an alternative approach to line widths.
428-
# The default line width in matplotlib is 1.0pt, in PGFPlots 0.4pt
429-
# ('thin').
430-
# Match the two defaults, and scale for the rest.
431-
scaled_line_width = line_width / 1.0 # scale by default line width
410+
# PGFplots gives line widths in pt, matplotlib in axes space. Translate.
411+
# Scale such that the default mpl line width (1.5) is mapped to the PGFplots
412+
# line with semithick, 0.6. From a visual comparison, semithick or even thick
413+
# matches best with the default mpl style.
414+
# Keep the line with in units of decipoint to make sure we stay in integers.
415+
line_width_decipoint = line_width * 4 # 4 = 10 * 0.6 / 1.5
432416
try:
433-
out = {
434-
0.25: "ultra thin",
435-
0.5: "very thin",
436-
1.0: None, # default, 'thin'
437-
1.5: "semithick",
438-
2: "thick",
439-
3: "very thick",
440-
4: "ultra thick",
441-
}[scaled_line_width]
417+
# https://github.com/pgf-tikz/pgf/blob/e9c22dc9fe48f975b7fdb32181f03090b3747499/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex#L1574
418+
return {
419+
1: "ultra thin",
420+
2: "very thin",
421+
4: None, # "thin",
422+
6: "semithick",
423+
8: "thick",
424+
12: "very thick",
425+
16: "ultra thick",
426+
}[line_width_decipoint]
442427
except KeyError:
443428
# explicit line width
444429
ff = data["float format"]
445-
out = f"line width={0.4 * line_width:{ff}}pt"
446-
447-
return out
430+
return f"line width={line_width_decipoint / 10:{ff}}pt"
448431

449432

450433
def mpl_linestyle2pgfplots_linestyle(data, line_style, line=None):

0 commit comments

Comments
 (0)