### Install Pynimate with Pip Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Installs the pynimate package using the pip package manager. This is the recommended way to get the library. ```sh pip install pynimate ``` -------------------------------- ### Installing Pynimate with pip (Shell) Source: https://github.com/julkaar9/pynimate/blob/main/README.md Installs the Pynimate package from PyPI using the pip package manager. This is the standard way to install the library. ```Shell pip install pynimate ``` -------------------------------- ### Installing Pynimate with pip (sh) Source: https://github.com/julkaar9/pynimate/blob/main/docs/index.md Command to install the pynimate Python package using the pip package manager. This is the standard way to get the library. ```sh pip install pynimate ``` -------------------------------- ### Simple Data Example for Interpolation Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md A minimal data example used to illustrate the concept of data interpolation for creating smoother animations. ```python time, col1, col2 2012 1 3 2013 2 2 2014 3 1 ``` -------------------------------- ### Example of Interpolated Data Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Shows how the simple data example looks after applying quarterly linear interpolation, resulting in more data points for smoother animation frames. ```python time col1 col2 2012-01-01 1.00 3.00 2012-04-01 1.25 2.75 2012-07-01 1.50 2.50 2012-10-01 1.75 2.25 2013-01-01 2.00 2.00 2013-04-01 2.25 1.75 2013-07-01 2.50 1.50 2013-10-01 2.75 1.25 2014-01-01 3.00 1.00 ``` -------------------------------- ### Install FFmpeg with Pip Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Installs the ffmpeg-python wrapper library using pip, which is required for saving animations in MP4 format. ```sh pip install ffmpeg-python ``` -------------------------------- ### Install FFmpeg with Conda Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Installs the ffmpeg library using the conda package manager, an alternative method for obtaining the necessary dependency for MP4 saving. ```sh conda install ffmpeg ``` -------------------------------- ### Example Data Format for Pynimate Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Illustrates the required data format for pynimate animations, where the first column represents time and is set as the index, and subsequent columns contain numerical data for different categories. ```python time, col1, col2, col3 2012 1 2 1 2013 1 1 2 2014 2 1.5 3 2015 2.5 2 3.5 ``` -------------------------------- ### Create and Show Bar Chart Race Animation Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md A complete example demonstrating how to create a Bar Chart Race animation using pynimate. It involves setting up the data, initializing the Canvas and Barhplot, configuring the time display, adding the plot to the canvas, animating, and displaying the result using Matplotlib. ```python # import matplotlib if you wish to see the animation in gui import pandas as pd from matplotlib import pyplot as plt import pynimate as nim df = pd.DataFrame( { "time": ["1960-01-01", "1961-01-01", "1962-01-01"], "Afghanistan": [1, 2, 3], "Angola": [2, 3, 4], "Albania": [1, 2, 5], "USA": [5, 3, 4], "Argentina": [1, 4, 5], } ).set_index("time") cnv = nim.Canvas() # Interpolation frequency is 2 days bar = nim.Barhplot.from_df(df, "%Y-%m-%d", "2d") # use set_time to draw the datetime in the canvas # here we are using a callback that returns datetime formatted in month, year bar.set_time(callback=lambda i, datafier: datafier.data.index[i].strftime("%b, %Y")) # add the bar plot to the canvas cnv.add_plot(bar) cnv.animate() plt.show() ``` -------------------------------- ### Expected Data Format for Pynimate (Python) Source: https://github.com/julkaar9/pynimate/blob/main/docs/index.md Example of the required pandas DataFrame format for use with pynimate. It shows that the time column should be set as the DataFrame index. ```python time, col1, col2, col3 2012 1 2 1 2013 1 1 2 2014 2 1.5 3 2015 2.5 2 3.5 ``` -------------------------------- ### Save Animation as MP4 Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Saves the created animation to a file in MP4 format using the Canvas object's save method. Requires FFmpeg to be installed. ```python cnv.save("file", 24 ,"mp4") ``` -------------------------------- ### Create Full Dark Themed Animated Line Plot with pynimate (Python) Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/lineplot_darkmode.md Provides a complete example for generating a dark-themed animated line plot of Covid-19 data using pynimate. It includes data loading with pandas, applying custom matplotlib styles, defining a post-update function for y-axis formatting, configuring plot elements like title, labels, time display, annotations, legend, and ticks, and finally animating and saving the output. ```python import os import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.ticker as tick import pandas as pd import pynimate as nim from pynimate.utils import human_readable for side in ["left", "right", "top", "bottom"]: mpl.rcParams[f"axes.spines.{side}"] = False mpl.rcParams["figure.facecolor"] = "#001219" mpl.rcParams["axes.facecolor"] = "#001219" mpl.rcParams["savefig.facecolor"] = "#001219" dir_path = os.path.dirname(os.path.realpath(__file__)) def post(self, i): self.ax.yaxis.set_major_formatter( tick.FuncFormatter(lambda x, pos: human_readable(x)) ) df = pd.read_csv(dir_path + "/data/covid_IN.csv").set_index("time") cnv = nim.Canvas() dfr = nim.LineDatafier(df, "%Y-%m-%d", "12h") plot = nim.Lineplot( dfr, post_update=post, palettes=["Set3"], scatter_markers=False, legend=True, fixed_ylim=True, grid=False, ) plot.set_column_linestyles({"cured": "dashed"}) plot.set_title("Covid cases India(2021)", y=1.05, color="w", weight=600) plot.set_xlabel("xlabel", color="w") plot.set_time( callback=lambda i, datafier: datafier.data.index[i].strftime("%d %b, %Y"), color="w", size=15, ) plot.set_line_annots(lambda col, val: f"({human_readable(val)})", color="w") plot.set_legend(labelcolor="w") plot.set_text( "sum", callback=lambda i, datafier: f"Total cases :{human_readable(datafier.data.cases.iloc[:i+1].sum() )}", size=10, x=0.8, y=0.20, color="w", ) plot.set_xticks(colors="w", length=0, labelsize=10) plot.set_yticks(colors="w", labelsize=10) cnv.add_plot(plot) cnv.animate() cnv.save("lineplot_dark", 24) plt.show() ``` -------------------------------- ### Set Specific Column Linestyles in pynimate Lineplot (Python) Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/lineplot_darkmode.md Customizes the linestyles for specific columns in a pynimate Lineplot. This example sets the line style for the 'cured' column to 'dashed', overriding the default solid style. ```python #Linestyle defaults to solid plot.set_column_linestyles({"cured": "dashed"}) ``` -------------------------------- ### Create Sample Pandas DataFrame Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Provides a sample pandas DataFrame structure suitable for pynimate, including a 'time' column set as the index and multiple data columns representing categories. ```python df = pd.DataFrame( { "time": ["1960-01-01", "1961-01-01", "1962-01-01"], "Afghanistan": [1, 2, 3], "Angola": [2, 3, 4], "Albania": [1, 2, 5], "USA": [5, 3, 4], "Argentina": [1, 4, 5], } ).set_index("time") ``` -------------------------------- ### Initialize Barhplot with BarDatafier Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Initializes the Barhplot class by first creating a BarDatafier instance with the DataFrame, time format, and interpolation frequency, and then passing the datafier to Barhplot. ```python dfr = nim.BarDatafier(df, "%Y-%m-%d", "2d") bar = nim.Barhplot(dfr) ``` -------------------------------- ### Import Pynimate Library Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Imports the pynimate library into a Python script or environment, following the common convention of aliasing it as 'nim'. ```python import pynimate as nim ``` -------------------------------- ### Creating a Bar Chart Animation with Pynimate (Python) Source: https://github.com/julkaar9/pynimate/blob/main/docs/index.md Demonstrates how to create a simple animated horizontal bar chart using pynimate. It involves creating a pandas DataFrame, initializing a Canvas, adding a Barhplot from the DataFrame, setting the time format, animating, and displaying the plot. Requires pandas and matplotlib. ```python import pandas as pd from matplotlib import pyplot as plt import pynimate as nim df = pd.DataFrame( { "time": ["1960-01-01", "1961-01-01", "1962-01-01"], "Afghanistan": [1, 2, 3], "Angola": [2, 3, 4], "Albania": [1, 2, 5], "USA": [5, 3, 4], "Argentina": [1, 4, 5] } ).set_index("time") cnv = nim.Canvas() bar = nim.Barhplot.from_df(df, "%Y-%m-%d", "2d") bar.set_time(callback=lambda i, datafier: datafier.data.index[i].strftime("%b, %Y")) cnv.add_plot(bar) cnv.animate() plt.show() ``` -------------------------------- ### Creating an Animated Bar Chart with Pynimate (Python) Source: https://github.com/julkaar9/pynimate/blob/main/README.md Demonstrates how to create an animated horizontal bar chart using Pynimate. It involves creating a pandas DataFrame, initializing a Pynimate Canvas and Barhplot, setting the time callback, adding the plot to the canvas, animating, and displaying the result. Requires pandas, matplotlib, and pynimate. ```Python import pandas as pd from matplotlib import pyplot as plt import pynimate as nim df = pd.DataFrame( { "time": ["1960-01-01", "1961-01-01", "1962-01-01"], "Afghanistan": [1, 2, 3], "Angola": [2, 3, 4], "Albania": [1, 2, 5], "USA": [5, 3, 4], "Argentina": [1, 4, 5] } ).set_index("time") cnv = nim.Canvas() bar = nim.Barhplot.from_df(df, "%Y-%m-%d", "2d") bar.set_time(callback=lambda i, datafier: datafier.data.index[i].year) cnv.add_plot(bar) cnv.animate() plt.show() ``` -------------------------------- ### Initialize Barhplot from DataFrame Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Initializes the Barhplot class directly from a pandas DataFrame using the `from_df` class method, providing the time format and interpolation frequency. ```python bar = nim.Barhplot.from_df(df, "%Y-%m-%d", "2d") ``` -------------------------------- ### Load Data with Pandas and Set Index Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Demonstrates how to load data from a CSV file into a pandas DataFrame and set the 'time' column as the DataFrame index, which is necessary for pynimate. ```python import pandas as pd df = pd.read_csv('data.csv').set_index('time') ``` -------------------------------- ### Create Sample Dataframe - Pynimate/Python Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/dark_mode.md Initializes a Pandas DataFrame with sample time-series data suitable for a bar chart race animation using Pynimate. The 'time' column is set as the index. ```python df = pd.DataFrame( { "time": ["1960-01-01", "1961-01-01", "1962-01-01"], "Afghanistan": [1, 2, 3], "Angola": [2, 3, 4], "Albania": [1, 2, 5], "USA": [5, 3, 4], "Argentina": [1, 4, 5], } ).set_index("time") ``` -------------------------------- ### Generate Dark Themed Bar Chart Race - Pynimate/Python Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/dark_mode.md A complete script demonstrating the creation of a dark-themed animated bar chart race using Pynimate. It includes importing libraries, setting Matplotlib styles for a dark theme, defining the post-update function, loading data, adding variables, setting custom colors, configuring various plot elements (title, labels, annotations, ticks, borders), adding the plot to a canvas, animating, and displaying the result. ```python import os import matplotlib as mpl import numpy as np import pandas as pd from matplotlib import pyplot as plt import pynimate as nim dir_path = os.path.dirname(os.path.realpath(__file__)) mpl.rcParams["axes.facecolor"] = "#001219" # Turning off the spines for side in ["left", "right", "top", "bottom"]: mpl.rcParams[f"axes.spines.{side}"] = False def post_update(self, i): # annotates continents next to bars for ind, (bar, x, y) in enumerate( zip(self.bar_attr.top_cols, self.bar_attr.bar_length, self.bar_attr.bar_rank) ): self.ax.text( x - 0.3, y, self.dfr.col_var.loc[bar, "continent"], ha="right", color="k", size=12, zorder=ind, ) df = pd.read_csv(dir_path + "/data/sample.csv").set_index("time") col_var = pd.DataFrame( { "columns": ["Afghanistan", "Angola", "Albania", "USA", "Argentina"], "continent": ["Asia", "Africa", "Europe", "N America", "S America"], } ).set_index("columns") bar_cols = { "Afghanistan": "#2a9d8f", "Angola": "#e9c46a", "Albania": "#e76f51", "USA": "#a7c957", "Argentina": "#e5989b", } cnv = nim.Canvas(figsize=(12.8, 7.2), facecolor="#001219") dfr = nim.BarDatafier(df, "%Y-%m-%d", "3d") dfr.add_var(col_var=col_var) bar = nim.Barhplot(dfr, post_update=post_update, rounded_edges=True, grid=False) bar.set_column_colors(bar_cols) bar.set_title("Sample Title", color="w", weight=600) bar.set_xlabel("xlabel", color="w") bar.set_time( callback=lambda i, datafier: datafier.data.index[i].strftime("%b, %Y"), color="w" ) bar.set_text( "sum", callback=lambda i, datafier: f"Total :{np.round(datafier.data.iloc[i].sum(), 2)}", size=20, x=0.72, y=0.20, color="w", ) bar.set_bar_annots(color="w", size=13) bar.set_xticks(colors="w", length=0, labelsize=13) bar.set_yticks(colors="w", labelsize=13) bar.set_bar_border_props( edge_color="black", pad=0.1, mutation_aspect=1, radius=0.2, mutation_scale=0.6 ) cnv.add_plot(bar) cnv.animate() plt.show() ``` -------------------------------- ### Save Animation as GIF Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/starter.md Saves the created animation to a file in GIF format using the Canvas object's save method. Requires Pillow or another compatible writer. ```python cnv.save("file", 24, "gif") ``` -------------------------------- ### Define Post-Update Annotation Function - Pynimate/Python Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/dark_mode.md Defines a callback function (`post_update`) that is executed for every frame of the animation. This specific implementation iterates through the top bars and adds text annotations (continent names from the `col_var` DataFrame) next to them. ```python def post_update(self, i): # annotates continents next to bars for ind, (bar, x, y) in enumerate( zip(self.bar_attr.top_cols, self.bar_attr.bar_length, self.bar_attr.bar_rank) ): self.ax.text( x - 0.3, y, self.dfr.col_var.loc[bar, "continent"], ha="right", color="k", size=12, zorder=ind, ) ``` -------------------------------- ### Create Column Variables Dataframe - Pynimate/Python Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/dark_mode.md Creates a Pandas DataFrame to hold additional categorical data (like continents) associated with the columns (entities) of the main dataset. This DataFrame is indexed by the column names and is used for annotations in the animation. ```python col_var = pd.DataFrame( { "columns": ["Afghanistan", "Angola", "Albania", "USA", "Argentina"], "continent": ["Asia", "Africa", "Europe", "N America", "S America"], } ).set_index("columns") ``` -------------------------------- ### Define Custom Bar Colors - Pynimate/Python Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/dark_mode.md Specifies a dictionary mapping each entity (column name) to a specific hexadecimal color code. This allows for custom coloring of individual bars in the bar chart race animation. ```python bar_cols = { "Afghanistan": "#2a9d8f", "Angola": "#e9c46a", "Albania": "#e76f51", "USA": "#a7c957", "Argentina": "#e5989b", } ``` -------------------------------- ### Define pynimate post_update for Y-axis Formatting (Python) Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/lineplot_darkmode.md Implements a `post_update` method for a pynimate plot object. This function is called for each frame and uses `matplotlib.ticker.FuncFormatter` to apply a `human_readable` function to the y-axis tick labels. ```python def post(self, i): self.ax.yaxis.set_major_formatter( tick.FuncFormatter(lambda x, pos: human_readable(x)) ) ``` -------------------------------- ### Customize Matplotlib Dark Theme Styles (Python) Source: https://github.com/julkaar9/pynimate/blob/main/docs/guide/lineplot_darkmode.md Configures Matplotlib's default styles to create a dark theme. Sets the figure, axes, and savefig facecolors to a dark hex value (`#001219`) and removes the default axis spines. ```python #Customizing matplotlib import matplotlib as mpl for side in ["left", "right", "top", "bottom"]: mpl.rcParams[f"axes.spines.{side}"] = False mpl.rcParams["figure.facecolor"] = "#001219" mpl.rcParams["axes.facecolor"] = "#001219" mpl.rcParams["savefig.facecolor"] = "#001219" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.