-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Bug summary
I have found a bug with the slider object (matplotlib 3.7.1)
The script is joined.
It works very well with win 10 and ubuntu 22.04 and python3.11.2
It doesn't work with with win 10 and ubuntu 22.04 and python3.11.3
When I click on the slider, I have this message
ax is None
I suppose a bug from python 3.11.3 or matplotlib !!
Thanks a lot
Philippe DALET
Lyp Champollion
FIGEAC - FRANCE
Code for reproduction
#!/usr/local/bin/python3.11
# -*- coding: utf-8 -*-
# Philippe DALET
# Lyp Champollion-46100 FIGEAC
# 22 october 2022
# 20 april 2023
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
import matplotlib.animation as animation
from math import pi
import numpy as np
xmax=10
Nmax=1000
lamb=3.0
#constants
xA=1
xB=2
#t=0
T=2
v=lamb/T
dt = T/50
Amplitude=1
#datas
x = np.linspace(0, xmax, Nmax)
t = np.linspace(0, 2*T, Nmax)
#camera
y = np.cos( 2*pi*( t/T - x/lamb) )
#oscillogram
yA_t = Amplitude*np.cos( 2*pi*( t/T - xA/lamb) )
yB_t = Amplitude*np.cos( 2*pi*( t/T - xB/lamb) )
#plot
fig, a = plt.subplots(2)
plt.subplots_adjust(left=0.10, bottom=0.25)
fig.suptitle(r'$Onde\ progressive\ sinusoidale$',color='b',fontsize=20)
#camera
a[0].set_xlim(0,xmax)
a[0].set_xticks(np.arange(0, 10, step=0.5))
a[0].set_ylim(-1.5*Amplitude,+1.5*Amplitude)
a[0].grid(True)
a[0].set_xlabel('x (m)', fontsize=10)
a[0].set_ylabel(r'$y(x,t)$', rotation=0, fontsize=10)
a[0].text(8.5, 1.2, r'$\lambda=%dm\ et\ T=%ds$' %(lamb,T) , fontsize=12)
#oscillogramm yA yB
a[1].set_xlim(0,2*T)
a[1].set_ylim(-1.5*Amplitude,+1.5*Amplitude)
a[1].grid(True)
a[1].set_xlabel('t (s)', fontsize=10)
a[1].set_ylabel(r'$y(t)$', rotation=0, fontsize=10)
a[1].plot(t,yA_t,'b', label=r'$y_{xA}(t)$')
a[1].plot(t,yB_t,'g', label=r'$y_{xB}(t)$')
a[1].legend(loc=1)
line, = a[0].plot(x,y,'r')
def init():
line.set_ydata(np.ma.array(x, mask=True))
scatA=a[0].scatter(xA, 0 , c = 'b')
scatB=a[0].scatter(xB, 0 , c = 'g')
lineA=a[0].vlines(xA, -1.5*Amplitude,+1.5*Amplitude, colors = 'b')
lineB=a[0].vlines(xB, -1.5*Amplitude,+1.5*Amplitude, colors = 'g')
return line, scatA, scatB, lineA, lineB
def animate(i):
global x,y,t,line
t=i*dt
y = Amplitude*np.cos( 2*pi*( t/T - x/lamb) )
yA=y[int(xA*100)]
yB=y[int(xB*100)]
line.set_ydata(y)
scatA=a[0].scatter(xA, yA , c = 'b')
scatB=a[0].scatter(xB, yB , c = 'g')
lineA=a[0].vlines(xA, -1.5*Amplitude,+1.5*Amplitude, colors = 'b')
lineB=a[0].vlines(xB, -1.5*Amplitude,+1.5*Amplitude, colors = 'g')
return line, scatA, scatB, lineA, lineB
def plot():
#oscillogramm
a[1].clear()
a[1].grid(True)
a[1].set_xlim(0,2*T)
a[1].set_ylim(-1.5*Amplitude,+1.5*Amplitude)
a[1].set_xlabel('t (s)', fontsize=10)
a[1].set_ylabel(r'$y(t)$', rotation=0, fontsize=10)
t = np.linspace(0, 2*T, Nmax)
yA_t = Amplitude*np.cos( 2*pi*( t/T - xA/lamb) )
yB_t = Amplitude*np.cos( 2*pi*( t/T - xB/lamb) )
a[1].plot(t,yA_t,'b', label=r'$y_{xA}(t)$')
a[1].plot(t,yB_t,'g', label=r'$y_{xB}(t)$')
a[1].legend(loc=1)
#camera
a[0].clear()
a[0].grid(True)
a[0].set_xlim(0,xmax)
a[0].set_xlabel('x (m)', fontsize=10)
a[0].set_ylabel(r'$y(x,t)$', rotation=0, fontsize=10)
a[0].set_xticks(np.arange(0, 10, step=0.5))
a[0].set_ylim(-1.5*Amplitude,+1.5*Amplitude)
fig.canvas.draw_idle()
def updateA(val):
global xA
xA=val
plot()
def updateB(val):
global xB
xB=val
plot()
# horizontal slider to control xA
axA = plt.axes([0.10, 0.15, 0.80, 0.03], facecolor= 'lightgoldenrodyellow')
xA_slider = Slider( ax=axA,label='xA', valmin=0, valmax=xmax, valinit=xA, color='blue')
xA_slider.on_changed(updateA)
# horizontal slider to control xB
axB = plt.axes([0.10, 0.10, 0.80, 0.03], facecolor= 'lightgoldenrodyellow')
xB_slider = Slider( ax=axB,label='xB', valmin=0, valmax=xmax, valinit=xB, color='green')
xB_slider.on_changed(updateB)
ani = animation.FuncAnimation(fig, animate, init_func=init, frames=100 ,interval=25, blit=True)
figManager = plt.get_current_fig_manager()
#figManager.window.showMaximized() # QtAgg only
plt.show()
Actual outcome
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/matplotlib/backend_bases.py", line 1226, in _on_timer
ret = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/matplotlib/animation.py", line 1426, in _step
still_going = super()._step(*args)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/matplotlib/animation.py", line 1119, in _step
self._draw_next_frame(framedata, self._blit)
File "/usr/local/lib/python3.11/site-packages/matplotlib/animation.py", line 1139, in _draw_next_frame
self._post_draw(framedata, blit)
File "/usr/local/lib/python3.11/site-packages/matplotlib/animation.py", line 1162, in _post_draw
self._blit_draw(self._drawn_artists)
File "/usr/local/lib/python3.11/site-packages/matplotlib/animation.py", line 1177, in _blit_draw
cur_view = ax._get_view()
^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '_get_view'
Aborted (core dumped)
Expected outcome
crash
Additional information
No response
Operating system
windows 10 , Ubuntu 22.04
Matplotlib Version
3.7.1
Matplotlib Backend
QtAgg
Python version
3.11.3
Jupyter version
No response
Installation
pip