Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative sums does not display #64

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
66bbb46
Added abiliy to use images as labels for the bars
andresberejnoi Jul 27, 2020
e1d9dc3
Importing TextArea. Cleaned up code and extra print statements. Added…
andresberejnoi Jul 28, 2020
c704fc5
fixed typo
andresberejnoi Jul 28, 2020
1b4eb5c
Adding option to remove tick labels in favor of only images
andresberejnoi Jul 28, 2020
39adcb9
adding options for image label
andresberejnoi Jul 29, 2020
7698896
added docstring for new parameter
andresberejnoi Jul 29, 2020
e2aa9d6
explained PIL import
andresberejnoi Jul 31, 2020
93a5dce
Added gif to show what the feature should do
andresberejnoi Jul 31, 2020
f99438d
merged changes in master branch
andresberejnoi Aug 4, 2020
9705ee4
past uncommitted changes
Rhitabrat Jan 21, 2021
344939d
brand colors added
Rhitabrat Jan 21, 2021
d0b32a3
extra pixel set to 2
Rhitabrat Jan 21, 2021
bbb0b51
icon size changed
Rhitabrat Jan 21, 2021
d316f1d
right end of the bar prevented from being cut from canvas
Rhitabrat Jan 21, 2021
6f6483d
backgrounds changed
Rhitabrat Jan 21, 2021
ce3e955
paddings created on all sides
Rhitabrat Jan 21, 2021
7c48ef8
paddings adjusted
Rhitabrat Jan 21, 2021
7019a1a
x-axis adjusted
Rhitabrat Jan 21, 2021
088146b
bar label distance adjusted
Rhitabrat Jan 21, 2021
644ff73
decimal values for labels
Rhitabrat Jan 21, 2021
fa87331
new gif added
Rhitabrat Jan 21, 2021
a6e37bd
gif file added
Rhitabrat Jan 21, 2021
5f06d18
path changed
Rhitabrat Jan 21, 2021
037ed49
instrcutions added
Rhitabrat Jan 24, 2021
015d86a
python formatting added
Rhitabrat Jan 24, 2021
18973d4
adjusted the position of images
Rhitabrat Feb 16, 2021
939d690
Merge pull request #1 from Rhitabrat/customized_programiz
parewa-ranjit Feb 16, 2021
bced38e
Deleted unnecessary files
basnetsoyuj Feb 16, 2021
afb4c8c
Reset Formatting Changes
basnetsoyuj Feb 16, 2021
3761963
Merge pull request #2 from basnetsoyuj/master
parewa-ranjit Feb 17, 2021
319b389
comments added
Rhitabrat Feb 17, 2021
e4630e0
data files removed
Rhitabrat Feb 17, 2021
4b94f24
Merge pull request #3 from basnetsoyuj/customization
parewa-ranjit Feb 18, 2021
83b72ee
Final Change
basnetsoyuj Mar 19, 2021
304283e
Merge pull request #4 from basnetsoyuj/master
parewa-ranjit Mar 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

45 changes: 0 additions & 45 deletions .github/workflows/python-package.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ site/
*.mp4
docs/
data/
.idea/
venv/
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

197 changes: 103 additions & 94 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,117 +1,126 @@
# Bar Chart Race

