How to plot multiple periods using pyplot?



I’m learning about signals now, but I’m having a tough time trying to plot more than one period using pyplot. I don’t know if the problem is with the mathematical part or with the code itself. I think this is a silly question, but any help would be great!

import numpy as np
import matplotlib.pyplot as plt

def function(t):
    return t**2

# Fundamental Period and Frequency:
T = 2*np.pi
w = 2*np.pi/T

# Defining the limits and the x values(in our case, time):
inferior_limit, superior_limit = -np.pi, np.pi
time_values = np.linspace(inferior_limit, superior_limit, 1000)

# Desired function plot:'bmh')
plt.plot(time_values, function(time_values), color='k')

This is what is begin plot:
enter image description here

And this is what I would like to plot:
enter image description here

Asked By: Filipe Reis



The main problem here is that is not a periodic function. The graph of the function you want is (((t + π) % (2π)) - π)² (graph).

You can implement that in the function function as:

def function(t):
    return (((t + np.pi) % (2*np.pi)) - np.pi)**2

Just changing that should give the output:

Answered By: xenon134
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.