From f841b0b5a0db359599fc09eabfae1f9c95ccd5cc Mon Sep 17 00:00:00 2001 From: Ignatius Liu Date: Mon, 14 Sep 2020 20:16:53 -0500 Subject: [PATCH 1/3] Update installation.md --- docs/installation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index 7557c9e..817de32 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -9,7 +9,7 @@ Install from pypi or conda-forge In order to save animations as mp4/m4v/mov/etc... files, you must [install ffmpeg][0], which allows for conversion to many different formats of video and audio. For macOS users, installation may be [easier using Homebrew][2]. -After installation, ensure that `ffmpeg` has been added to your path by going to your command line and entering `ffmepg -version`. +After installation, ensure that `ffmpeg` has been added to your path by going to your command line and entering `ffmpeg -version`. ## Install ImageMagick for animated gifs @@ -21,4 +21,4 @@ Bar Chart Race requires that you have both matplotlib and pandas installed. [0]: https://www.ffmpeg.org/download.html [1]: https://imagemagick.org/ -[2]: https://trac.ffmpeg.org/wiki/CompilationGuide/macOS#ffmpegthroughHomebrew \ No newline at end of file +[2]: https://trac.ffmpeg.org/wiki/CompilationGuide/macOS#ffmpegthroughHomebrew From 00a66b763724ae98342996786a45db9c5c107aec Mon Sep 17 00:00:00 2001 From: Ignatius Liu Date: Wed, 16 Sep 2020 12:40:57 -0500 Subject: [PATCH 2/3] Update installation.md More detailed adding ffmpeg to path instructions --- docs/installation.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/installation.md b/docs/installation.md index 817de32..2569459 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -9,6 +9,7 @@ Install from pypi or conda-forge In order to save animations as mp4/m4v/mov/etc... files, you must [install ffmpeg][0], which allows for conversion to many different formats of video and audio. For macOS users, installation may be [easier using Homebrew][2]. +For Windows, go to *Edit the system environment variables* (search from Windows menu), then navigate to *Advanced* > *Environment Variables*. In the Environment Variables window, select Path, click new and enter the `ffmpeg\bin` location you have saved in your system. After installation, ensure that `ffmpeg` has been added to your path by going to your command line and entering `ffmpeg -version`. ## Install ImageMagick for animated gifs From 22068d32b7deccea93305cfc874cba11bbd26e0a Mon Sep 17 00:00:00 2001 From: suitangi Date: Wed, 16 Sep 2020 15:37:39 -0500 Subject: [PATCH 3/3] Saving video to file now shows a progress bar while rendering --- bar_chart_race/_bar_chart_race.py | 10 ++++++---- bar_chart_race/_func_animation.py | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/bar_chart_race/_bar_chart_race.py b/bar_chart_race/_bar_chart_race.py index 8b31d34..cf86962 100644 --- a/bar_chart_race/_bar_chart_race.py +++ b/bar_chart_race/_bar_chart_race.py @@ -5,6 +5,7 @@ import matplotlib.pyplot as plt from matplotlib import ticker from ._func_animation import FuncAnimation +from ._func_animation import printProgressBar from matplotlib.colors import Colormap from ._common_chart import CommonChart @@ -461,7 +462,7 @@ def anim_func(self, i): for text in ax.texts[start:]: text.remove() self.plot_bars(ax, i) - + def make_animation(self): def init_func(): ax = self.fig.axes[0] @@ -478,10 +479,8 @@ def frame_generator(n): for _ in range(pause): frames.append(None) return frames - frames = frame_generator(len(self.df_values)) anim = FuncAnimation(self.fig, self.anim_func, frames, init_func, interval=interval) - try: fc = self.fig.get_facecolor() if fc == (1, 1, 1, 0): @@ -498,8 +497,11 @@ def frame_generator(n): fc = self.fig.get_facecolor() if fc == (1, 1, 1, 0): fc = 'white' + print("Rendering video to " + self.filename) ret_val = anim.save(self.filename, fps=self.fps, writer=self.writer, - savefig_kwargs=savefig_kwargs) + savefig_kwargs=savefig_kwargs, progress_callback=printProgressBar) + printProgressBar(100, 100) + print("Rendering Complete") except Exception as e: message = str(e) raise Exception(message) diff --git a/bar_chart_race/_func_animation.py b/bar_chart_race/_func_animation.py index 16ba842..055d2b8 100644 --- a/bar_chart_race/_func_animation.py +++ b/bar_chart_race/_func_animation.py @@ -6,6 +6,15 @@ from matplotlib import rcParams from matplotlib import animation +def printProgressBar(current_frame, total_frames): + percent = ("{0:.2f}").format(100 * (current_frame / float(total_frames))) + filledLength = int(100 * current_frame // total_frames) + bar = '█' * filledLength + '-' * (100 - filledLength) + print(f'\r|{bar}| {percent}%', end = "\r") + # Print New Line on Complete + if current_frame == total_frames: + print() + class FuncAnimation(animation.FuncAnimation): def to_html5_video(self, embed_limit=None, savefig_kwargs=None):