0

I have written a code to examine the alias effect for a sine-wave. The code produces a series of plots, which show the results of sampling the sine-wave at a given sampling frequency. The frequency of the sinewave is increased in increments of 50 hz using while-loop logic.

import numpy as np
from math import pi
import matplotlib.pyplot as plt

f_0 = 50
f_s = 150

t_a = np.arange(0, 0.1, 10e-06)
t_d = np.arange(1/f_s, 0.1, 1/f_s)

def a_sinewave(t_a, f_0):
return np.sin(2 * pi * f_0 * t_a)

def d_sinewave(t_d, f_0):
return np.sin(2 * pi * f_0 * t_d)

while f_0 <= 300:
y = a_sinewave(t_a, f_0)
z = d_sinewave(t_d, f_0)
plt.plot(t_a, y)
plt.plot(t_d, z, 'ro')
plt.show()
f_0 += 50  

Running this code displays a series of plots for each value of f_0, one after another. I would like to display these plots as a "slide-show", as in one plot is shown every t seconds. How can I do this?

In the blind
  • 115
  • 5
  • `slide-show` in what program? PowerPoint? You can always `save()` every plot to separated images and later use them in any program to create slideshow. Or you can use them with [ffmpeg](http://ffmpeg.org/) to generate video or animated-gif. And if you would use [FuncAnimation](https://matplotlib.org/stable/api/_as_gen/matplotlib.animation.FuncAnimation.html) (instead of `while`-loop) then you could save it in video directly from Python. – furas Sep 20 '22 at 14:00
  • please, always put code with correct indentations. – furas Sep 20 '22 at 14:03
  • see also [python - Plotting in a non-blocking way with Matplotlib - Stack Overflow](https://stackoverflow.com/questions/28269157/plotting-in-a-non-blocking-way-with-matplotlib) – furas Sep 20 '22 at 14:06

0 Answers0