Tkinter outputting KeyError when Updating Multiple Matplotlib Objects - python

I am somewhat new to python animation, and I'm getting the following error when I try to update multiple matplotlib 2D objects in FuncAnimation
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/me/anaconda/lib/python3.6/tkinter/__init__.py", line 1699, in __call__
return self.func(*args)
File "/Users/me/anaconda/lib/python3.6/tkinter/__init__.py", line 745, in callit
func(*args)
File "/Users/me/anaconda/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 95, in _on_timer
TimerBase._on_timer(self)
File "/Users/me/anaconda/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 1382, in _on_timer
ret = func(*args, **kwargs)
File "/Users/me/anaconda/lib/python3.6/site-packages/matplotlib/animation.py", line 1542, in _step
still_going = Animation._step(self, *args)
File "/Users/me/anaconda/lib/python3.6/site-packages/matplotlib/animation.py", line 1277, in _step
self._draw_next_frame(framedata, self._blit)
File "/Users/me/anaconda/lib/python3.6/site-packages/matplotlib/animation.py", line 1296, in _draw_next_frame
self._draw_frame(framedata)
File "/Users/me/anaconda/lib/python3.6/site-packages/matplotlib/animation.py", line 1814, in _draw_frame
self._drawn_artists = self._func(framedata, *self._args)
File "<ipython-input-73-4c78ddeac2f8>", line 10, in animate
moving_x = [0, orbradii[ii]*np.cos(angle)]
File "/Users/me/anaconda/lib/python3.6/site-packages/pandas/core/series.py", line 623, in __getitem__
result = self.index.get_value(self, key)
File "/Users/me/anaconda/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 2557, in get_value
tz=getattr(series.dtype, 'tz', None))
File "pandas/_libs/index.pyx", line 83, in pandas._libs.index.IndexEngine.get_value
File "pandas/_libs/index.pyx", line 91, in pandas._libs.index.IndexEngine.get_value
File "pandas/_libs/index.pyx", line 139, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 811, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 817, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0
Following is the code that I wrote to animate orbital motion. I have been running this in python 3.6 using TkAgg as the backend.
df = pd.read_csv('file.csv')
orbradii = df['radii']
planet_total = len(orbradii)
fig = plt.figure()
ax = fig.add_subplot(111, xlim=(-max(orbradii), max(orbradii)), ylim=(-max(orb_radii), max(orb_radii)))
lines = []
for _ in range(planet_total):
lines.append(ax.plot([], [], 'o'))
def init():
#set the data to empty lists for the x, y coordinates, respectively
for ii in range(len(lines)):
print(lines[ii])
lines[ii][0].set_data([], [])
return lines
def animate(i):
angle = i/10. * np.pi
for ii in range(planet_total):
moving_x = [0, orbradii[ii]*np.cos(angle)]
moving_y = [0, orbradii[ii]*np.sin(angle)]
#set the x, y coordinates to these new values
print(lines[ii])
lines[ii][0].set_data(moving_x, moving_y)
return lines
our_animation = ani.FuncAnimation(fig, animate, np.arange(1, 1000), interval=75, init_func=init)
plt.show()
Thank you for your help!
EDIT:
Thanks to Tom's comment, I realized that if I convert the orbradii variable to values, my code works.
orbradii = df['radii'].values

Related

Sympy matrix exponential raises ValueError

