|
17 | 17 | import matplotlib.font_manager as font_manager
|
18 | 18 | import matplotlib.text as text
|
19 | 19 | import matplotlib.cbook as cbook
|
20 |
| -import matplotlib.mathtext as mathtext |
21 | 20 | import matplotlib.patches as mpatches
|
22 |
| -import matplotlib.texmanager as texmanager |
23 | 21 | import matplotlib.transforms as mtransforms
|
24 | 22 |
|
25 | 23 | # Import needed for adding manual selection capability to clabel
|
@@ -243,20 +241,12 @@ def get_label_width(self, lev, fmt, fsize):
|
243 | 241 | """
|
244 | 242 | if not isinstance(lev, str):
|
245 | 243 | lev = self.get_text(lev, fmt)
|
246 |
| - lev, ismath = text.Text()._preprocess_math(lev) |
247 |
| - if ismath == 'TeX': |
248 |
| - lw, _, _ = (texmanager.TexManager() |
249 |
| - .get_text_width_height_descent(lev, fsize)) |
250 |
| - elif ismath: |
251 |
| - if not hasattr(self, '_mathtext_parser'): |
252 |
| - self._mathtext_parser = mathtext.MathTextParser('agg') |
253 |
| - _, _, _, _, _, img, _ = self._mathtext_parser.parse( |
254 |
| - lev, dpi=72, prop=self.labelFontProps) |
255 |
| - _, lw = np.shape(img) # at dpi=72, the units are PostScript points |
256 |
| - else: |
257 |
| - # width is much less than "font size" |
258 |
| - lw = len(lev) * fsize * 0.6 |
259 |
| - return lw |
| 244 | + fig = self.axes.figure |
| 245 | + width = (text.Text(0, 0, lev, figure=fig, |
| 246 | + size=fsize, fontproperties=self.labelFontProps) |
| 247 | + .get_window_extent(fig.canvas.get_renderer()).width) |
| 248 | + width *= 72 / fig.dpi |
| 249 | + return width |
260 | 250 |
|
261 | 251 | def set_label_props(self, label, text, color):
|
262 | 252 | """Set the label properties - color, fontsize, text."""
|
|
0 commit comments