I'm fairly new to Python, and I have just purchased a M1 MacBook Air. I'm trying to reproduce some of the codes I've written in my previous windows computer, and they do not seem to be working properly.
When I try to use Matplotlib with LaTEx, I get an error stating that there is a missing font. The funny thing is that the same code runs fine as a regular .py (python) file, but shows an error message when I run it as a .ipynb (Jupyter notebook) file!
#Loads libraries
import matplotlib.pyplot as plt
import numpy as np
print("Finished imports")
#Sets default interpreter to Latex
plt.rcParams.update({
"text.usetex": True,
"font.family": "Helvetica"
})
print("Setted Latex interpreter")
%matplotlib inline
A = np.array([1,2,3])
B=A
plt.figure()
plt.plot(A,B)
print("Printed figure")
The error message that displays is the following:
`Finished imports
Setted Latex interpreter
Printed figure
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~/opt/anaconda3/lib/python3.9/site-packages/IPython/core/formatters.py in __call__(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)
~/opt/anaconda3/lib/python3.9/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
149 FigureCanvasBase(fig)
150
--> 151 fig.canvas.print_figure(bytes_io, **kw)
152 data = bytes_io.getvalue()
153 if fmt == 'svg':
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2293 )
2294 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2295 self.figure.draw(renderer)
2296
2297 if bbox_inches:
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
71 #wraps(draw)
72 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 73 result = draw(artist, renderer, *args, **kwargs)
74 if renderer._rasterizing:
75 renderer.stop_rasterizing()
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer)
51 finally:
52 if artist.get_agg_filter() is not None:
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/figure.py in draw(self, renderer)
2835
2836 self.patch.draw(renderer)
-> 2837 mimage._draw_list_compositing_images(
2838 renderer, self, artists, self.suppressComposite)
2839
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer)
51 finally:
52 if artist.get_agg_filter() is not None:
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_base.py in draw(self, renderer)
3089 renderer.stop_rasterizing()
3090
-> 3091 mimage._draw_list_compositing_images(
3092 renderer, self, artists, self.figure.suppressComposite)
3093
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer)
51 finally:
52 if artist.get_agg_filter() is not None:
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)
1157
1158 ticks_to_draw = self._update_ticks()
-> 1159 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
1160 renderer)
1161
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axis.py in _get_tick_bboxes(self, ticks, renderer)
1083 def _get_tick_bboxes(self, ticks, renderer):
1084 """Return lists of bboxes for ticks' label1's and label2's."""
-> 1085 return ([tick.label1.get_window_extent(renderer)
1086 for tick in ticks if tick.label1.get_visible()],
1087 [tick.label2.get_window_extent(renderer)
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axis.py in <listcomp>(.0)
1083 def _get_tick_bboxes(self, ticks, renderer):
1084 """Return lists of bboxes for ticks' label1's and label2's."""
-> 1085 return ([tick.label1.get_window_extent(renderer)
1086 for tick in ticks if tick.label1.get_visible()],
1087 [tick.label2.get_window_extent(renderer)
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/text.py in get_window_extent(self, renderer, dpi)
908
909 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 910 bbox, info, descent = self._get_layout(self._renderer)
911 x, y = self.get_unitless_position()
912 x, y = self.get_transform().transform((x, y))
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/text.py in _get_layout(self, renderer)
307
308 # Full vertical extent of font, including ascenders and descenders:
--> 309 _, lp_h, lp_d = renderer.get_text_width_height_descent(
310 "lp", self._fontproperties,
311 ismath="TeX" if self.get_usetex() else False)
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
257 texmanager = self.get_texmanager()
258 fontsize = prop.get_size_in_points()
--> 259 w, h, d = texmanager.get_text_width_height_descent(
260 s, fontsize, renderer=self)
261 return w, h, d
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
336 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
337 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
--> 338 page, = dvi
339 # A total height (including the descent) needs to be returned.
340 return page.width, page.height + page.descent, page.descent
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/dviread.py in __iter__(self)
235 integers.
236 """
--> 237 while self._read():
238 yield self._output()
239
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/dviread.py in _read(self)
314 while True:
315 byte = self.file.read(1)[0]
--> 316 self._dtable[byte](self, byte)
317 name = self._dtable[byte].__name__
318 if name == "_push":
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/dviread.py in wrapper(self, byte)
164 if state is not None and self.state != state:
165 raise ValueError("state precondition failed")
--> 166 return method(self, *[f(self, byte-min) for f in get_args])
167 if max is None:
168 table[min] = wrapper
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/dviread.py in _fnt_def(self, k, c, s, d, a, l)
465 #_dispatch(min=243, max=246, args=('olen1', 'u4', 'u4', 'u4', 'u1', 'u1'))
466 def _fnt_def(self, k, c, s, d, a, l):
--> 467 self._fnt_def_real(k, c, s, d, a, l)
468
469 def _fnt_def_real(self, k, c, s, d, a, l):
~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/dviread.py in _fnt_def_real(self, k, c, s, d, a, l)
472 tfm = _tfmfile(fontname)
473 if tfm is None:
--> 474 raise FileNotFoundError("missing font metrics file: %s" % fontname)
475 if c != 0 and tfm.checksum != 0 and c != tfm.checksum:
476 raise ValueError('tfm checksum mismatch: %s' % n)
FileNotFoundError: missing font metrics file: phvr7t
<Figure size 640x480 with 1 Axes>
I've installed MacTex, so I believe that LaTEx should be installed.
What is interesting is that:
The code works fine when I run it from the terminal (using a regular .py file, instead of the Jupyter notebook);
The plot is successfully generated if I omit the lines that se the default interpreter to LaTEx.
I've installed python through Anaconda, and I've tried to run the code on Jupyter notebook, Jupyter lab and on VS Code.
Thank you - and sorry in advance if the question is not properly formatted. This is my first question asked here in Stack Overflow. :-)
Related
I know there are a few similar questions related to this but I have absolutely no idea on what to do. I am absolutely a newbie when it comes to this so if possible a step-by-step guide would be extremely helpful.
So I have been trying to write a simple code in Jupyter notebook:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
rc('text', usetex=True)
plt.rcParams.update({'font.size': 22})
zeta = np.arange(10**-6,10**4,1000)
N0 = 50
ns = 1-(3*(1+16*zeta*N0/3))/(N0*(1+8*zeta*N0))
plt.plot(zeta,ns)
plt.show()
This is my code. And I am getting the following error:
FileNotFoundError Traceback (most recent call last)
~\anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)
~\anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
149 FigureCanvasBase(fig)
150
--> 151 fig.canvas.print_figure(bytes_io, **kw)
152 data = bytes_io.getvalue()
153 if fmt == 'svg':
~\anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2228 else suppress())
2229 with ctx:
-> 2230 self.figure.draw(renderer)
2231
2232 if bbox_inches:
~\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
72 #wraps(draw)
73 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 74 result = draw(artist, renderer, *args, **kwargs)
75 if renderer._rasterizing:
76 renderer.stop_rasterizing()
~\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
~\anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
2788
2789 self.patch.draw(renderer)
-> 2790 mimage._draw_list_compositing_images(
2791 renderer, self, artists, self.suppressComposite)
2792
~\anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
~\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
~\anaconda3\lib\site-packages\matplotlib\_api\deprecation.py in wrapper(*inner_args, **inner_kwargs)
429 else deprecation_addendum,
430 **kwargs)
--> 431 return func(*inner_args, **inner_kwargs)
432
433 return wrapper
~\anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2919 renderer.stop_rasterizing()
2920
-> 2921 mimage._draw_list_compositing_images(renderer, self, artists)
2922
2923 renderer.close_group('axes')
~\anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
~\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
~\anaconda3\lib\site-packages\matplotlib\axis.py in draw(self, renderer, *args, **kwargs)
1140
1141 ticks_to_draw = self._update_ticks()
-> 1142 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
1143 renderer)
1144
~\anaconda3\lib\site-packages\matplotlib\axis.py in _get_tick_bboxes(self, ticks, renderer)
1066 def _get_tick_bboxes(self, ticks, renderer):
1067 """Return lists of bboxes for ticks' label1's and label2's."""
-> 1068 return ([tick.label1.get_window_extent(renderer)
1069 for tick in ticks if tick.label1.get_visible()],
1070 [tick.label2.get_window_extent(renderer)
~\anaconda3\lib\site-packages\matplotlib\axis.py in <listcomp>(.0)
1066 def _get_tick_bboxes(self, ticks, renderer):
1067 """Return lists of bboxes for ticks' label1's and label2's."""
-> 1068 return ([tick.label1.get_window_extent(renderer)
1069 for tick in ticks if tick.label1.get_visible()],
1070 [tick.label2.get_window_extent(renderer)
~\anaconda3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
901
902 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 903 bbox, info, descent = self._get_layout(self._renderer)
904 x, y = self.get_unitless_position()
905 x, y = self.get_transform().transform((x, y))
~\anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
304
305 # Full vertical extent of font, including ascenders and descenders:
--> 306 _, lp_h, lp_d = renderer.get_text_width_height_descent(
307 "lp", self._fontproperties,
308 ismath="TeX" if self.get_usetex() else False)
~\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
227 texmanager = self.get_texmanager()
228 fontsize = prop.get_size_in_points()
--> 229 w, h, d = texmanager.get_text_width_height_descent(
230 s, fontsize, renderer=self)
231 return w, h, d
~\anaconda3\lib\site-packages\matplotlib\texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
399 dvifile = self.make_dvi(tex, fontsize)
400 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
--> 401 page, = dvi
402 # A total height (including the descent) needs to be returned.
403 return page.width, page.height + page.descent, page.descent
~\anaconda3\lib\site-packages\matplotlib\dviread.py in __iter__(self)
249 integers.
250 """
--> 251 while self._read():
252 yield self._output()
253
~\anaconda3\lib\site-packages\matplotlib\dviread.py in _read(self)
329 while True:
330 byte = self.file.read(1)[0]
--> 331 self._dtable[byte](self, byte)
332 downs += self._dtable[byte].__name__ == "_down"
333 if (self._baseline_v is None
~\anaconda3\lib\site-packages\matplotlib\dviread.py in wrapper(self, byte)
172 if state is not None and self.state != state:
173 raise ValueError("state precondition failed")
--> 174 return method(self, *[f(self, byte-min) for f in get_args])
175 if max is None:
176 table[min] = wrapper
~\anaconda3\lib\site-packages\matplotlib\dviread.py in _fnt_def(self, k, c, s, d, a, l)
474 #_dispatch(min=243, max=246, args=('olen1', 'u4', 'u4', 'u4', 'u1', 'u1'))
475 def _fnt_def(self, k, c, s, d, a, l):
--> 476 self._fnt_def_real(k, c, s, d, a, l)
477
478 def _fnt_def_real(self, k, c, s, d, a, l):
~\anaconda3\lib\site-packages\matplotlib\dviread.py in _fnt_def_real(self, k, c, s, d, a, l)
481 tfm = _tfmfile(fontname)
482 if tfm is None:
--> 483 raise FileNotFoundError("missing font metrics file: %s" % fontname)
484 if c != 0 and tfm.checksum != 0 and c != tfm.checksum:
485 raise ValueError('tfm checksum mismatch: %s' % n)
FileNotFoundError: missing font metrics file: cmss17
I am not sure if I should be placing the whole error here but this is what I am getting when I try plotting the graph. The only thing which I could think of is the fact that some file which is used to write things on the graph is missing but I don't know how to resolve this. Any help would be appreciated.
Thank You.
I just came across the same error, in my case I needed to use latex. I found out that if other fonts are correctly installed, changing the default font can resolve the issue:
plt.rcParams.update({
"text.usetex": True,
"font.family": "sans-serif",
"font.sans-serif": ["Helvetica"]})
You could insert this script at line 6 of your code and see if it helps.
I didn't follow from what you posted what you were looking to be font size 22, and so this does it for the labels of the axis ticks.
Simpler version of what you posted:
import numpy as np
import matplotlib.pyplot as plt
zeta = np.arange(10**-6,10**4,1000)
N0 = 50
ns = 1-(3*(1+16*zeta*N0/3))/(N0*(1+8*zeta*N0))
plt.plot(zeta,ns)
plt.tick_params(labelsize=22)
plt.show()
You can go to here in my comment, open a notebook after the session spins up, and test that code there. You should see it should work. If it doesn't work the same way where you are trying you have something out of date.
The tick formatting basics are illustrated right at the top of Matplotlib's tick formatters documentation in the first block of code. You shouldn't need rc or rcParams any longer in most cases. The syntax is much more obvious now. Any answers using that are either outdated as they aren't using the provided routes or they are covering unusual / edge cases.
I have searched in many forums for an answer to this question, but not found anything that works for me or fully answers the question of what the error means. Below is a reproducible example:
from matplotlib import pyplot as plt
import numpy as np
xTest = [.1,.2,.1]
yTest = [.1,.2,.1]
circleLabels = [0,1,0]
colormap = np.array(['r', 'b'])
colorVec = colormap[circleLabels]
plt.plot(xTest, yTest,"o",color = colorVec)
plt.xlabel('x coordinate')
plt.ylabel('y coordinate')
plt.title("scatterplot of circle points")
Which gives me the error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~/opt/anaconda3/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)
~/opt/anaconda3/lib/python3.8/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
246
247 if 'png' in formats:
--> 248 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
249 if 'retina' in formats or 'png2x' in formats:
250 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
~/opt/anaconda3/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
130 FigureCanvasBase(fig)
131
--> 132 fig.canvas.print_figure(bytes_io, **kw)
133 data = bytes_io.getvalue()
134 if fmt == 'svg':
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2191 else suppress())
2192 with ctx:
-> 2193 self.figure.draw(renderer)
2194
2195 bbox_inches = self.figure.get_tightbbox(
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/figure.py in draw(self, renderer)
1861
1862 self.patch.draw(renderer)
-> 1863 mimage._draw_list_compositing_images(
1864 renderer, self, artists, self.suppressComposite)
1865
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py in wrapper(*inner_args, **inner_kwargs)
409 else deprecation_addendum,
410 **kwargs)
--> 411 return func(*inner_args, **inner_kwargs)
412
413 return wrapper
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2745 renderer.stop_rasterizing()
2746
-> 2747 mimage._draw_list_compositing_images(renderer, self, artists)
2748
2749 renderer.close_group('axes')
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/lines.py in draw(self, renderer)
794 gc.set_antialiased(self._antialiased)
795
--> 796 ec_rgba = mcolors.to_rgba(
797 self.get_markeredgecolor(), self._alpha)
798 fc_rgba = mcolors.to_rgba(
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/colors.py in to_rgba(c, alpha)
187 rgba = None
188 if rgba is None: # Suppress exception chaining of cache lookup failure.
--> 189 rgba = _to_rgba_no_colorcycle(c, alpha)
190 try:
191 _colors_full_map.cache[c, alpha] = rgba
~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
267 # Checks that don't work: `map(float, ...)`, `np.array(..., float)` and
268 # `np.array(...).astype(float)` would all convert "0.5" to 0.5.
--> 269 raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
270 # Return a tuple to prevent the cached value from being modified.
271 c = tuple(map(float, c))
ValueError: Invalid RGBA argument: array(['r', 'b', 'r'], dtype='<U1')
<Figure size 432x288 with 1 Axes>
Following some similar answers, I have tried:
swapping out the c parameter for color -> no effect
using np.squeeze on the color array -> no effect
using a 2-d array for the color vector, with an array of rgb values instead of the string literals "r" and "b" or "red" and "green" -> no effect
Does anyone know how I can fix this while still using the pyplot.plot() function?
Thank you,
Paul
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(?).