I have two bar graphs oli
and prachanda
. I want to increase height of these to graph in real-time.
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
# plt.rcParams['animation.ffmpeg_path'] = 'C:\\ffmpeg\\bin\\ffmpeg'
x1 = [0, 0, 0, 0, 0, 0]
labels = ['2018/04', '2018/05', '2018/06', '2018/07', '2018/08', '2018/09']
n_groups = 6
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.20
opacity = 0.8
fig.canvas.set_window_title('Nagarik News')
oli = plt.bar(index, x1, bar_width,
alpha=opacity,
label='Oli')
prachanda = plt.bar(index + bar_width, x1, bar_width,
alpha=opacity,
label='Prachanda')
deuwa = plt.bar(index + bar_width + bar_width, x1, bar_width,
alpha=opacity,
label='Deuwa')
def init_oli():
ax.set_ylim(0, 50)
return oli
def update_oli(frame):
new_height = oli[0].get_height() + frame
oli[0].set_height(new_height)
return oli
def init_prachanda():
return prachanda
def update_prachanda(frame):
new_height = prachanda[0].get_height() + frame
prachanda[0].set_height(new_height)
return prachanda
frames = (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
ani = FuncAnimation(fig, update_oli, frames=frames, init_func=init_oli, blit=True, interval=500, repeat=False)
ani2 = FuncAnimation(fig, update_prachanda, frames=frames, init_func=init_prachanda, blit=True, interval=500,
repeat=False)
plt.xlabel('Month')
plt.ylabel('Count')
plt.title('Count by Politician')
plt.xticks(index + bar_width, labels)
plt.legend()
plt.tight_layout()
plt.show()
# writer = FFMpegWriter()
# ani.save('basic_animation.mp4', writer=writer)
The problem is only the height of the graph prachanda
is increasing.