@@ -254,7 +254,6 @@ def close(event):
254254from matplotlib import rcParams
255255from hashlib import md5
256256from matplotlib import _png
257- from matplotlib .font_manager import weight_as_number
258257from matplotlib import _path
259258
260259try :
@@ -306,6 +305,7 @@ def close(event):
306305import io
307306import textwrap
308307import uuid
308+ import numbers
309309from functools import partial
310310from math import cos , sin , pi
311311
@@ -666,7 +666,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
666666 plot_text .text = six .text_type ("{}" .format (s ))
667667 if prop .get_style () == 'italic' :
668668 plot_text .italic = True
669- if weight_as_number (prop .get_weight ()) > 500 :
669+ if self . weight_as_number (prop .get_weight ()) > 500 :
670670 plot_text .bold = True
671671 plot_text .refresh ()
672672 with self .widget .canvas :
@@ -802,6 +802,44 @@ def new_gc(self):
802802
803803 def points_to_pixels (self , points ):
804804 return points / 72.0 * self .dpi
805+
806+ def weight_as_number (self , weight ):
807+ ''' Replaces the deprecated matplotlib function of the same name
808+ '''
809+ # Return if number
810+ if isinstance (weight , numbers .Number ):
811+ return weight
812+ # else use the mapping of matplotlib 2.2
813+ elif weight == 'ultralight' :
814+ return 100
815+ elif weight == 'light' :
816+ return 200
817+ elif weight == 'normal' :
818+ return 400
819+ elif weight == 'regular' :
820+ return 400
821+ elif weight == 'book' :
822+ return 500
823+ elif weight == 'medium' :
824+ return 500
825+ elif weight == 'roman' :
826+ return 500
827+ elif weight == 'semibold' :
828+ return 600
829+ elif weight == 'demibold' :
830+ return 600
831+ elif weight == 'demi' :
832+ return 600
833+ elif weight == 'bold' :
834+ return 700
835+ elif weight == 'heavy' :
836+ return 800
837+ elif weight == 'extra bold' :
838+ return 800
839+ elif weight == 'black' :
840+ return 900
841+ else :
842+ raise ValueError ('weight ' + weight + ' not valid' )
805843
806844
807845class NavigationToolbar2Kivy (NavigationToolbar2 ):
0 commit comments