Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upfirst example does not work on OSx #68
Comments
|
I don't think the matplotlib.text.Text objects have a bounding box in the MacOS backend. attempting to call matplotlib.text.Text.get_window_extent() throws the same error. May also be a problem with get render. I tried matplotlib.use('TKAgg')...no dice. |
|
the command matplotlib.use('TkAgg') does not work in my environment, so half the above is false or misleading. In any case you should state up front that this library only works with backends supporting bounding boxes. (maybe you did and I missed it). I think there may be an easy hack to retrieve a funcitonal get_render instance. see matplotlib/matplotlib#1852. However I am too far down this rabbit hole already. |
|
solution is to install python 3.6 conda environment |
|
Hi. Sorry, it's not working for you. I don't have a MacOS system to try this. I believe someone even made a fix at some point to make adjustText work with MacOS backend... So lack of bounding boxes for texts there is news to me! The whole backend business is very confusing, especially because there isn't really any documentation about differences between backends, as far as I know. So, in the end it works for you with python 3.6? But the same version of matplotlib? |
Hello using Python 2.7.13 :: Anaconda custom (64-bit) conda 4.5.11 on OS X Sierra, the first example fails with the following Runtime error:
In [139]: %run -i adjustTextExample.py
RuntimeError Traceback (most recent call last)
/Users/mccartt1/Documents/14Cproject/Spectra/Data/IsoSum/adjustTextExample.py in ()
12 plt.plot(x, y, 'bo')
13 texts = [plt.text(x[i], y[i], 'Text%s' %i, ha='center', va='center') for i in range(len(x))]
---> 14 adjust_text(texts)
//anaconda/lib/python2.7/site-packages/adjustText/init.pyc in adjust_text(texts, x, y, add_objects, ax, expand_text, expand_points, expand_objects, expand_align, autoalign, va, ha, force_text, force_points, force_objects, lim, precision, only_move, text_from_text, text_from_points, save_steps, save_prefix, save_format, add_step_numbers, draggable, on_basemap, *args, **kwargs)
435 # ydiff = np.diff(ax.get_ylim())[0]
436
--> 437 bboxes = get_bboxes(texts, r, (1.0, 1.0), ax)
438 sum_width = np.sum(list(map(lambda x: x.width, bboxes)))
439 sum_height = np.sum(list(map(lambda x: x.height, bboxes)))
//anaconda/lib/python2.7/site-packages/adjustText/init.pyc in get_bboxes(objs, r, expand, ax)
19 ax = plt.gca()
20 return [i.get_window_extent(r).expanded(*expand).transformed(ax.
---> 21 transData.inverted()) for i in objs]
22
23 def get_midpoint(bbox):
//anaconda/lib/python2.7/site-packages/matplotlib/text.pyc in get_window_extent(self, renderer, dpi)
739 raise RuntimeError('Cannot get window extent w/o renderer')
740
--> 741 bbox, info, descent = self._get_layout(self._renderer)
742 x, y = self.get_position()
743 x, y = self.get_transform().transform_point((x, y))
//anaconda/lib/python2.7/site-packages/matplotlib/text.pyc in _get_layout(self, renderer)
309 tmp, lp_h, lp_bl = renderer.get_text_width_height_descent('lp',
310 self._fontproperties,
--> 311 ismath=False)
312 offsety = (lp_h - lp_bl) * self._linespacing
313
//anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.pyc in get_text_width_height_descent(self, s, prop, ismath)
164 size = self.points_to_pixels(points)
165 width, height, descent = self.gc.get_text_width_height_descent(
--> 166 six.text_type(s), family, size, weight, style)
167 return width, height, 0.0*descent
168
RuntimeError: CGContextRef is NULL