I have a 3x3 symbolic matrix and I want to calculate the matrix exponential of it using Sympy.
from sympy import *
a0,a1,y0,y1,k,t = symbols('a0 a1 y0 y1 k t')
A = Matrix([[-y1*t-a1*t,-y0*t,0],[t,-a1*t,-k*t],[0,t,-a1*t]])
res = exp(A)
print(res)
This gives the following error:
Warning (from warnings module):
File "/usr/lib/python3/dist-packages/apport/report.py", line 13
import fnmatch, glob, traceback, errno, sys, atexit, locale, imp, stat
DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/sympy/core/cache.py", line 94, in wrapper
retval = cfunc(*args, **kwargs)
TypeError: unhashable type: 'MutableDenseMatrix'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/sympy/core/cache.py", line 94, in wrapper
retval = cfunc(*args, **kwargs)
TypeError: unhashable type: 'MutableDenseMatrix'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/sympy/core/compatibility.py", line 419, in as_int
raise TypeError
TypeError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
exec(code, self.locals)
File "/home/kaguro/Documents/PROJECT/Paper-simulation/Finite-time/Model B/extra.py", line 7, in <module>
res = exp(At)
File "/usr/lib/python3/dist-packages/sympy/core/cache.py", line 96, in wrapper
retval = func(*args, **kwargs)
File "/usr/lib/python3/dist-packages/sympy/core/function.py", line 473, in __new__
result = super(Function, cls).__new__(cls, *args, **options)
File "/usr/lib/python3/dist-packages/sympy/core/cache.py", line 96, in wrapper
retval = func(*args, **kwargs)
File "/usr/lib/python3/dist-packages/sympy/core/function.py", line 288, in __new__
evaluated = cls.eval(*args)
File "/usr/lib/python3/dist-packages/sympy/functions/elementary/exponential.py", line 320, in eval
return arg.exp()
File "/usr/lib/python3/dist-packages/sympy/matrices/matrices.py", line 3208, in exp
P, J = self.jordan_form()
File "/usr/lib/python3/dist-packages/sympy/matrices/matrices.py", line 1811, in jordan_form
jordan_basis = [eig_mat(eig, 1).nullspace()[0] for eig in blocks]
File "/usr/lib/python3/dist-packages/sympy/matrices/matrices.py", line 1811, in <listcomp>
jordan_basis = [eig_mat(eig, 1).nullspace()[0] for eig in blocks]
File "/usr/lib/python3/dist-packages/sympy/matrices/matrices.py", line 1011, in nullspace
reduced, pivots = self.rref(iszerofunc=iszerofunc, simplify=simplify)
File "/usr/lib/python3/dist-packages/sympy/matrices/matrices.py", line 941, in rref
ret, pivot_cols = self._eval_rref(iszerofunc=iszerofunc,
File "/usr/lib/python3/dist-packages/sympy/matrices/matrices.py", line 593, in _eval_rref
reduced, pivot_cols, swaps = self._row_reduce(iszerofunc, simpfunc,
File "/usr/lib/python3/dist-packages/sympy/matrices/matrices.py", line 713, in _row_reduce
assumed_nonzero, newly_determined = _find_reasonable_pivot(
File "/usr/lib/python3/dist-packages/sympy/matrices/matrices.py", line 5327, in _find_reasonable_pivot
if x.equals(S.Zero):
File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 757, in equals
constant = diff.is_constant(simplify=False, failing_number=True)
File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 683, in is_constant
if b is not None and b is not S.NaN and b.equals(a) is False:
File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 834, in equals
mp = minimal_polynomial(diff)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 655, in minimal_polynomial
result = _minpoly_compose(ex, x, domain)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 534, in _minpoly_compose
res = _minpoly_add(x, dom, *ex.args)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 362, in _minpoly_add
mp = _minpoly_op_algebraic_element(Add, a[0], a[1], x, dom)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 242, in _minpoly_op_algebraic_element
mp1 = _minpoly_compose(ex1, x, dom)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 547, in _minpoly_compose
mp1 = minimal_polynomial(ex1, x)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 655, in minimal_polynomial
result = _minpoly_compose(ex, x, domain)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 557, in _minpoly_compose
res = _minpoly_mul(x, dom, *ex.args)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 374, in _minpoly_mul
mp = _minpoly_op_algebraic_element(Mul, a[0], a[1], x, dom)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 244, in _minpoly_op_algebraic_element
mp2 = _minpoly_compose(ex2, y, dom)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 559, in _minpoly_compose
res = _minpoly_pow(ex.base, ex.exp, x, dom)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 337, in _minpoly_pow
mp = _minpoly_compose(ex, x, dom)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 534, in _minpoly_compose
res = _minpoly_add(x, dom, *ex.args)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 362, in _minpoly_add
mp = _minpoly_op_algebraic_element(Add, a[0], a[1], x, dom)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 279, in _minpoly_op_algebraic_element
res = _choose_factor(factors, x, op(ex1, ex2), dom)
File "/usr/lib/python3/dist-packages/sympy/polys/numberfields.py", line 70, in _choose_factor
if abs(f.as_expr().evalf(prec1, points)) < eps:
File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 171, in __abs__
return Abs(self)
File "/usr/lib/python3/dist-packages/sympy/core/cache.py", line 94, in wrapper
retval = cfunc(*args, **kwargs)
File "/usr/lib/python3/dist-packages/sympy/core/function.py", line 473, in __new__
result = super(Function, cls).__new__(cls, *args, **options)
File "/usr/lib/python3/dist-packages/sympy/core/cache.py", line 94, in wrapper
retval = cfunc(*args, **kwargs)
File "/usr/lib/python3/dist-packages/sympy/core/function.py", line 288, in __new__
evaluated = cls.eval(*args)
File "/usr/lib/python3/dist-packages/sympy/functions/elementary/complexes.py", line 473, in eval
arg = signsimp(arg, evaluate=False)
File "/usr/lib/python3/dist-packages/sympy/simplify/simplify.py", line 383, in signsimp
e = sub_post(sub_pre(expr))
File "/usr/lib/python3/dist-packages/sympy/simplify/cse_opts.py", line 16, in sub_pre
adds = [a for a in e.atoms(Add) if a.could_extract_minus_sign()]
File "/usr/lib/python3/dist-packages/sympy/simplify/cse_opts.py", line 16, in <listcomp>
adds = [a for a in e.atoms(Add) if a.could_extract_minus_sign()]
File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 2386, in could_extract_minus_sign
(negative_self).extract_multiplicatively(-1) is not None)
File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 2208, in extract_multiplicatively
newarg = arg.extract_multiplicatively(c)
File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 2221, in extract_multiplicatively
newarg = arg.extract_multiplicatively(c)
File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 2134, in extract_multiplicatively
elif c == self:
File "/usr/lib/python3/dist-packages/sympy/core/numbers.py", line 2248, in __eq__
return Rational.__eq__(self, other)
File "/usr/lib/python3/dist-packages/sympy/core/numbers.py", line 1906, in __eq__
integer_log(self.p//m, 2) == (t, True)
File "/usr/lib/python3/dist-packages/sympy/core/power.py", line 147, in integer_log
y = as_int(y)
File "/usr/lib/python3/dist-packages/sympy/core/compatibility.py", line 425, in as_int
raise ValueError('%s is not an integer' % (n,))
ValueError: 1 is not an integer
I don't understand why is it not working. Earlier I had used a 2x2 matrix with similar kind of form, and it worked perfectly (albeit very complicated looking).
The eigenvalues can be found of this matrix, but asking for eigenvectors gives the same error. So I can't use the diagonalisation method manually either (didn't expect this to work, because then Sympy would have done that).
Any help would be greatly appreciated.

Unable to type latex \lVert symbol with matplotlib

Using LaTeX with matplotlib I'm able to reproduce several commands. For example:
import numpy as np
import matplotlib.pyplot as plt
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
fig = plt.figure()
ax = fig.add_subplot()
foo = np.arange(8)
ax.plot(foo, foo, label=r"$\omega$")
ax.legend()
correctly gives the desired output.
However, I can't understand why I am unable to use the command \lVert. Changing in the previous code:
ax.plot(foo, foo, label=r"$\omega$")
to:
ax.plot(foo, foo, label=r"$\lVert \omega \lVert$"),
gives the following error:
Traceback (most recent call last):
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\texmanager.py", line 275, in _run_checked_subprocess
report = subprocess.check_output(command,
File "C:\Users\admin\anaconda3\lib\subprocess.py", line 415, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Users\admin\anaconda3\lib\subprocess.py", line 516, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', 'C:\\Users\\admin\\.matplotlib\\tex.cache\\2937b4303e7d9aeb9070eea14ecf2572.tex']' returned non-zero exit status 1.
Following the docs and some answers, I deleted my .matplotlib/tex.cache but it didn't work out. I also checked Miktex (my LaTeX distribution) is in my Windows PATH.
The whole error message is the following:
Traceback (most recent call last):
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\texmanager.py", line 275, in _run_checked_subprocess
report = subprocess.check_output(command,
File "C:\Users\admin\anaconda3\lib\subprocess.py", line 415, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Users\admin\anaconda3\lib\subprocess.py", line 516, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', 'C:\\Users\\admin\\.matplotlib\\tex.cache\\01217377e7c38555f6bd8b50bf425d29.tex']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 480, in _draw_idle
self.draw()
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 407, in draw
self.figure.draw(self.renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\figure.py", line 1863, in draw
mimage._draw_list_compositing_images(
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py", line 411, in wrapper
return func(*inner_args, **inner_kwargs)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2747, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\legend.py", line 606, in draw
bbox = self._legend_box.get_window_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 346, in get_window_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 471, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 471, in <listcomp>
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 341, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 544, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 544, in <listcomp>
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 341, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 471, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 471, in <listcomp>
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 341, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 544, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 544, in <listcomp>
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 886, in get_extent
bbox, info, d = self._text._get_layout(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\text.py", line 295, in _get_layout
w, h, d = renderer.get_text_width_height_descent(
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 227, in get_text_width_height_descent
w, h, d = texmanager.get_text_width_height_descent(
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\texmanager.py", line 423, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\texmanager.py", line 309, in make_dvi
self._run_checked_subprocess(
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\texmanager.py", line 283, in _run_checked_subprocess
raise RuntimeError(
RuntimeError: latex was not able to process the following string:
b'$\\\\lVert \\\\omega \\\\lVert$'
Here is the full report generated by latex:
latex: security risk: running with elevated privileges
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (MiKTeX 21.12.10) (preloaded format=latex.fmt)
restricted \write18 enabled.
entering extended mode
(C:/Users/admin/.matplotlib/tex.cache/01217377e7c38555f6bd8b50bf425d29.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2021-11-22>
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/base\article.cls
Document Class: article 2021/10/04 v1.4n Standard LaTeX document class
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/base\size10.clo))
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/type1cm\type1cm.sty)
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/cm-super\type1ec.sty
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/base\t1cmr.fd))
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/base\inputenc.sty)
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/geometry\geometry.sty
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/graphics\keyval.sty)
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/generic/iftex\ifvtex.sty
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/generic/iftex\iftex.sty))
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/geometry\geometry.cfg)
Package geometry Warning: Over-specification in `h'-direction.
`width' (5058.9pt) is ignored.
Package geometry Warning: Over-specification in `v'-direction.
`height' (5058.9pt) is ignored.
) (C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/base\textcomp.sty)
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/l3backend\l3backend-dvi
ps.def) (01217377e7c38555f6bd8b50bf425d29.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: dvips
! Undefined control sequence.
<recently read> \lVert
l.19 {\rmfamily $\lVert
\omega \lVert$}
No pages of output.
Transcript written on 01217377e7c38555f6bd8b50bf425d29.log.
Traceback (most recent call last):
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\texmanager.py", line 275, in _run_checked_subprocess
report = subprocess.check_output(command,
File "C:\Users\admin\anaconda3\lib\subprocess.py", line 415, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Users\admin\anaconda3\lib\subprocess.py", line 516, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', 'C:\\Users\\admin\\.matplotlib\\tex.cache\\01217377e7c38555f6bd8b50bf425d29.tex']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 480, in _draw_idle
self.draw()
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 407, in draw
self.figure.draw(self.renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\figure.py", line 1863, in draw
mimage._draw_list_compositing_images(
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py", line 411, in wrapper
return func(*inner_args, **inner_kwargs)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2747, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\legend.py", line 606, in draw
bbox = self._legend_box.get_window_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 346, in get_window_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 471, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 471, in <listcomp>
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 341, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 544, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 544, in <listcomp>
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 341, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 471, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 471, in <listcomp>
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 341, in get_extent
w, h, xd, yd, offsets = self.get_extent_offsets(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 544, in get_extent_offsets
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 544, in <listcomp>
whd_list = [c.get_extent(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\offsetbox.py", line 886, in get_extent
bbox, info, d = self._text._get_layout(renderer)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\text.py", line 295, in _get_layout
w, h, d = renderer.get_text_width_height_descent(
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 227, in get_text_width_height_descent
w, h, d = texmanager.get_text_width_height_descent(
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\texmanager.py", line 423, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\texmanager.py", line 309, in make_dvi
self._run_checked_subprocess(
File "C:\Users\admin\anaconda3\lib\site-packages\matplotlib\texmanager.py", line 283, in _run_checked_subprocess
raise RuntimeError(
RuntimeError: latex was not able to process the following string:
b'$\\\\lVert \\\\omega \\\\lVert$'
Here is the full report generated by latex:
latex: security risk: running with elevated privileges
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (MiKTeX 21.12.10) (preloaded format=latex.fmt)
restricted \write18 enabled.
entering extended mode
(C:/Users/admin/.matplotlib/tex.cache/01217377e7c38555f6bd8b50bf425d29.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2021-11-22>
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/base\article.cls
Document Class: article 2021/10/04 v1.4n Standard LaTeX document class
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/base\size10.clo))
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/type1cm\type1cm.sty)
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/cm-super\type1ec.sty
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/base\t1cmr.fd))
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/base\inputenc.sty)
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/geometry\geometry.sty
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/graphics\keyval.sty)
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/generic/iftex\ifvtex.sty
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/generic/iftex\iftex.sty))
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/geometry\geometry.cfg)
Package geometry Warning: Over-specification in `h'-direction.
`width' (5058.9pt) is ignored.
Package geometry Warning: Over-specification in `v'-direction.
`height' (5058.9pt) is ignored.
) (C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/base\textcomp.sty)
(C:\Users\admin\AppData\Local\Programs\MiKTeX\tex/latex/l3backend\l3backend-dvi
ps.def) (01217377e7c38555f6bd8b50bf425d29.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: dvips
! Undefined control sequence.
<recently read> \lVert
l.19 {\rmfamily $\lVert
\omega \lVert$}
No pages of output.
Transcript written on 01217377e7c38555f6bd8b50bf425d29.log.

How to calculate values from functions without returning them or setting them global (for numba.cuda)?

I am trying to run this simple code on a CUDA GPU. The module I am using for this is numba.cuda:
import numba
from numba import cuda
#numba.cuda.jit
def function_4(j, k):
l = j + k
return l
l = function_4(1, 2)
print(l)
Output:
Traceback (most recent call last):
File "/home/amu/Desktop/RL_framework/help_functions/test2.py", line 9, in <module>
l = function_4(1, 2)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/cuda/compiler.py", line 758, in __call__
kernel = self.specialize(*args)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/cuda/compiler.py", line 769, in specialize
kernel = self.compile(argtypes)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/cuda/compiler.py", line 785, in compile
**self.targetoptions)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/cuda/compiler.py", line 57, in compile_kernel
cres = compile_cuda(pyfunc, types.void, args, debug=debug, inline=inline)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/cuda/compiler.py", line 46, in compile_cuda
locals={})
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler.py", line 568, in compile_extra
return pipeline.compile_extra(func)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler.py", line 339, in compile_extra
return self._compile_bytecode()
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler.py", line 401, in _compile_bytecode
return self._compile_core()
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler.py", line 381, in _compile_core
raise e
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler.py", line 372, in _compile_core
pm.run(self.state)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 341, in run
raise patched_exception
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 332, in run
self._runPass(idx, pass_inst, state)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 291, in _runPass
mutated |= check(pss.run_pass, internal_state)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 264, in check
mangled = func(compiler_state)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/typed_passes.py", line 98, in run_pass
raise_errors=self._raise_errors)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/typed_passes.py", line 70, in type_inference_stage
infer.propagate(raise_errors=raise_errors)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/typeinfer.py", line 986, in propagate
raise errors[0]
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No conversion from int64 to none for '$12return_value.4', defined at None
File "test2.py", line 7:
def function_4(j, k):
<source elided>
l = j + k
return l
^
[1] During: typing of assignment at /home/amu/Desktop/RL_framework/help_functions/test2.py (7)
File "test2.py", line 7:
def function_4(j, k):
<source elided>
l = j + k
return l
^
numba.cuda does not support the return statement. So how do I use functions to calculate values? The global statement seems not to be supported either:
import numba
from numba import cuda
#numba.cuda.jit
def function_4(j, k):
global l
l = j + k
function_4(1, 2)
print(l)
Output:
Traceback (most recent call last):
File "/home/amu/Desktop/RL_framework/help_functions/test.py", line 9, in <module>
function_4(1, 2)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/cuda/compiler.py", line 758, in __call__
kernel = self.specialize(*args)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/cuda/compiler.py", line 769, in specialize
kernel = self.compile(argtypes)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/cuda/compiler.py", line 785, in compile
**self.targetoptions)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/cuda/compiler.py", line 57, in compile_kernel
cres = compile_cuda(pyfunc, types.void, args, debug=debug, inline=inline)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/cuda/compiler.py", line 46, in compile_cuda
locals={})
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler.py", line 568, in compile_extra
return pipeline.compile_extra(func)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler.py", line 339, in compile_extra
return self._compile_bytecode()
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler.py", line 401, in _compile_bytecode
return self._compile_core()
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler.py", line 381, in _compile_core
raise e
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler.py", line 372, in _compile_core
pm.run(self.state)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 341, in run
raise patched_exception
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 332, in run
self._runPass(idx, pass_inst, state)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 291, in _runPass
mutated |= check(pss.run_pass, internal_state)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 264, in check
mangled = func(compiler_state)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/untyped_passes.py", line 86, in run_pass
func_ir = interp.interpret(bc)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/interpreter.py", line 116, in interpret
flow.run()
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/byteflow.py", line 107, in run
runner.dispatch(state)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/byteflow.py", line 269, in dispatch
raise UnsupportedError(msg, loc=self.get_debug_loc(inst.lineno))
numba.core.errors.UnsupportedError: Failed in nopython mode pipeline (step: analyzing bytecode)
Use of unsupported opcode (STORE_GLOBAL) found
File "test.py", line 7:
def function_4(j, k):
<source elided>
global l
l = j + k
^
Your code would need to look something like this:
import numpy as np
import numba
from numba import cuda
#cuda.jit
def function_4(i, j, k):
i[0] = j[0] + k[0]
j = np.array([1], dtype=np.int32)
k = np.array([2], dtype=np.int32)
i = np.zeros_like(j)
function_4[1,1](i, j, k)
print(i[0])
[Note code written on a phone in an airport departure lounge, never tested, use at own risk]
Basically everything had to be passed as arrays with explicit dtypes. If your intention is to write kernels, you would be better served starting in CUDAs native C++ dialect, which is well documented, and then coming back to Numba, which isn't. Then everything will be self-evident

