Merge pull request #32124 from anntzer/figsize-mm · matplotlib/matplotlib@97193c6 · GitHub
Skip to content

Commit 97193c6

Browse files
authored
Merge pull request #32124 from anntzer/figsize-mm
Support millimeters as figsize unit.
2 parents 102c683 + 95d6e41 commit 97193c6

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

Lines changed: 4 additions & 0 deletions

lib/matplotlib/figure.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,7 @@ def __init__(self,
24882488
The figure dimensions. This can be
24892489
24902490
- a tuple ``(width, height, unit)``, where *unit* is one of "in" (inch),
2491-
"cm" (centimenter), "px" (pixel).
2491+
"cm" (centimenter), "mm" (millimeter), "px" (pixel).
24922492
- a tuple ``(width, height)``, which is interpreted in inches, i.e. as
24932493
``(width, height, "in")``.
24942494
@@ -3761,7 +3761,7 @@ def _parse_figsize(figsize, dpi):
37613761
This can be
37623762
37633763
- a tuple ``(width, height, unit)``, where *unit* is one of "in" (inch),
3764-
"cm" (centimenter), "px" (pixel).
3764+
"cm" (centimeter), "mm" (millimeter), "px" (pixel).
37653765
- a tuple ``(width, height)``, which is interpreted in inches, i.e. as
37663766
``(width, height, "in")``.
37673767
@@ -3780,6 +3780,11 @@ def _parse_figsize(figsize, dpi):
37803780
x /= 2.54
37813781
if y is not None:
37823782
y /= 2.54
3783+
elif unit == 'mm':
3784+
if x is not None:
3785+
x /= 25.4
3786+
if y is not None:
3787+
y /= 25.4
37833788
elif unit == 'px':
37843789
if x is not None:
37853790
x /= dpi
@@ -3788,7 +3793,7 @@ def _parse_figsize(figsize, dpi):
37883793
else:
37893794
raise ValueError(
37903795
f"Invalid unit {unit!r} in 'figsize'; "
3791-
"supported units are 'in', 'cm', 'px'"
3796+
"supported units are 'in', 'cm', 'mm', 'px'"
37923797
)
37933798
else:
37943799
raise ValueError(

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def figure(
948948
The figure dimensions. This can be
949949
950950
- a tuple ``(width, height, unit)``, where *unit* is one of "in", "cm",
951-
"px".
951+
"mm", "px".
952952
- a tuple ``(x, y)``, which is interpreted as ``(x, y, "in")``.
953953
954954
One of *width* or *height* may be ``None``; the respective value is taken

lib/matplotlib/tests/test_figure.py

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)