I'm trying to execute this exact code multipage pdf, copy %paste on Ipython, ubuntu14.04, python 2.7.6
I get the following error though
RuntimeError: LaTeX was not able to process the following string:
'lp'
Full traceback
sh: 1: latex: not found
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-5-e46ddc0d5d7d> in <module>()
19 plt.plot(x, np.sin(x), 'b-')
20 plt.title('Page Two')
---> 21 pdf.savefig()
22 plt.close()
23
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.pyc in savefig(self, figure, **kwargs)
2439 else:
2440 figureManager.canvas.figure.savefig(self, format='pdf',
-> 2441 **kwargs)
2442
2443 def get_pagecount(self):
/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in savefig(self, *args, **kwargs)
1474 self.set_frameon(frameon)
1475
-> 1476 self.canvas.print_figure(*args, **kwargs)
1477
1478 if frameon:
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5agg.pyc in print_figure(self, *args, **kwargs)
159
160 def print_figure(self, *args, **kwargs):
--> 161 FigureCanvasAgg.print_figure(self, *args, **kwargs)
162 self.draw()
163
/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2209 orientation=orientation,
2210 bbox_inches_restore=_bbox_inches_restore,
-> 2211 **kwargs)
2212 finally:
2213 if bbox_inches and restore_bbox:
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.pyc in print_pdf(self, filename, **kwargs)
2483 RendererPdf(file, image_dpi),
2484 bbox_inches_restore=_bbox_inches_restore)
-> 2485 self.figure.draw(renderer)
2486 renderer.finalize()
2487 finally:
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in draw(self, renderer)
1083 dsu.sort(key=itemgetter(0))
1084 for zorder, a, func, args in dsu:
-> 1085 func(*args)
1086
1087 renderer.close_group('figure')
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
2108
2109 for zorder, a in dsu:
-> 2110 a.draw(renderer)
2111
2112 renderer.close_group('axes')
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/usr/local/lib/python2.7/dist-packages/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
1114 ticks_to_draw = self._update_ticks(renderer)
1115 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1116 renderer)
1117
1118 for tick in ticks_to_draw:
/usr/local/lib/python2.7/dist-packages/matplotlib/axis.pyc in _get_tick_bboxes(self, ticks, renderer)
1063 for tick in ticks:
1064 if tick.label1On and tick.label1.get_visible():
-> 1065 extent = tick.label1.get_window_extent(renderer)
1066 ticklabelBoxes.append(extent)
1067 if tick.label2On and tick.label2.get_visible():
/usr/local/lib/python2.7/dist-packages/matplotlib/text.pyc in get_window_extent(self, renderer, dpi)
796 raise RuntimeError('Cannot get window extent w/o renderer')
797
--> 798 bbox, info, descent = self._get_layout(self._renderer)
799 x, y = self.get_position()
800 x, y = self.get_transform().transform_point((x, y))
/usr/local/lib/python2.7/dist-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
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.pyc in get_text_width_height_descent(self, s, prop, ismath)
2042 fontsize = prop.get_size_in_points()
2043 w, h, d = texmanager.get_text_width_height_descent(s, fontsize,
-> 2044 renderer=self)
2045 return w, h, d
2046
/usr/local/lib/python2.7/dist-packages/matplotlib/texmanager.pyc in get_text_width_height_descent(self, tex, fontsize, renderer)
668 else:
669 # use dviread. It sometimes returns a wrong descent.
--> 670 dvifile = self.make_dvi(tex, fontsize)
671 dvi = dviread.Dvi(dvifile, 72 * dpi_fraction)
672 try:
/usr/local/lib/python2.7/dist-packages/matplotlib/texmanager.pyc in make_dvi(self, tex, fontsize)
415 'string:\n%s\nHere is the full report generated by '
416 'LaTeX: \n\n' % repr(tex.encode('unicode_escape')) +
--> 417 report))
418 else:
419 mpl.verbose.report(report, 'debug')
Any guess what is wrong with this runtime error?
Since I actually can import rc from matplotlib.
In case someone is in the same situation I am posting the answer,
apparently latex was installed but matplotlib coudn't figure out the path,
I rebuilt all the environnement as follows:
Updating deb repository
sudo apt-get update
This outputs latex reports on ipython
sudo apt-get install texlive-latex-extra
Finally rebuild all
sudo apt-get install dvipng
sudo apt-get build-dep python-matplotlib
Related
I was going through some of the Quantitative Finance tutorials on Quantopia, when I encountered a problem in creating a histogram. Originally, I used my data set, X, and plotted it in a graph. The graph was displayed in the notebook, but when I tried to run the last line in the code shown, I got a number of traceback errors.
I managed to make the histogram by removing the lines of code which plotted X to a graph, but I'm confused as to why I can't create both a graph and a histogram. Is the object being changed somewhere along the way? My apologies if this is something rudimentary, I am fairly new to coding, and this is my first question on Stack Exchange. If it helps, the Quantopia notebooks are on Python 2.7. Thanks, and have a great day.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = get_pricing('MSFT', start_date='2012-1-1', end_date='2015-6-1')
X = data['price']
plt.plot(X.index, X.values)
plt.ylabel('Price')
plt.legend(['MSFT']);
R = X.pct_change()[1:]
plt.hist(R, bins = 20)
Here's the error:
ValueErrorTraceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/IPython/core/formatters.pyc in __call__(self, obj)
332 pass
333 else:
--> 334 return printer(obj)
335 # Finally look for special method names
336 method = get_real_method(obj, self.print_method)
/usr/local/lib/python2.7/dist-packages/IPython/core/pylabtools.pyc in <lambda>(fig)
245
246 if 'png' in formats:
--> 247 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
248 if 'retina' in formats or 'png2x' in formats:
249 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
/usr/local/lib/python2.7/dist-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
129
130 bytes_io = BytesIO()
--> 131 fig.canvas.print_figure(bytes_io, **kw)
132 data = bytes_io.getvalue()
133 if fmt == 'svg':
/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2178 orientation=orientation,
2179 dryrun=True,
-> 2180 **kwargs)
2181 renderer = self.figure._cachedRenderer
2182 bbox_inches = self.figure.get_tightbbox(renderer)
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
525
526 def print_png(self, filename_or_obj, *args, **kwargs):
--> 527 FigureCanvasAgg.draw(self)
528 renderer = self.get_renderer()
529 original_dpi = renderer.dpi
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.pyc in draw(self)
472
473 try:
--> 474 self.figure.draw(self.renderer)
475 finally:
476 RendererAgg.lock.release()
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in draw(self, renderer)
1157 dsu.sort(key=itemgetter(0))
1158 for zorder, a, func, args in dsu:
-> 1159 func(*args)
1160
1161 renderer.close_group('figure')
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
2322
2323 for zorder, a in dsu:
-> 2324 a.draw(renderer)
2325
2326 renderer.close_group('axes')
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
59 def draw_wrapper(artist, renderer, *args, **kwargs):
60 before(artist, renderer)
---> 61 draw(artist, renderer, *args, **kwargs)
62 after(artist, renderer)
63
/usr/local/lib/python2.7/dist-packages/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
1104 renderer.open_group(__name__)
1105
-> 1106 ticks_to_draw = self._update_ticks(renderer)
1107 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
1108 renderer)
/usr/local/lib/python2.7/dist-packages/matplotlib/axis.pyc in _update_ticks(self, renderer)
947
948 interval = self.get_view_interval()
--> 949 tick_tups = [t for t in self.iter_ticks()]
950 if self._smart_bounds:
951 # handle inverted limits
/usr/local/lib/python2.7/dist-packages/matplotlib/axis.pyc in iter_ticks(self)
890 Iterate through all of the major and minor ticks.
891 """
--> 892 majorLocs = self.major.locator()
893 majorTicks = self.get_major_ticks(len(majorLocs))
894 self.major.formatter.set_locs(majorLocs)
/usr/local/lib/python2.7/dist-packages/matplotlib/dates.pyc in __call__(self)
1004 def __call__(self):
1005 'Return the locations of the ticks'
-> 1006 self.refresh()
1007 return self._locator()
1008
/usr/local/lib/python2.7/dist-packages/matplotlib/dates.pyc in refresh(self)
1024 def refresh(self):
1025 'Refresh internal information based on current limits.'
-> 1026 dmin, dmax = self.viewlim_to_dt()
1027 self._locator = self.get_locator(dmin, dmax)
1028
/usr/local/lib/python2.7/dist-packages/matplotlib/dates.pyc in viewlim_to_dt(self)
768 vmin, vmax = vmax, vmin
769
--> 770 return num2date(vmin, self.tz), num2date(vmax, self.tz)
771
772 def _get_unit(self):
/usr/local/lib/python2.7/dist-packages/matplotlib/dates.pyc in num2date(x, tz)
417 tz = _get_rc_timezone()
418 if not cbook.iterable(x):
--> 419 return _from_ordinalf(x, tz)
420 else:
421 x = np.asarray(x)
/usr/local/lib/python2.7/dist-packages/matplotlib/dates.pyc in _from_ordinalf(x, tz)
269
270 ix = int(x)
--> 271 dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
272
273 remainder = float(x) - ix
ValueError: ordinal must be >= 1
<matplotlib.figure.Figure at 0x7fdbbf910dd0>
I am trying to plot a bar. But it shows Runtime error, and shows In FT2Font: Can not load face. at the Botton.
I have tried uninstall and install it again. And tried another method, but still can not work. I think the code is right, because I successfully run it on a windows laptop. And my jupyter notebook is for Mac python 2.7.
The code is as following:
import numpy as np
import pandas as pd
obj = pd.Series([4, 7, -5, 3])
print type(obj)
obj
%matplotlib inline
obj.plot(kind = 'bar', figsize=[5,4])
But it shows some error :
<matplotlib.axes._subplots.AxesSubplot at 0x1114e69d0>
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/anaconda2/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
332 pass
333 else:
--> 334 return printer(obj)
335 # Finally look for special method names
336 method = get_real_method(obj, self.print_method)
/anaconda2/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in <lambda>(fig)
238
239 if 'png' in formats:
--> 240 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
241 if 'retina' in formats or 'png2x' in formats:
242 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
/anaconda2/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
122
123 bytes_io = BytesIO()
--> 124 fig.canvas.print_figure(bytes_io, **kw)
125 data = bytes_io.getvalue()
126 if fmt == 'svg':
/anaconda2/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2206 orientation=orientation,
2207 dryrun=True,
-> 2208 **kwargs)
2209 renderer = self.figure._cachedRenderer
2210 bbox_inches = self.figure.get_tightbbox(renderer)
/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
505
506 def print_png(self, filename_or_obj, *args, **kwargs):
--> 507 FigureCanvasAgg.draw(self)
508 renderer = self.get_renderer()
509 original_dpi = renderer.dpi
/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in draw(self)
428 if toolbar:
429 toolbar.set_cursor(cursors.WAIT)
--> 430 self.figure.draw(self.renderer)
431 finally:
432 if toolbar:
/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
/anaconda2/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
1293
1294 mimage._draw_list_compositing_images(
-> 1295 renderer, self, artists, self.suppressComposite)
1296
1297 renderer.close_group('figure')
/anaconda2/lib/python2.7/site-packages/matplotlib/image.pyc in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
2397 renderer.stop_rasterizing()
2398
-> 2399 mimage._draw_list_compositing_images(renderer, self, artists)
2400
2401 renderer.close_group('axes')
/anaconda2/lib/python2.7/site-packages/matplotlib/image.pyc in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
/anaconda2/lib/python2.7/site-packages/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
1133 ticks_to_draw = self._update_ticks(renderer)
1134 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1135 renderer)
1136
1137 for tick in ticks_to_draw:
/anaconda2/lib/python2.7/site-packages/matplotlib/axis.pyc in _get_tick_bboxes(self, ticks, renderer)
1073 for tick in ticks:
1074 if tick.label1On and tick.label1.get_visible():
-> 1075 extent = tick.label1.get_window_extent(renderer)
1076 ticklabelBoxes.append(extent)
1077 if tick.label2On and tick.label2.get_visible():
/anaconda2/lib/python2.7/site-packages/matplotlib/text.pyc in get_window_extent(self, renderer, dpi)
968 raise RuntimeError('Cannot get window extent w/o renderer')
969
--> 970 bbox, info, descent = self._get_layout(self._renderer)
971 x, y = self.get_unitless_position()
972 x, y = self.get_transform().transform_point((x, y))
/anaconda2/lib/python2.7/site-packages/matplotlib/text.pyc in _get_layout(self, renderer)
352 tmp, lp_h, lp_bl = renderer.get_text_width_height_descent('lp',
353 self._fontproperties,
--> 354 ismath=False)
355 offsety = (lp_h - lp_bl) * self._linespacing
356
/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in get_text_width_height_descent(self, s, prop, ismath)
233
234 flags = get_hinting_flag()
--> 235 font = self._get_agg_font(prop)
236 font.set_text(s, 0.0, flags=flags) # the width and height of unrotated string
237 w, h = font.get_width_height()
/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in _get_agg_font(self, prop)
270 font = get_font(
271 fname,
--> 272 hinting_factor=rcParams['text.hinting_factor'])
273
274 font.clear()
/anaconda2/lib/python2.7/site-packages/backports/functools_lru_cache.pyc in wrapper(*args, **kwds)
135 stats[HITS] += 1
136 return result
--> 137 result = user_function(*args, **kwds)
138 with lock:
139 root, = nonlocal_root
RuntimeError: In FT2Font: Can not load face.
<matplotlib.figure.Figure at 0x1114e6290>
I have tried uninstall it. and another code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
obj = pd.Series([4, 7, -5, 3])
print type(obj)
obj
plt.plot(obj)
plt.show()
And still show errors:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/anaconda2/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
332 pass
333 else:
--> 334 return printer(obj)
335 # Finally look for special method names
336 method = get_real_method(obj, self.print_method)
/anaconda2/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in <lambda>(fig)
238
239 if 'png' in formats:
--> 240 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
241 if 'retina' in formats or 'png2x' in formats:
242 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
/anaconda2/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
122
123 bytes_io = BytesIO()
--> 124 fig.canvas.print_figure(bytes_io, **kw)
125 data = bytes_io.getvalue()
126 if fmt == 'svg':
/anaconda2/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2206 orientation=orientation,
2207 dryrun=True,
-> 2208 **kwargs)
2209 renderer = self.figure._cachedRenderer
2210 bbox_inches = self.figure.get_tightbbox(renderer)
/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
505
506 def print_png(self, filename_or_obj, *args, **kwargs):
--> 507 FigureCanvasAgg.draw(self)
508 renderer = self.get_renderer()
509 original_dpi = renderer.dpi
/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in draw(self)
428 if toolbar:
429 toolbar.set_cursor(cursors.WAIT)
--> 430 self.figure.draw(self.renderer)
431 finally:
432 if toolbar:
/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
/anaconda2/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
1293
1294 mimage._draw_list_compositing_images(
-> 1295 renderer, self, artists, self.suppressComposite)
1296
1297 renderer.close_group('figure')
/anaconda2/lib/python2.7/site-packages/matplotlib/image.pyc in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
2397 renderer.stop_rasterizing()
2398
-> 2399 mimage._draw_list_compositing_images(renderer, self, artists)
2400
2401 renderer.close_group('axes')
/anaconda2/lib/python2.7/site-packages/matplotlib/image.pyc in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
/anaconda2/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:
/anaconda2/lib/python2.7/site-packages/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
1133 ticks_to_draw = self._update_ticks(renderer)
1134 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1135 renderer)
1136
1137 for tick in ticks_to_draw:
/anaconda2/lib/python2.7/site-packages/matplotlib/axis.pyc in _get_tick_bboxes(self, ticks, renderer)
1073 for tick in ticks:
1074 if tick.label1On and tick.label1.get_visible():
-> 1075 extent = tick.label1.get_window_extent(renderer)
1076 ticklabelBoxes.append(extent)
1077 if tick.label2On and tick.label2.get_visible():
/anaconda2/lib/python2.7/site-packages/matplotlib/text.pyc in get_window_extent(self, renderer, dpi)
968 raise RuntimeError('Cannot get window extent w/o renderer')
969
--> 970 bbox, info, descent = self._get_layout(self._renderer)
971 x, y = self.get_unitless_position()
972 x, y = self.get_transform().transform_point((x, y))
/anaconda2/lib/python2.7/site-packages/matplotlib/text.pyc in _get_layout(self, renderer)
352 tmp, lp_h, lp_bl = renderer.get_text_width_height_descent('lp',
353 self._fontproperties,
--> 354 ismath=False)
355 offsety = (lp_h - lp_bl) * self._linespacing
356
/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in get_text_width_height_descent(self, s, prop, ismath)
233
234 flags = get_hinting_flag()
--> 235 font = self._get_agg_font(prop)
236 font.set_text(s, 0.0, flags=flags) # the width and height of unrotated string
237 w, h = font.get_width_height()
/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in _get_agg_font(self, prop)
270 font = get_font(
271 fname,
--> 272 hinting_factor=rcParams['text.hinting_factor'])
273
274 font.clear()
/anaconda2/lib/python2.7/site-packages/backports/functools_lru_cache.pyc in wrapper(*args, **kwds)
135 stats[HITS] += 1
136 return result
--> 137 result = user_function(*args, **kwds)
138 with lock:
139 root, = nonlocal_root
RuntimeError: In FT2Font: Can not load face.
<matplotlib.figure.Figure at 0x113232250>
I was facing same issue while using anaconda and spyder with python 3+ on MacOS.
I am not sure if this solution would work for you but i solved it by deleting all files and folder in:
/Users/YOUR_USER/.matplotlib
and then uninstalling and reinstalling 'matplotlib' from my environment in Anaconda Navigator.
I just had this error - looking through the matplotlib debug logs, everything seemed ok. However, when I checked the path of the font that had been selected, the file size was 0KB. Maybe it got corrupted when matplotlib was being installed.
Copying the font file from another machine into the font directory fixed the problem.
Fyi, the path is %CONDA_ENV%\Lib\site-packages\matplotlib\mpl-data\fonts\ttf (I'm using conda on Windows, but the path should be the same relative to your site-packages directory on your local installation). Reinstalling matplotlib will fix the issue, but it's worth checking this folder, just in case the issue is just one bad font file.
I just upgraded matplotlib to matplotlib2.0. As far I could see nothing was supposed to change in the basic use, yet I now have this strange bu with rgb coding :
myDF_DoMS.mean().plot(color =(0.2,0.2,0.7),xticks=np.arange(1,31,1))
plt.plot([1,32],[zeMeanS,zeMeanS],color=(0.2,0.7,0.9))
plt.xlabel('xlabel')
plt.ylabel('Some Score')
plt.title(Study+"\n A name")
plt.show()
Complaints from the kernel :
ValueError: Invalid RGBA argument: 0.2
(full error stack below)
suddently 0.2 is not a float anymore !
What's worst if I put 'b' it works
while on line 2 the other 'rgb' list on line 2 works fine (color=(0.2,0.7,0.9)) ...
I'm a bit lost.
Setting :
Copy of a cell in a jupyter notebook that use to work perfectly.
Python 2.7 in an anaconda environment. Windows 10 as OS.
Here are the outputs :
ValueError Traceback (most recent call
last) C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\IPython\core\formatters.pyc
in __call__(self, obj)
305 pass
306 else:
--> 307 return printer(obj)
308 # Finally look for special method names
309 method = get_real_method(obj, self.print_method)
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\IPython\core\pylabtools.pyc
in <lambda>(fig)
238
239 if 'png' in formats:
--> 240 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
241 if 'retina' in formats or 'png2x' in formats:
242 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\IPython\core\pylabtools.pyc
in print_figure(fig, fmt, bbox_inches, **kwargs)
122
123 bytes_io = BytesIO()
--> 124 fig.canvas.print_figure(bytes_io, **kw)
125 data = bytes_io.getvalue()
126 if fmt == 'svg':
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\backend_bases.pyc
in print_figure(self, filename, dpi, facecolor, edgecolor,
orientation, format, **kwargs) 2198
orientation=orientation, 2199 dryrun=True,
-> 2200 **kwargs) 2201 renderer = self.figure._cachedRenderer 2202 bbox_inches = self.figure.get_tightbbox(renderer)
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\backends\backend_agg.pyc
in print_png(self, filename_or_obj, *args, **kwargs)
543
544 def print_png(self, filename_or_obj, *args, **kwargs):
--> 545 FigureCanvasAgg.draw(self)
546 renderer = self.get_renderer()
547 original_dpi = renderer.dpi
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\backends\backend_agg.pyc
in draw(self)
462
463 try:
--> 464 self.figure.draw(self.renderer)
465 finally:
466 RendererAgg.lock.release()
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\artist.pyc
in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\figure.pyc
in draw(self, renderer) 1142 1143
mimage._draw_list_compositing_images(
-> 1144 renderer, self, dsu, self.suppressComposite) 1145 1146 renderer.close_group('figure')
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\image.pyc
in _draw_list_compositing_images(renderer, parent, dsu,
suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\artist.pyc
in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\axes\_base.pyc
in draw(self, renderer, inframe) 2424
renderer.stop_rasterizing() 2425
-> 2426 mimage._draw_list_compositing_images(renderer, self, dsu) 2427 2428 renderer.close_group('axes')
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\image.pyc
in _draw_list_compositing_images(renderer, parent, dsu,
suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\artist.pyc
in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\lines.pyc
in draw(self, renderer)
801 self._set_gc_clip(gc)
802
--> 803 ln_color_rgba = self._get_rgba_ln_color()
804 gc.set_foreground(ln_color_rgba, isRGBA=True)
805 gc.set_alpha(ln_color_rgba[3])
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\lines.pyc
in _get_rgba_ln_color(self, alt) 1342 1343 def
_get_rgba_ln_color(self, alt=False):
-> 1344 return mcolors.to_rgba(self._color, self._alpha) 1345 1346 # some aliases....
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\colors.pyc
in to_rgba(c, alpha)
141 rgba = _colors_full_map.cache[c, alpha]
142 except (KeyError, TypeError): # Not in cache, or unhashable.
--> 143 rgba = _to_rgba_no_colorcycle(c, alpha)
144 try:
145 _colors_full_map.cache[c, alpha] = rgba
C:\Program
Files\Anaconda2\envs\moonshade\lib\site-packages\matplotlib\colors.pyc
in _to_rgba_no_colorcycle(c, alpha)
192 # float)` and `np.array(...).astype(float)` all convert "0.5" to 0.5.
193 # Test dimensionality to reject single floats.
--> 194 raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
195 # Return a tuple to prevent the cached value from being modified.
196 c = tuple(c.astype(float))
ValueError: Invalid RGBA argument: 0.2
<matplotlib.figure.Figure at 0x14e54ac8>
If your dataframe to plot has 3 columns, the color specification as color=(0.2,0.2,0.7) is ambiguous. It could well be interpreted as a tuple of colors, in which case 0.2 would be the color for the first column to plot. However, 0.2 is not a valid color after all and thus the error.
An option is to use
color=matplotlib.colors.to_hex((0.2,0.2,0.9))
or directly use the hex equivalent
color="#3333e5"
By the way, I don't think that this behaviour has changed between matplotlib versions, so it may just be that you use a different dataframe now(?).
I have been having a problem with python and matplotlib
I am running
from matplotlib import rc
import matplotlib.cm as cm
from matplotlib.ticker import MultipleLocator
scoreArray = [3,8,7,8,9,0]
scoreArrayIsopmap = [3,4,7,1,3,0]
scoreArrayPCA = [0,1,7,6,3,15]
rc('font',**{'family':'Bitstream Vera Sans','serif': ['Palatino']})
rc('text', usetex=True)
fig, (ax1) = plt.subplots(1,1, figsize=(7,5))
ax1.plot(range(0,6), scoreArray, color = 'b', ls='-', lw=4, alpha=0.7, label="A Priori Manifold")
ax1.plot(range(0,6), scoreArrayIsopmap, color = 'r', ls='-', lw=4, alpha=0.7, label="Isomap")
ax1.plot(range(0,6), scoreArrayPCA, color = 'g', ls='-', lw=4, alpha=0.7, label="PCA")
ax1.xaxis.set_major_locator(MultipleLocator(10))
ax1.grid(which='major', axis='x', linewidth=0.25, linestyle='-', color='0.75')
ax1.grid(True)
ax1.set_ylabel('Dunn Index')
ax1.set_xlabel('Number Of Components')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
1419 self.set_frameon(frameon)
1420
-> 1421 self.canvas.print_figure(*args, **kwargs)
1422
1423 if frameon:
/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2218 orientation=orientation,
2219 bbox_inches_restore=_bbox_inches_restore,
-> 2220 **kwargs)
2221 finally:
2222 if bbox_inches and restore_bbox:
/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_pdf(self, *args, **kwargs)
1950 from backends.backend_pdf import FigureCanvasPdf # lazy import
1951 pdf = self.switch_backends(FigureCanvasPdf)
-> 1952 return pdf.print_pdf(*args, **kwargs)
1953
1954 def print_pgf(self, *args, **kwargs):
/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_pdf.pyc in print_pdf(self, filename, **kwargs)
2338 width, height, image_dpi, RendererPdf(file, image_dpi),
2339 bbox_inches_restore=_bbox_inches_restore)
-> 2340 self.figure.draw(renderer)
2341 renderer.finalize()
2342 finally:
/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
52 def draw_wrapper(artist, renderer, *args, **kwargs):
53 before(artist, renderer)
---> 54 draw(artist, renderer, *args, **kwargs)
55 after(artist, renderer)
56
/usr/local/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
1032 dsu.sort(key=itemgetter(0))
1033 for zorder, a, func, args in dsu:
-> 1034 func(*args)
1035
1036 renderer.close_group('figure')
/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
52 def draw_wrapper(artist, renderer, *args, **kwargs):
53 before(artist, renderer)
---> 54 draw(artist, renderer, *args, **kwargs)
55 after(artist, renderer)
56
/usr/local/lib/python2.7/site-packages/matplotlib/axes.pyc in draw(self, renderer, inframe)
2084
2085 for zorder, a in dsu:
-> 2086 a.draw(renderer)
2087
2088 renderer.close_group('axes')
/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
52 def draw_wrapper(artist, renderer, *args, **kwargs):
53 before(artist, renderer)
---> 54 draw(artist, renderer, *args, **kwargs)
55 after(artist, renderer)
56
/usr/local/lib/python2.7/site-packages/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
1087 ticks_to_draw = self._update_ticks(renderer)
1088 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1089 renderer)
1090
1091 for tick in ticks_to_draw:
/usr/local/lib/python2.7/site-packages/matplotlib/axis.pyc in _get_tick_bboxes(self, ticks, renderer)
1036 for tick in ticks:
1037 if tick.label1On and tick.label1.get_visible():
-> 1038 extent = tick.label1.get_window_extent(renderer)
1039 ticklabelBoxes.append(extent)
1040 if tick.label2On and tick.label2.get_visible():
/usr/local/lib/python2.7/site-packages/matplotlib/text.pyc in get_window_extent(self, renderer, dpi)
751 raise RuntimeError('Cannot get window extent w/o renderer')
752
--> 753 bbox, info, descent = self._get_layout(self._renderer)
754 x, y = self.get_position()
755 x, y = self.get_transform().transform_point((x, y))
/usr/local/lib/python2.7/site-packages/matplotlib/text.pyc in _get_layout(self, renderer)
318 tmp, lp_h, lp_bl = get_text_width_height_descent('lp',
319 self._fontproperties,
--> 320 ismath=False)
321 offsety = (lp_h - lp_bl) * self._linespacing
322
/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_pdf.pyc in get_text_width_height_descent(self, s, prop, ismath)
1945 def get_text_width_height_descent(self, s, prop, ismath):
1946 if rcParams['text.usetex']:
-> 1947 texmanager = self.get_texmanager()
1948 fontsize = prop.get_size_in_points()
1949 w, h, d = texmanager.get_text_width_height_descent(s, fontsize,
/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in get_texmanager(self)
612 if self._texmanager is None:
613 from matplotlib.texmanager import TexManager
--> 614 self._texmanager = TexManager()
615 return self._texmanager
616
/usr/local/lib/python2.7/site-packages/matplotlib/texmanager.pyc in __init__(self)
170 if len(ff) == 1 and ff[0].lower() in self.font_families:
171 self.font_family = ff[0].lower()
--> 172 elif ff.lower() in self.font_families:
173 self.font_family = ff.lower()
174 else:
AttributeError: 'list' object has no attribute 'lower'
I get the image above but the axis are not visible. I run python 2.7.5 and matplotlib 1.3. I work on a mac and it works fine on a different mac. It was working fine on mine until 2 days ago.
Anyone has any idea why this happens?
There are two things here:
From the matplotlib code:
font.family must be one of (serif, sans-serif, cursive, monospace) when text.usetex is True. serif will be used by default.
So if you use the text.usetex you should set the font.family to be one of the supported values.
You found a bug in the matplotlib 1.3.0 :) But it's already fixed on the development branch. So in the next release you won't get the error.
I'm trying to get a "degree" sign (°) in a matplotlib plot from ipython notebook.
When I run
ax = plt.gca()
ax.set_xlabel("something at 55" + unicode("\xc2", errors='replace'))
ax.plot([0.,1.,], [0.,1.])
I get a plot, but instead of the degree sign, I have a strange black square with a question mark. This also happens when I try to savefig the figure to PDF.
If I try to run
ax = plt.gca()
ax.set_xlabel("something at 55°")
ax.plot([0.,1.,], [0.,1.])
I get an error (see below).
Any idea what I'm doing wrong?
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/zmq/pylab/backend_inline.pyc in show(close)
100 try:
101 for figure_manager in Gcf.get_all_fig_managers():
--> 102 send_figure(figure_manager.canvas.figure)
103 finally:
104 show._to_draw = []
/usr/lib/python2.7/dist-packages/IPython/zmq/pylab/backend_inline.pyc in send_figure(fig)
188 """
189 fmt = InlineBackend.instance().figure_format
--> 190 data = print_figure(fig, fmt)
191 # print_figure will return None if there's nothing to draw:
192 if data is None:
/usr/lib/python2.7/dist-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt)
102 try:
103 bytes_io = BytesIO()
--> 104 fig.canvas.print_figure(bytes_io, format=fmt, bbox_inches='tight')
105 data = bytes_io.getvalue()
106 finally:
/usr/lib/pymodules/python2.7/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
1981 orientation=orientation,
1982 dryrun=True,
-> 1983 **kwargs)
1984 renderer = self.figure._cachedRenderer
1985 bbox_inches = self.figure.get_tightbbox(renderer)
/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
467
468 def print_png(self, filename_or_obj, *args, **kwargs):
--> 469 FigureCanvasAgg.draw(self)
470 renderer = self.get_renderer()
471 original_dpi = renderer.dpi
/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.pyc in draw(self)
419
420 try:
--> 421 self.figure.draw(self.renderer)
422 finally:
423 RendererAgg.lock.release()
/usr/lib/pymodules/python2.7/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 def draw_wrapper(artist, renderer, *args, **kwargs):
54 before(artist, renderer)
---> 55 draw(artist, renderer, *args, **kwargs)
56 after(artist, renderer)
57
/usr/lib/pymodules/python2.7/matplotlib/figure.pyc in draw(self, renderer)
896 dsu.sort(key=itemgetter(0))
897 for zorder, a, func, args in dsu:
--> 898 func(*args)
899
900 renderer.close_group('figure')
/usr/lib/pymodules/python2.7/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 def draw_wrapper(artist, renderer, *args, **kwargs):
54 before(artist, renderer)
---> 55 draw(artist, renderer, *args, **kwargs)
56 after(artist, renderer)
57
/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in draw(self, renderer, inframe)
1995
1996 for zorder, a in dsu:
-> 1997 a.draw(renderer)
1998
1999 renderer.close_group('axes')
/usr/lib/pymodules/python2.7/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 def draw_wrapper(artist, renderer, *args, **kwargs):
54 before(artist, renderer)
---> 55 draw(artist, renderer, *args, **kwargs)
56 after(artist, renderer)
57
/usr/lib/pymodules/python2.7/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
1052 self._update_label_position(ticklabelBoxes, ticklabelBoxes2)
1053
-> 1054 self.label.draw(renderer)
1055
1056 self._update_offset_text_position(ticklabelBoxes, ticklabelBoxes2)
/usr/lib/pymodules/python2.7/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
53 def draw_wrapper(artist, renderer, *args, **kwargs):
54 before(artist, renderer)
---> 55 draw(artist, renderer, *args, **kwargs)
56 after(artist, renderer)
57
/usr/lib/pymodules/python2.7/matplotlib/text.pyc in draw(self, renderer)
524 renderer.open_group('text', self.get_gid())
525
--> 526 bbox, info = self._get_layout(renderer)
527 trans = self.get_transform()
528
/usr/lib/pymodules/python2.7/matplotlib/text.pyc in _get_layout(self, renderer)
303 baseline = 0
304 for i, line in enumerate(lines):
--> 305 clean_line, ismath = self.is_math_text(line)
306 if clean_line:
307 w, h, d = get_text_width_height_descent(clean_line,
/usr/lib/pymodules/python2.7/matplotlib/text.pyc in is_math_text(s)
987 return s, 'TeX'
988
--> 989 if cbook.is_math_text(s):
990 return s, True
991 else:
/usr/lib/pymodules/python2.7/matplotlib/cbook.pyc in is_math_text(s)
1836 except UnicodeDecodeError:
1837 raise ValueError(
-> 1838 "matplotlib display text must have all code points < 128 or use Unicode strings")
1839
1840 dollar_count = s.count(r'$') - s.count(r'\$')
ValueError: matplotlib display text must have all code points < 128 or use Unicode strings
The error message is telling you what to do:
ValueError: matplotlib display text must have all code points < 128
or use Unicode strings
Make your xlabel a unicode string:
ax.set_xlabel(u"something at 55°")
The problem is that the font you are using to write the label does not have the ° sign. Try to use matplotlib's mathtext instead and format the ° with latex:
ax.set_xlabel("something at 55$^\circ$")