plot dates and values in python

I have a file containing data as below. you see the first column is dates. I need to plot all other columns against dates in the first column. I tried to use the code below but I receive an error message. the code an error are provided.
Data
2010-01-01,1.628,0.7063157895,0,0.9216842105
2010-01-03,1.602631579,0.6901052632,0,0.9125263158
2010-01-04,1.5818947369,0.6775789474,0,0.9043157895
2010-01-05,1.5755789473,0.6716842105,0,0.9038947368
2010-01-06,1.5605263158,0.6622105263,0,0.8983157895
2010-01-07,1.5611578948,0.6608421053,0,0.9003157895
2010-01-08,1.5598947369,0.6593684211,0,0.9005263158
2010-01-09,1.5576842105,0.6569473684,0,0.9007368421
2010-01-10,1.5462105263,0.6543157895,0,0.8918947368
2010-01-11,1.5656842105,0.6666315789,0,0.8990526316
2010-01-12,1.5517894736,0.6546315789,0,0.8971578947
2010-01-13,1.5558947368,0.6551578947,0,0.9007368421
2010-01-14,1.5638947369,0.6588421053,0,0.9050526316
2010-01-15,1.5375789474,0.6432631579,0,0.8943157895
2010-01-16,1.522631579,0.6352631579,0,0.8873684211
2010-01-17,1.5056842105,0.6254736842,0,0.8802105263
2010-01-18,1.4881052632,0.6157894737,0,0.8723157895
2010-01-19,1.4889842789,0.6251948052,0,0.8637894737
2010-01-20,1.4733383459,0.6182857143,0,0.8550526316
2010-01-21,1.4507368421,0.6009473684,0,0.8497894737
Code
import csv
import datetime as dt
import matplotlib.pyplot as plt
lis1=[]
lis2=[]
lis3=[]
lis4=[]
lis5=[]
with open('/home/omar/Desktop/finall.csv', 'rU') as f:
reader=csv.reader(f, delimiter=',')
for row in reader:
lis1.append(dt.datetime.strptime(row[0],'%Y-%m-%d'))
lis2.append(row[1])
lis3.append(row[2])
lis4.append(row[3])
lis5.append(row[4])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(lis1,lis2,lis3,lis4,lis5,'o-')
fig.autofmt_xdate()
plt.show()
Error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/widge/externalshell/sitecustomize.py", line 540, in runfile execfile(filename, namespace)
File "/home/omar/python/plot_txt.py", line 37, in <module>
fig.autofmt_xdate()
File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 431, in autofmt_xdate
for label in self.axes[0].get_xticklabels():
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 2614, in get_xticklabels
self.xaxis.get_ticklabels(minor=minor))
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1161, in get_ticklabels
return self.get_majorticklabels()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1145, in get_majorticklabels
ticks = self.get_major_ticks()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1244, in get_major_ticks
numticks = len(self.get_major_locator()())
File "/usr/lib/pymodules/python2.7/matplotlib/dates.py", line 802, in __call__
self.refresh()
File "/usr/lib/pymodules/python2.7/matplotlib/dates.py", line 819, in refresh
dmin, dmax = self.viewlim_to_dt()
File "/usr/lib/pymodules/python2.7/matplotlib/dates.py", line 564, in viewlim_to_dt
return num2date(vmin, self.tz), num2date(vmax, self.tz)
File "/usr/lib/pymodules/python2.7/matplotlib/dates.py", line 311, in num2date
return _from_ordinalf(x, tz)
File "/usr/lib/pymodules/python2.7/matplotlib/dates.py", line 214, in _from_ordinalf
dt = datetime.datetime.fromordinal(ix)
ValueError: ordinal must be >= 1
>>> Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_qt4.py", line 374, in idle_draw
self.draw()
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_qt4agg.py", line 154, in draw
FigureCanvasAgg.draw(self)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 451, in draw
self.figure.draw(self.renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1034, in draw
func(*args)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 2086, in draw
a.draw(renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1091, in draw ticks_to_draw = self._update_ticks(renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 945, in _update_ticks
tick_tups = [t for t in self.iter_ticks()]
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 889, in iter_ticks
majorLocs = self.major.locator()
File "/usr/lib/pymodules/python2.7/matplotlib/dates.py", line 802, in __call__
self.refresh()
File "/usr/lib/pymodules/python2.7/matplotlib/dates.py", line 819, in refresh
dmin, dmax = self.viewlim_to_dt()
File "/usr/lib/pymodules/python2.7/matplotlib/dates.py", line 564, in viewlim_to_dt
return num2date(vmin, self.tz), num2date(vmax, self.tz)
File "/usr/lib/pymodules/python2.7/matplotlib/dates.py", line 311, in num2date
return _from_ordinalf(x, tz)
File "/usr/lib/pymodules/python2.7/matplotlib/dates.py", line 214, in _from_ordinalf
dt = datetime.datetime.fromordinal(ix)
ValueError: ordinal must be >= 1
The error is in your plot command.
You need to repeat what is on the x axis for each field you plot on the y axis.
So change this:
ax.plot(lis1,lis2,lis3,lis4,lis5,'o-')
to this:
ax.plot(lis1,lis2,lis1,lis3,lis1,lis4,lis1,lis5,'o-')
try:
import csv
import datetime as dt
import matplotlib.pyplot as plt
lis1=[]
lis2=[]
lis3=[]
lis4=[]
lis5=[]
with open('/home/omar/Desktop/finall.csv', 'rU') as f:
reader=csv.reader(f, delimiter=',')
for row in reader:
lis1.append(dt.datetime.strptime(row[0],'%Y-%m-%d'))
lis2.append(row[1])
lis3.append(row[2])
lis4.append(row[3])
lis5.append(row[4])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot_date(lis1,lis2,'o-',
lis1,lis3,'o-',
lis1,lis4,'o-',
lis1,lis5,'o-')
plt.show()
see documentation here: http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot

How to get rid of maximum recursion depth error while plotting interactively?

I'm trying to build an interactive plot. This one is supposed to clear the figure if clicked within axes and draw a circle at a random place. The code is as follows:
import matplotlib.pyplot as plt
import random
def draw_circle(event):
if event.inaxes:
print(event.xdata, event.ydata)
plt.cla()
a = random.randint(0,100)
b = random.randint(0,100)
s, = plt.plot(a,b,'o', ms=100, color="blue",visible=True )
plt.show()
fig = plt.figure()
ax = plt.subplot(111)
s, = plt.plot(1,2,'o', ms=100, color="blue",visible=True )
plt.connect("button_press_event", draw_circle)
plt.show()
After clicking for 42 times, the program breaks and I get the following traceback:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 286, in button_press_event
FigureCanvasBase.button_press_event(self, x, y, num, guiEvent=event)
File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1632, in button_press_event
self.callbacks.process(s, mouseevent)
File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 262, in process
proxy(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 192, in __call__
return mtd(*args, **kwargs)
File "/home/almarahat/Dropbox/python/GUI/Testing site/test_rt/baud_test.py", line 8, in draw_circle
plt.cla()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2784, in cla
ret = gca().cla()
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 842, in cla
spine.cla()
File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 157, in cla
self.axis.cla()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 731, in cla
self.reset_ticks()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 744, in reset_ticks
self.majorTicks.extend([self._get_tick(major=True)])
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1553, in _get_tick
return XTick(self.axes, 0, '', major=major, **tick_kw)
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 141, in __init__
self.tick2line = self._get_tick2line()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 401, in _get_tick2line
l.set_transform(self.axes.get_xaxis_transform(which='tick2'))
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 586, in get_xaxis_transform
return self.spines['top'].get_spine_transform()
File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 374, in get_spine_transform
self._ensure_position_is_set()
File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 140, in _ensure_position_is_set
self.set_position(self._position)
File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 365, in set_position
self.axis.cla()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 731, in cla
self.reset_ticks()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 744, in reset_ticks
self.majorTicks.extend([self._get_tick(major=True)])
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1553, in _get_tick
return XTick(self.axes, 0, '', major=major, **tick_kw)
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 140, in __init__
self.tick1line = self._get_tick1line()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 383, in _get_tick1line
zorder=self._zorder,
File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 195, in __init__
self._marker = MarkerStyle()
File "/usr/lib/pymodules/python2.7/matplotlib/markers.py", line 112, in __init__
self.set_marker(marker)
File "/usr/lib/pymodules/python2.7/matplotlib/markers.py", line 171, in set_marker
self._recache()
File "/usr/lib/pymodules/python2.7/matplotlib/markers.py", line 116, in _recache
self._path = Path(np.empty((0,2)))
File "/usr/lib/pymodules/python2.7/matplotlib/path.py", line 112, in __init__
if ma.isMaskedArray(vertices):
File "/usr/local/lib/python2.7/dist-packages/numpy-1.6.2-py2.7-linux-x86_64.egg/numpy/ma/core.py", line 5683, in isMaskedArray
return isinstance(x, MaskedArray)
RuntimeError: maximum recursion depth exceeded while calling a Python object
At this point, I am not certain where the recursion occurs and how to alleviate this error.
I understand (from other Q&As) that I could enhance my stack limit and get around the problem. However, I don't consider that as a solution in this particular case and would like to get to the bottom of this.
Any help would be appreciate.
Thanks in advance.
Additional Information:
The main functionality that matters include clearing the figure and drawing something new on clicking the canvas.
The clicking does not raise this error, if I am not trying to plot something. Thus, I suspect, I'm missing something in handling matplotlib.
Instead of plt.show(), from within your callback call plt.draw(). The problem is that plt.show runs a mainloop of the GUI library; you just want to update what is shown within the existing mainloop. Using the Qt backend, your code would show the error QCoreApplication::exec: The event loop is already running.
See What is interactive mode? for more guidance on how to use Matplotlib interactively.

Categories