@@ -2623,8 +2623,9 @@ def bar_label(self, container, labels=None, *, fmt="%g", label_type="edge",
26232623 label texts will be the data values formatted with *fmt*.
26242624
26252625 fmt : str or callable, default: '%g'
2626- A format string for the label or a function to call with the value
2627- as the first argument.
2626+ An unnamed %-style or {}-style format string for the label or a
2627+ function to call with the value as the first argument.
2628+ When *fmt* is a string, %-style takes precedence over {}-style.
26282629
26292630 label_type : {'edge', 'center'}, default: 'edge'
26302631 The label type. Possible values:
@@ -2747,21 +2748,11 @@ def sign(x):
27472748 lbl = ''
27482749
27492750 if lbl is None :
2750- if callable (fmt ):
2751- formatted_value = fmt (value )
2752- elif isinstance (fmt , str ):
2753- if fmt .count ('{:' ) == fmt .count ('}' ) == 1 :
2754- formatted_value = fmt .format (value )
2755- else :
2756- formatted_value = fmt % value
2757- else :
2758- raise ValueError (
2759- 'fmt expected to be a callable or a format string. '
2760- f'Got "{ fmt } ".'
2761- )
2762- else :
2763- formatted_value = lbl
2764- annotation = self .annotate (formatted_value ,
2751+ try :
2752+ lbl = fmt (value )
2753+ except TypeError :
2754+ lbl = cbook ._auto_format_str (fmt , value )
2755+ annotation = self .annotate (lbl ,
27652756 xy , xytext , textcoords = "offset points" ,
27662757 ha = ha , va = va , ** kwargs )
27672758 annotations .append (annotation )
0 commit comments