{"id":15029463,"url":"https://github.com/dexplo/bar_chart_race","last_synced_at":"2025-05-14T19:07:45.983Z","repository":{"id":40604957,"uuid":"259213243","full_name":"dexplo/bar_chart_race","owner":"dexplo","description":"Create animated bar chart races in Python with matplotlib","archived":false,"fork":false,"pushed_at":"2024-06-27T10:45:01.000Z","size":69272,"stargazers_count":1406,"open_issues_count":50,"forks_count":367,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-05-11T14:48:08.685Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dexplo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://www.dunderdata.com"]}},"created_at":"2020-04-27T05:21:00.000Z","updated_at":"2025-05-05T23:37:23.000Z","dependencies_parsed_at":"2024-09-20T22:00:59.601Z","dependency_job_id":"f9cd72a3-31d6-4c61-8eac-7a9cb589d6f3","html_url":"https://github.com/dexplo/bar_chart_race","commit_stats":{"total_commits":176,"total_committers":1,"mean_commits":176.0,"dds":0.0,"last_synced_commit":"5930c3138a597d30c7d345379f5c1329ba68a035"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dexplo%2Fbar_chart_race","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dexplo%2Fbar_chart_race/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dexplo%2Fbar_chart_race/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dexplo%2Fbar_chart_race/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dexplo","download_url":"https://codeload.github.com/dexplo/bar_chart_race/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254209859,"owners_count":22032897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T20:10:44.858Z","updated_at":"2025-05-14T19:07:44.745Z","avatar_url":"https://github.com/dexplo.png","language":"Python","funding_links":["https://www.dunderdata.com"],"categories":[],"sub_categories":[],"readme":"# Bar Chart Race\n\n[![](https://img.shields.io/pypi/v/bar_chart_race)](https://pypi.org/project/bar_chart_race)\n[![PyPI - License](https://img.shields.io/pypi/l/bar_chart_race)](LICENSE)\n\nMake animated bar and line chart races in Python with matplotlib or plotly.\n\n![img](https://github.com/dexplo/bar_chart_race/raw/gh-pages/images/covid19_horiz.gif)\n\n## Official Documentation\n\nVisit the [bar_chart_race official documentation](https://www.dexplo.org/bar_chart_race) for detailed usage instructions.\n\n## Installation\n\nInstall with either:\n\n* `pip install bar_chart_race`\n* `conda install -c conda-forge bar_chart_race`\n\n## Quickstart\n\nMust begin with a pandas DataFrame containing 'wide' data where:\n\n* Every row represents a single period of time\n* Each column holds the value for a particular category\n* The index contains the time component (optional)\n  \nThe data below is an example of properly formatted data. It shows total deaths from COVID-19 for several countries by date.\n\n![img](https://github.com/dexplo/bar_chart_race/raw/gh-pages/images/wide_data.png)\n\n### Create bar and line chart races\n\nThere are three core functions available to construct the animations.\n\n* `bar_chart_race`\n* `bar_chart_race_plotly`\n* `line_chart_race`\n\nThe above animation was created with the help of matplotlib using the following call to `bar_chart_race`.\n\n```python\nimport bar_chart_race as bcr\ndf = bcr.load_dataset('covid19_tutorial')\nbcr.bar_chart_race(\n        df=df, \n        filename='../docs/images/covid19_horiz.gif', \n        orientation='h', \n        sort='desc', \n        n_bars=8, \n        fixed_order=False, \n        fixed_max=True, \n        steps_per_period=20, \n        period_length=500, \n        end_period_pause=0,\n        interpolate_period=False, \n        period_label={'x': .98, 'y': .3, 'ha': 'right', 'va': 'center'}, \n        period_template='%B %d, %Y', \n        period_summary_func=lambda v, r: {'x': .98, 'y': .2, \n                                          's': f'Total deaths: {v.sum():,.0f}', \n                                          'ha': 'right', 'size': 11}, \n        perpendicular_bar_func='median', \n        colors='dark12', \n        title='COVID-19 Deaths by Country', \n        bar_size=.95, \n        bar_textposition='inside',\n        bar_texttemplate='{x:,.0f}', \n        bar_label_font=7, \n        tick_label_font=7, \n        tick_template='{x:,.0f}',\n        shared_fontdict=None, \n        scale='linear', \n        fig=None, \n        writer=None, \n        bar_kwargs={'alpha': .7},\n        fig_kwargs={'figsize': (6, 3.5), 'dpi': 144},\n        filter_column_colors=False) \n```\n\n### Save animation to disk or embed into a Jupyter Notebook\n\nIf you are working within a Jupyter Notebook, leave the `filename` as `None` and it will be automatically embedded into a Jupyter Notebook.\n\n```python\nbcr.bar_chart_race(df=df, filename=None)\n```\n\n![img](https://github.com/dexplo/bar_chart_race/raw/gh-pages/images/bcr_notebook.png)\n\n### Customization\n\nThere are many options to customize the bar chart race to get the animation you desire. Below, we have an animation where the maximum x-value and order of the bars are set for the entire duration. A custom summary label and perpendicular bar of the median is also added.\n\n```python\ndef period_summary(values, ranks):\n    top2 = values.nlargest(2)\n    leader = top2.index[0]\n    lead = top2.iloc[0] - top2.iloc[1]\n    s = f'{leader} by {lead:.0f}'\n    return {'s': s, 'x': .99, 'y': .03, 'ha': 'right', 'size': 8}\n\ndf_baseball = bcr.load_dataset('baseball').pivot(index='year',\n                                                 columns='name',\n                                                 values='hr')\ndf_baseball.bcr.bar_chart_race(\n                   period_length=1000,\n                   fixed_max=True, \n                   fixed_order=True, \n                   n_bars=10,\n                   period_summary_func=period_summary,\n                   period_label={'x': .99, 'y': .1},\n                   period_template='Season {x:,.0f}',\n                   title='Top 10 Home Run Hitters by Season Played')\n```\n\n![img](https://github.com/dexplo/bar_chart_race/raw/gh-pages/images/baseball_horiz.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdexplo%2Fbar_chart_race","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdexplo%2Fbar_chart_race","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdexplo%2Fbar_chart_race/lists"}