df=df.sort_values(x).reset_index(drop=True)plt.plot(df[x],df[y],'o')plt.xlabel(x),plt.ylabel(y)#add linear regression line to scatterplotm,b=np.polyfit(df[x],df[y],1)plt.plot(df[x],m*df[x]+b)plt.show()
importnumpyasnpimportmatplotlib.pyplotasplt%matplotlibinlineimportmatplotlib_inlinematplotlib_inline.backend_inline.set_matplotlib_formats('svg')frommatplotlib.animationimportFuncAnimation,writers,PillowWriter,FFMpegWriterimportseabornassnssns.set_theme()## affects all matplotlib and seaborn plotsplt.style.use('ggplot')
## plotactual_no_of_frames=len(y_values)fig=plt.figure(figsize=(aspect_w,aspect_h),## inchesdpi=res_w/16## )plt.tight_layout()ax=plt.gca()## Get current axesax.set_title("Title")ax.set_xlim(xmin=0,xmax=(len(y_values)-1)*1.05)ax.set_ylim(ymin=0,ymax=max(y_values)*1.05)ax.set_xticks(x_values,[""]+list(x_ticks))ax.grid(False,axis="x")line,=ax.plot(0,0,linewidth=3)defanimation_frame(i):## avoid changing axes, titles, etc in updates: low fps issue## ax.set_title(y_values[i])ifinotin[0,1]andi<=actual_no_of_frames:ax.text(x=i-1,y=y_values[i-1],s=y_values[i-1],backgroundcolor="white",size=10,blit=True)line.set_xdata(x_values[:i])line.set_ydata(y_values[:i])returnline,interval=(duration*1000)/actual_no_of_frames#msfps=1000/intervalno_of_blank_frames=int(fps*pause_duration)total_no_of_frames=actual_no_of_frames+no_of_blank_framesfor_inrange(no_of_blank_frames):x_values.append(x_values[-1])y_values.append(y_values[-1])## print(x_values)animation=FuncAnimation(fig,func=animation_frame,frames=total_no_of_frames,interval=interval,blit=True## comment if it causes issue)
## setting up writer objectWriter=writers['ffmpeg']## PillowWriterwriter=Writer(fps=fps,bitrate=5000,metadata=dict(artist='Ahmed Thahir'))