how to plot a time function in python

Solutions on MaxInterview for how to plot a time function in python by the best coders in the world

showing results for - "how to plot a time function in python"
Arianna
19 Jul 2016
1import matplotlib.pyplot as plt
2import numpy as np
3
4# 100 linearly spaced numbers
5x = np.linspace(-5,5,100)
6
7# the function, which is y = x^2 here
8y = x**2
9
10# setting the axes at the centre
11fig = plt.figure()
12ax = fig.add_subplot(1, 1, 1)
13ax.spines['left'].set_position('center')
14ax.spines['bottom'].set_position('zero')
15ax.spines['right'].set_color('none')
16ax.spines['top'].set_color('none')
17ax.xaxis.set_ticks_position('bottom')
18ax.yaxis.set_ticks_position('left')
19
20# plot the function
21plt.plot(x,y, 'r')
22
23# show the plot
24plt.show()