Non periodic square function train in python
Question:
Answers:
The thing to do is to just write some custom code, instead of built-in modules like to tried. For instance:
from matplotlib import pyplot as plt
def plot_square_pulses(n, p, dur, amp, offset):
plt.figure()
for i in range(n):
x1 = i * (p + dur) + offset
x2 = x1 + dur
plt.hlines(amp, x1, x2, linewidth=2)
plt.vlines(x1, 0, amp, linewidth=2)
plt.vlines(x2, 0, amp, linewidth=2)
plt.axis('equal')
# Example usage:
plot_square_pulses(n=5, p=0.3, dur=1, amp=1, offset=0.2)
The resulting plot can probably be improved, but should put you in the right direction:
The thing to do is to just write some custom code, instead of built-in modules like to tried. For instance:
from matplotlib import pyplot as plt
def plot_square_pulses(n, p, dur, amp, offset):
plt.figure()
for i in range(n):
x1 = i * (p + dur) + offset
x2 = x1 + dur
plt.hlines(amp, x1, x2, linewidth=2)
plt.vlines(x1, 0, amp, linewidth=2)
plt.vlines(x2, 0, amp, linewidth=2)
plt.axis('equal')
# Example usage:
plot_square_pulses(n=5, p=0.3, dur=1, amp=1, offset=0.2)
The resulting plot can probably be improved, but should put you in the right direction: