提交 d08c87a2 编写于 作者: F feilong

fix bug

上级 57caaa36
......@@ -54,6 +54,7 @@ class BarChartRace:
self.col_filt = self.get_col_filt()
self.bar_colors = self.get_default_bar_colors(cmap)
self.str_index = self.df_values.index.astype('str')
self.progress = None
def get_extension(self):
if self.filename:
......@@ -415,7 +416,7 @@ class BarChartRace:
i += 1
def anim_func(self, i):
self.bar.next(1)
self.progress.next(1)
plt.xkcd(scale=1, length=100, randomness=2)
if(platform.system() == 'Linux'):
plt.rcParams.update({'font.family': "WenQuanYi Micro Hei"})
......@@ -433,8 +434,9 @@ class BarChartRace:
self.plot_bars(0)
total_count = len(self.df_values)
self.bar = IncrementalBar(self.filename, max=total_count)
interval = self.period_length / self.steps_per_period
self.progress = IncrementalBar(
self.filename, max=total_count)
anim = FuncAnimation(self.fig, self.anim_func, range(len(self.df_values)),
init_func, interval=interval)
......@@ -464,7 +466,7 @@ class BarChartRace:
raise Exception(message)
finally:
plt.rcParams = self.orig_rcParams
self.bar.finish()
self.progress.finish()
return ret_val
......
......@@ -7,6 +7,7 @@ def concat_gif_list(gifs, output):
clips.append(mp.VideoFileClip(gif))
final = mp.concatenate_videoclips(clips)
final.write_videofile(output)
print(f"@合并生成GIF:{output}")
def merge_video_audio(video, audio, output):
......@@ -34,3 +35,5 @@ def merge_video_audio(video, audio, output):
final = v.set_audio(final_audio)
final.write_videofile(output)
print(f"@合成视频和音频:{output}")
......@@ -93,10 +93,30 @@ class Top:
if end >= max_rows:
end = max_rows+1
step = end-i
self.df = df[i:end]
filename = os.path.join(self.output, f'{j}.{self.ext}')
self.__build_race(filename)
if i+step >= max_rows:
# 最后一个
last_df = df[i:end]
# 生成一个短摘要
min_half = 5
if min_half > last_df.shape[0]:
min_half = 0
self.df = last_df[min_half:]
filename_abstracts = os.path.join(
self.output, f'{j}_abstracts.{self.ext}')
self.__build_race(filename_abstracts)
# 加强最后一帧
self.df = last_df
for k in range(0, 12):
self.df = self.df.append(df[end-2:end])
self.__build_race(filename)
else:
self.df = df[i:end]
self.__build_race(filename)
gifs.append(filename)
i += step
j += 1
......@@ -225,6 +245,7 @@ class Top:
bar_size=0.7,
bar_label_size=14,
tick_label_size=14,
steps_per_period=20,
)
def __exit(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册