Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
fasterconvergence
#11
runfile('C:/Users/Desktop/python ode/homework11.py', wdir='C:/Users/Desktop/python ode')
<itertools.islice object at 0x0000024F73D16188>
Traceback (most recent call last):

  File "<ipython-input-104-56c93f909ab5>", line 1, in <module>
    runfile('C:/Users/Desktop/python ode/homework11.py', wdir='C:/Users/Desktop/python ode')

  File "C:\Users\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
    execfile(filename, namespace)

  File "C:\Users\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Desktop/python ode/homework11.py", line 134, in <module>
    plt.plot(a)

  File "C:\Users\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 3363, in plot
    ret = ax.plot(*args, **kwargs)

  File "C:\Users\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 1867, in inner
    return func(ax, *args, **kwargs)

  File "C:\Users\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1528, in plot
    for line in self._get_lines(*args, **kwargs):

  File "C:\Users\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 406, in _grab_next_args
    for seg in self._plot_args(this, kwargs):

  File "C:\Users\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 383, in _plot_args
    x, y = self._xy_from_xy(x, y)

  File "C:\Users\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 216, in _xy_from_xy
    by = self.axes.yaxis.update_units(y)

  File "C:\Users\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1463, in update_units
    converter = munits.registry.get_converter(data)

  File "C:\Users\Anaconda3\lib\site-packages\matplotlib\units.py", line 182, in get_converter
    converter = self.get_converter(next_item)

  File "C:\Users\Anaconda3\lib\site-packages\matplotlib\units.py", line 188, in get_converter
    thisx = safe_first_element(x)

  File "C:\Users\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 2359, in safe_first_element
    raise RuntimeError("matplotlib does not support generators "

RuntimeError: matplotlib does not support generators as input
Reply
#12
It says that it fails at line 134 if homework11.py but the code that you posted above doesn't have that many lines. It is impossible to debug without the actual code that throws the error.
Reply
#13
it says line 134 because the code from previous tasks is right above, so the lines add up, but the code I submitted here is the only active one in this file, because I manually dis-activated the rest by including it between """ """, so it does not make a difference that is there, since is ignored by the compiler.
Reply
#14
if you run this code in a brand new file, line 134 corresponds to line 37, the last line.
Reply
#15
I ran the code many times and never got the exception that you mention above.
Reply
#16
this is quite strange.

Once again, this is the code I run:

def applog(n,x):
    a0=(1+x)/2
    b0=sqrt(x)
   
    for i in range(n):
        a0=(a0+b0)/2
        b0=sqrt((a0)*b0)
    return (x-1)/a0




def Euler_accelerate(sequence):
   
    s0 = next(sequence) 
    s1 = next(sequence) 
    s2 = next(sequence) 
    while True:
        yield s0 - ((s1 - s0)**2)/(s2 - 2*s1 + s0)
        s0, s1, s2 = s1, s2, next(sequence)

x = np.linspace(10, 500, 100)
nn=range(1,6)
colors = mpl.cm.rainbow(np.linspace(0, 1, len(nn)))


a=(itertools.islice(Euler_accelerate(applog(n,x)), 5))
for c,n in zip(colors,nn):
  
    print(a)
    plt.plot(a)
and what I get is the outcome I posted yesterday with an empty graph in the end.
However, If I comment the last line (# plt.plot(a))
this is all I get:

<itertools.islice object at 0x0000024F73D14D68>
<itertools.islice object at 0x0000024F73D14D68>
<itertools.islice object at 0x0000024F73D14D68>
<itertools.islice object at 0x0000024F73D14D68>
<itertools.islice object at 0x0000024F73D14D68>
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020