@@ -66,20 +66,21 @@ def _line_height(self, renderer) -> float:
6666 parts : list [tuple [str , tuple [float , float ], float , float ]]
6767
6868 try :
69- # matplotlib.Text._get_layout is a private API and we cannot
70- # tell how using it may fail in the future .
69+ # matplotlib.Text._get_layout is a private API. If its name or
70+ # return shape changes we fall back to an estimate .
7171 _ , parts , _ = self ._get_layout (renderer ) # pyright: ignore[reportAttributeAccessIssue]
72- except Exception :
72+ except ( AttributeError , ValueError , TypeError ) :
7373 from warnings import warn
7474
7575 from plotnine .exceptions import PlotnineWarning
7676
7777 # The canvas height is nearly always bigger than the stated
7878 # fontsize. 1.36 is a good multiplication factor obtained by
79- # some rough exploration
79+ # some rough exploration. A non-numeric size (e.g. "large")
80+ # falls back to a fixed estimate.
8081 f = 1.36
8182 size = self .get_fontsize ()
82- height = round ( size * f ) if isinstance (size , int ) else 14
83+ height = size * f if isinstance (size , ( int , float ) ) else 14
8384 warn (
8485 f"Could not calculate line height for { self .get_text ()} . "
8586 "Using an estimate, please let us know about this at "
0 commit comments