Related
I made this function to find the distribution of all the columns in my pandas dataframe and it works when I have each individual line in separate cells, but when I put it into this one function I get the error message
TypeError: float() argument must be a string or a number, not 'pandas._libs.interval.Interval'
I'm relatively new to coding so I don't know what that means or how to fix it. Please help! thank you
def function():
for x in range(df.shape[1]):
columns = df.columns
if len(df[columns[x]].unique()) > 10:
samp = pd.qcut(df[columns[x]], 4)
bins = samp.unique
sampdf = pd.DataFrame(samp)
ex1 = sampdf.groupby(columns[x]).agg({columns[x]:'count'})
ex2 = ex1.reset_index(drop=True)`
else:
samp = df[columns[x]]
sampdf = pd.DataFrame(samp)
ex1 = sampdf.groupby(columns[x]).agg({columns[x]:'count'})
plt.style.use('ggplot')
plt.bar(ex1.index, ex1[columns[x]], color= 'purple')
plt.ylabel('Customers')
plt.xlabel(columns[x])
plt.title('Distribution of ' + columns[x])
plt.show()
The Traceback was:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-28-c0b3cafe2087> in <module>
----> 1 function1()
<ipython-input-27-bcfb6d749f86> in function1()
15
16 plt.style.use('ggplot')
---> 17 plt.bar(ex1.index, ex1[columns[0]], color= 'purple')
18 plt.ylabel('Customers')
19 plt.xlabel(columns[0])
/opt/anaconda3/lib/python3.8/site-packages/matplotlib/pyplot.py in bar(x, height, width, bottom, align, data, **kwargs)
2485 x, height, width=0.8, bottom=None, *, align='center',
2486 data=None, **kwargs):
-> 2487 return gca().bar(
2488 x, height, width=width, bottom=bottom, align=align,
2489 **({"data": data} if data is not None else {}), **kwargs)
/opt/anaconda3/lib/python3.8/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
1436 def inner(ax, *args, data=None, **kwargs):
1437 if data is None:
-> 1438 return func(ax, *map(sanitize_sequence, args), **kwargs)
1439
1440 bound = new_sig.bind(ax, *args, **kwargs)
/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_axes.py in bar(self, x, height, width, bottom, align, **kwargs)
2492 elif orientation == 'horizontal':
2493 r.sticky_edges.x.append(l)
-> 2494 self.add_patch(r)
2495 patches.append(r)
2496
/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_base.py in add_patch(self, p)
2031 if p.get_clip_path() is None:
2032 p.set_clip_path(self.patch)
-> 2033 self._update_patch_limits(p)
2034 self.patches.append(p)
2035 p._remove_method = self.patches.remove
/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_base.py in _update_patch_limits(self, patch)
2051 vertices = patch.get_path().vertices
2052 if vertices.size > 0:
-> 2053 xys = patch.get_patch_transform().transform(vertices)
2054 if patch.get_data_transform() != self.transData:
2055 patch_to_data = (patch.get_data_transform() -
/opt/anaconda3/lib/python3.8/site-packages/matplotlib/patches.py in get_patch_transform(self)
790
791 def get_patch_transform(self):
--> 792 self._update_patch_transform()
793 return self._rect_transform
794
/opt/anaconda3/lib/python3.8/site-packages/matplotlib/patches.py in _update_patch_transform(self)
769 """
770 x0, y0, x1, y1 = self._convert_units()
--> 771 bbox = transforms.Bbox.from_extents(x0, y0, x1, y1)
772 rot_trans = transforms.Affine2D()
773 rot_trans.rotate_deg_around(x0, y0, self.angle)
/opt/anaconda3/lib/python3.8/site-packages/matplotlib/transforms.py in from_extents(*args)
820 The *y*-axis increases upwards.
821 """
--> 822 return Bbox(np.reshape(args, (2, 2)))
823
824 def __format__(self, fmt):
/opt/anaconda3/lib/python3.8/site-packages/matplotlib/transforms.py in __init__(self, points, **kwargs)
772 """
773 BboxBase.__init__(self, **kwargs)
--> 774 points = np.asarray(points, float)
775 if points.shape != (2, 2):
776 raise ValueError('Bbox points must be of the form '
/opt/anaconda3/lib/python3.8/site-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
81
82 """
---> 83 return array(a, dtype, copy=False, order=order)
84
85
TypeError: float() argument must be a string or a number, not 'pandas._libs.interval.Interval'
Unlike what has been said here, the AttributeError: Unknown property color_cycle is still persistent in the newest Pandas version (0.19.0-1).
In my case, I have a dataframe similar to this, although much longer (3,000,000 rows):
A B C
1 05010001 17 1
2 05020001 5 1
3 05020002 11 1
4 05020003 2 1
5 05030001 86 1
6 07030001 84 2
7 07030002 10 2
8 08010001 16 3
For some reason, if I implement this very example, there are no errors. In my actual case, executing the simple
df.boxplot(by='C')
triggers this mess:
AttributeError Traceback (most recent call last)
<ipython-input-51-5c645348f82f> in <module>()
----> 1 df.boxplot(by='C')
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\core\frame.pyc in boxplot(self, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
5514
5515 columns = list(data.dtype.names)
-> 5516 arrays = [data[k] for k in columns]
5517 return arrays, columns
5518 else:
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\tools\plotting.pyc in boxplot(data, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
2687 ax : Matplotlib axes object, optional
2688 fontsize : int or string
-> 2689 rot : label rotation angle
2690 figsize : A tuple (width, height) in inches
2691 grid : Setting this to True will show the grid
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\tools\plotting.pyc in _grouped_plot_by_column(plotf, data, columns, by, numeric_only, grid, figsize, ax, layout, return_type, **kwargs)
3091 >>> df = pandas.DataFrame(data, columns=list('ABCD'), index=index)
3092 >>>
-> 3093 >>> grouped = df.groupby(level='lvl1')
3094 >>> boxplot_frame_groupby(grouped)
3095 >>>
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\tools\plotting.pyc in plot_group(keys, values, ax)
2659 create a figure with the default figsize, causing the figsize=parameter to
2660 be ignored.
-> 2661 """
2662 if ax is None and len(plt.get_fignums()) > 0:
2663 ax = _gca()
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\__init__.pyc in inner(ax, *args, **kwargs)
1810 warnings.warn(msg % (label_namer, func.__name__),
1811 RuntimeWarning, stacklevel=2)
-> 1812 return func(ax, *args, **kwargs)
1813 pre_doc = inner.__doc__
1814 if pre_doc is None:
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_axes.pyc in boxplot(self, x, notch, sym, vert, whis, positions, widths, patch_artist, bootstrap, usermedians, conf_intervals, meanline, showmeans, showcaps, showbox, showfliers, boxprops, labels, flierprops, medianprops, meanprops, capprops, whiskerprops, manage_xticks)
3321 meanline=meanline, showfliers=showfliers,
3322 capprops=capprops, whiskerprops=whiskerprops,
-> 3323 manage_xticks=manage_xticks)
3324 return artists
3325
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_axes.pyc in bxp(self, bxpstats, positions, widths, vert, patch_artist, shownotches, showmeans, showcaps, showbox, showfliers, boxprops, whiskerprops, flierprops, medianprops, capprops, meanprops, meanline, manage_xticks)
3650 boxes.extend(dopatch(box_x, box_y, **final_boxprops))
3651 else:
-> 3652 boxes.extend(doplot(box_x, box_y, **final_boxprops))
3653
3654 # draw the whiskers
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_axes.pyc in doplot(*args, **kwargs)
3564 if vert:
3565 def doplot(*args, **kwargs):
-> 3566 return self.plot(*args, **kwargs)
3567
3568 def dopatch(xs, ys, **kwargs):
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\__init__.pyc in inner(ax, *args, **kwargs)
1810 warnings.warn(msg % (label_namer, func.__name__),
1811 RuntimeWarning, stacklevel=2)
-> 1812 return func(ax, *args, **kwargs)
1813 pre_doc = inner.__doc__
1814 if pre_doc is None:
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_axes.pyc in plot(self, *args, **kwargs)
1422 kwargs['color'] = c
1423
-> 1424 for line in self._get_lines(*args, **kwargs):
1425 self.add_line(line)
1426 lines.append(line)
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_base.pyc in _grab_next_args(self, *args, **kwargs)
384 return
385 if len(remaining) <= 3:
--> 386 for seg in self._plot_args(remaining, kwargs):
387 yield seg
388 return
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_base.pyc in _plot_args(self, tup, kwargs)
372 ncx, ncy = x.shape[1], y.shape[1]
373 for j in xrange(max(ncx, ncy)):
--> 374 seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
375 ret.append(seg)
376 return ret
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_base.pyc in _makeline(self, x, y, kw, kwargs)
278 default_dict = self._getdefaults(None, kw, kwargs)
279 self._setdefaults(default_dict, kw, kwargs)
--> 280 seg = mlines.Line2D(x, y, **kw)
281 self.set_lineprops(seg, **kwargs)
282 return seg
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\lines.pyc in __init__(self, xdata, ydata, linewidth, linestyle, color, marker, markersize, markeredgewidth, markeredgecolor, markerfacecolor, markerfacecoloralt, fillstyle, antialiased, dash_capstyle, solid_capstyle, dash_joinstyle, solid_joinstyle, pickradius, drawstyle, markevery, **kwargs)
365 # update kwargs before updating data to give the caller a
366 # chance to init axes (and hence unit support)
--> 367 self.update(kwargs)
368 self.pickradius = pickradius
369 self.ind_offset = 0
C:\Users\B4058846\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\artist.pyc in update(self, props)
854 func = getattr(self, 'set_' + k, None)
855 if func is None or not six.callable(func):
--> 856 raise AttributeError('Unknown property %s' % k)
857 func(v)
858 changed = True
AttributeError: Unknown property color_cycle
And I am left with a blank 4-pane plot, when there should have been just one with 5 boxplot columns:
How to fix this?
I've verified myself that one needs to have pandas 0.19.0-1 together with matplotlib 1.5.1-8 to not experience this error.
I have a pandas DataFrame. The columns, head and dtypes are as shown below:
print sorted_results.dtypes
print sorted_results[['coefficients']].head()
0 object
coefficients float64
dtype: object
coefficients
62 2.432853
70 2.187059
19 1.804636
68 1.507075
130 1.120488
I want to plot a barchart using matplot lib, so
plt.barh(range(len(sorted_results)), sorted_results[['coefficients']])
gives the following:
ValueError Traceback (most recent call last)
<ipython-input-17-1d344a50d686> in <module>()
1
----> 2 plt.barh(range(len(sorted_results)), sorted_results[['coefficients']])
/Users/sram/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in barh(bottom, width, height, left, hold, **kwargs)
2665 ax.hold(hold)
2666 try:
-> 2667 ret = ax.barh(bottom, width, height=height, left=left, **kwargs)
2668 finally:
2669 ax.hold(washold)
/Users/sram/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in barh(self, bottom, width, height, left, **kwargs)
2245
2246 patches = self.bar(left=left, height=height, width=width,
-> 2247 bottom=bottom, orientation='horizontal', **kwargs)
2248 return patches
2249
/Users/sram/anaconda/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
1817 warnings.warn(msg % (label_namer, func.__name__),
1818 RuntimeWarning, stacklevel=2)
-> 1819 return func(ax, *args, **kwargs)
1820 pre_doc = inner.__doc__
1821 if pre_doc is None:
/Users/sram/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in bar(self, left, height, width, bottom, **kwargs)
2085 edgecolor=e,
2086 linewidth=lw,
-> 2087 label='_nolegend_'
2088 )
2089 r.update(kwargs)
/Users/sram/anaconda/lib/python2.7/site-packages/matplotlib/patches.pyc in __init__(self, xy, width, height, angle, **kwargs)
640 self._x = float(xy[0])
641 self._y = float(xy[1])
--> 642 self._width = float(width)
643 self._height = float(height)
644 self._angle = float(angle)
ValueError: could not convert string to float: coefficients
Coefficients seems to have the right datatype. I'm stumped by why I am doing wrong here
I have encountered an error while working through Ch12 of the book Numerical Python: A Practical Techniques Approach for Industry (http://jrjohansson.github.io/numericalpython.html).
I am getting an error when I try to plot a series object using the pandas library.
So far the following lines of code have worked:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
pd.set_option('display.mpl_style', 'default')
s = pd.Series([909976, 8615246, 2872086, 2273305])
s
0 909976
1 8615246
2 2872086
3 2273305
dtype: int64
When I plot the series object s I get the following error:
AttributeError Traceback (most recent call last)
<ipython-input-81-d3eb09d34df4> in <module>()
----> 1 s.plot()
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in generate(self)
985 self._compute_plot_data()
986 self._setup_subplots()
--> 987 self._make_plot()
988 self._add_table()
989 self._make_legend()
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in _make_plot(self)
1662 stacking_id=stacking_id,
1663 is_errorbar=is_errorbar,
-> 1664 **kwds)
1665 self._add_legend_handle(newlines[0], label, index=i)
1666
anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in _plot(cls, ax, x, y, style, column_num, stacking_id, **kwds)
1676 cls._initialize_stacker(ax, stacking_id, len(y))
1677 y_values = cls._get_stacked_values(ax, stacking_id, y, kwds['label'])
-> 1678 lines = MPLPlot._plot(ax, x, y_values, style=style, **kwds)
1679 cls._update_stacker(ax, stacking_id, y)
1680 return lines
/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in _plot(cls, ax, x, y, style, is_errorbar, **kwds)
1298 else:
1299 args = (x, y)
-> 1300 return ax.plot(*args, **kwds)
1301
1302 def _get_index_name(self):
/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1809 warnings.warn(msg % (label_namer, func.__name__),
1810 RuntimeWarning, stacklevel=2)
-> 1811 return func(ax, *args, **kwargs)
1812 pre_doc = inner.__doc__
1813 if pre_doc is None:
/anaconda/lib/python3.5/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
1425 kwargs['color'] = c
1426
-> 1427 for line in self._get_lines(*args, **kwargs):
1428 self.add_line(line)
1429 lines.append(line)
/anaconda/lib/python3.5/site-packages/matplotlib/axes/_base.py in _grab_next_args(self, *args, **kwargs)
384 return
385 if len(remaining) <= 3:
--> 386 for seg in self._plot_args(remaining, kwargs):
387 yield seg
388 return
anaconda/lib/python3.5/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs)
372 ncx, ncy = x.shape[1], y.shape[1]
373 for j in xrange(max(ncx, ncy)):
--> 374 seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
375 ret.append(seg)
376 return ret
/anaconda/lib/python3.5/site-packages/matplotlib/axes/_base.py in _makeline(self, x, y, kw, kwargs)
278 default_dict = self._getdefaults(None, kw, kwargs)
279 self._setdefaults(default_dict, kw, kwargs)
--> 280 seg = mlines.Line2D(x, y, **kw)
281 self.set_lineprops(seg, **kwargs)
282 return seg
/anaconda/lib/python3.5/site-packages/matplotlib/lines.py in __init__(self, xdata, ydata, linewidth, linestyle, color, marker, markersize, markeredgewidth, markeredgecolor, markerfacecolor, markerfacecoloralt, fillstyle, antialiased, dash_capstyle, solid_capstyle, dash_joinstyle, solid_joinstyle, pickradius, drawstyle, markevery, **kwargs)
364 # update kwargs before updating data to give the caller a
365 # chance to init axes (and hence unit support)
--> 366 self.update(kwargs)
367 self.pickradius = pickradius
368 self.ind_offset = 0
/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in update(self, props)
854 func = getattr(self, 'set_' + k, None)
855 if func is None or not six.callable(func):
--> 856 raise AttributeError('Unknown property %s' % k)
857 func(v)
858 changed = True
AttributeError: Unknown property color_cycle
I have a 64 bit linux OS and the most recent anaconda installed.
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.