[![](https://img.shields.io/pypi/v/bar_chart_race)](https://pypi.org/project/bar_chart_race)
[![PyPI - License](https://img.shields.io/pypi/l/bar_chart_race)](LICENSE)

Make animated bar and line chart races in Python with matplotlib or plotly.

![img](https://github.com/dexplo/bar_chart_race/raw/gh-pages/images/covid19_horiz.gif)

## Official Documentation

Visit the [bar_chart_race official documentation](https://www.dexplo.org/bar_chart_race) for detailed usage instructions.

## Installation

Install with either:
Original Repo (without icons) : [https://github.com/dexplo/bar_chart_race](https://github.com/dexplo/bar_chart_race)

* `pip install bar_chart_race`
* `conda install -c conda-forge bar_chart_race`
Andres Berejnoi's Repo (with
icons) : [https://github.com/andresberejnoi/bar_chart_race](https://github.com/andresberejnoi/bar_chart_race)

## Quickstart
---

Must begin with a pandas DataFrame containing 'wide' data where:
## Top Computer Science Schools 2000 - 2020

* Every row represents a single period of time
* Each column holds the value for a particular category
* The index contains the time component (optional)

The data below is an example of properly formatted data. It shows total deaths from COVID-19 for several countries by date.
![img](demo.gif)

![img](https://github.com/dexplo/bar_chart_race/raw/gh-pages/images/wide_data.png)
---

### Create bar and line chart races
## Installation

There are three core functions available to construct the animations.
First Create a New Virtual Environment & Activate It:

* `bar_chart_race`
* `bar_chart_race_plotly`
* `line_chart_race`
```
pip install virtualenv
virtualenv venv
.\venv\Scripts\activate
```

The above animation was created with the help of matplotlib using the following call to `bar_chart_race`.
Install `bar_chart_race` using `pip`:

```python
import bar_chart_race as bcr
df = bcr.load_dataset('covid19_tutorial')
bcr.bar_chart_race(
df=df,
filename='../docs/images/covid19_horiz.gif',
orientation='h',
sort='desc',
n_bars=8,
fixed_order=False,
fixed_max=True,
steps_per_period=20,
period_length=500,
end_period_pause=0,
interpolate_period=False,
period_label={'x': .98, 'y': .3, 'ha': 'right', 'va': 'center'},
period_template='%B %d, %Y',
period_summary_func=lambda v, r: {'x': .98, 'y': .2,
's': f'Total deaths: {v.sum():,.0f}',
'ha': 'right', 'size': 11},
perpendicular_bar_func='median',
colors='dark12',
title='COVID-19 Deaths by Country',
bar_size=.95,
bar_textposition='inside',
bar_texttemplate='{x:,.0f}',
bar_label_font=7,
tick_label_font=7,
tick_template='{x:,.0f}',
shared_fontdict=None,
scale='linear',
fig=None,
writer=None,
bar_kwargs={'alpha': .7},
fig_kwargs={'figsize': (6, 3.5), 'dpi': 144},
filter_column_colors=False)
```
pip install git+https://github.com/programiz/bar_chart_race.git@master
```

### Save animation to disk or embed into a Jupyter Notebook
You also need to install
FFmpeg: [https://github.com/BtbN/FFmpeg-Builds/releases/](https://github.com/BtbN/FFmpeg-Builds/releases/)

If you are working within a Jupyter Notebook, leave the `filename` as `None` and it will be automatically embedded into a Jupyter Notebook.
---

```python
bcr.bar_chart_race(df=df, filename=None)
```
## Usage

![img](https://github.com/dexplo/bar_chart_race/raw/gh-pages/images/bcr_notebook.png)
Create a file and use the `bar_chart_race` library as shown below:

### Customization
```python
import bar_chart_race as bcr
import pandas as pd

There 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.
df = pd.read_csv("data.csv", index_col="Date")

```python
def period_summary(values, ranks):
top2 = values.nlargest(2)
leader = top2.index[0]
lead = top2.iloc[0] - top2.iloc[1]
s = f'{leader} by {lead:.0f}'
return {'s': s, 'x': .99, 'y': .03, 'ha': 'right', 'size': 8}

df_baseball = bcr.load_dataset('baseball').pivot(index='year',
columns='name',
values='hr')
df_baseball.bcr.bar_chart_race(
period_length=1000,
fixed_max=True,
fixed_order=True,
n_bars=10,
period_summary_func=period_summary,
period_label={'x': .99, 'y': .1},
period_template='Season {x:,.0f}',
title='Top 10 Home Run Hitters by Season Played')
```
# replace empty values with 0
df.fillna(0.0, inplace=True)

![img](https://github.com/dexplo/bar_chart_race/raw/gh-pages/images/baseball_horiz.gif)
# using the bar_chart_race package
bcr.bar_chart_race(
# must be a DataFrame where each row represents a single period of time.
df=df,

# name of the video file
filename="video.mp4",

# specify location of image folder
img_label_folder="bar_image_labels",

# change the Figure properties
fig_kwargs={
'figsize': (26, 15),
'dpi': 120,
'facecolor': '#F8FAFF'
},

# orientation of the bar: h or v
orientation="h",

# sort the bar for each period
sort="desc",

# number of bars to display in each frame
n_bars=10,

# to fix the maximum value of the axis
# fixed_max=True,

# smoothness of the animation
steps_per_period=45,

# time period in ms for each row
period_length=1500,

# custom set of colors
colors=[
'#6ECBCE', '#FF2243', '#FFC33D', '#CE9673', '#FFA0FF', '#6501E5', '#F79522', '#699AF8', '#34718E', '#00DBCD',
'#00A3FF', '#F8A737', '#56BD5B', '#D40CE5', '#6936F9', '#FF317B', '#0000F3', '#FFA0A0', '#31FF83', '#0556F3'
],

# title and its styles
title={'label': 'Programming Language Popularity 1990 - 2020',
'size': 52,
'weight': 'bold',
'pad': 40
},

# adjust the position and style of the period label
period_label={'x': .95, 'y': .15,
'ha': 'right',
'va': 'center',
'size': 72,
'weight': 'semibold'
},

# style the bar label text
bar_label_font={'size': 27},

# style the labels in x and y axis
tick_label_font={'size': 27},

# adjust the style of bar
# alpha is opacity of bar
# ls - width of edge
bar_kwargs={'alpha': .99, 'lw': 0},

# adjust the bar label format
bar_texttemplate='{x:.2f}',

# adjust the period label format
period_template='{x:.0f}',
)
```
Loading