Python matplotlib Pages - 1 2
Download Python Project : Py-Bar-Chart.zip - (8.91 KB zip file) Download
Source Code of Python Project - Py-Bar-Chart :
Download this Source Code at python file: Py_Bar_Chart.py - (572 Byte Python file) download
Output of Py-Bar-Chart project, Creating a Bar Chart using plt.bar()
Download Python Project : Py-graphe-animate.zip - (11.0 KB zip file) Download
Source Code of Python Project - Py_graphe_animate :
Download this Source Code at python file: Py_graphe_animate.py - (1.44 KB Python file) download
from datetime import datetime
from random import randint
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# figure ...
fig = plt.figure()
ax = fig.add_subplot()
#create lists to hold the data
time_series = []
value_a_series = []
value_b_series = []
#create a function to generate some dummy data
def generate_dummy_data():
time = datetime.now()
value_a = randint(-100, 100)
value_b = randint(-10, 10)
time_series.append(time)
value_a_series.append(value_a)
value_b_series.append(value_b)
#create a function to draw an animated graph.
def animate(i):
generate_dummy_data()
#the axis of the graph can constantly change
ax.clear()
plt.title('An animated graph')
plt.xlabel('Time')
plt.ylabel('values')
#plot the contents of the list or lists of data
ax.plot(time_series, value_a_series, label='value_a_series')
ax.plot(time_series, value_b_series, label='value_b_series')
#To finish off this function
plt.legend()
fig.autofmt_xdate()
#create an animation object. This will call the animate function every 1000 millisecond
ani = animation.FuncAnimation(fig, animate, frames= list ( range (1 ,50 )), interval=1000) #interval=500)
#anim = FuncAnimation(fig, animate, frames= list ( range (1 ,50 )), interval=500 , blit=False, repeat=False ) #repeat=True )
#display your plot
plt.show()
Output of Py-graphe-animate Python program, Animate a graph with Python