Skip to content
This repository has been archived by the owner on Jan 22, 2020. It is now read-only.

Support usage of MyBinder.org - fixes #2, #3 #4

Merged
merged 3 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/datastory-org/weekly-chart/master?urlpath=%2Flab%2Ftree%2Fnotebooks)

# Datastory Weekly Chart
This repository contains data and analysis for the [Datastory Weekly Charts](https://datastory.org/sv/veckans-graf) which are posted on Datastory.org and on social media.

## Run the code in the cloud
The Jupyter notebooks within this repository can be run using mybinder.org, just
press the 'launch: binder' button above.

## Installation
To work with the notebooks on your own computer, we recommend to [download and
install Python as part of the anaconda
distribution](https://www.anaconda.com/distribution/). That way, you get `git`
to fetch the source code from this repository and Jupyter installed for you.

To install the Python dependencies required for this project, do the following
from a terminal or command prompt.

```sh
# get the content of this git repository
git clone https://github.com/datastory-org/weekly-chart

# enter the weekly-chart directory
cd weekly-chart

# install pipenv (https://pipenv.readthedocs.io)
pip install pipenv

# install the Python dependencies from the Pipfile
pipenv install

# enter the environment
pipenv shell

To run the notebooks, you need to install the packages listed in the `Pipfile`. The easiest way is to use [Pipenv](https://pipenv.readthedocs.io/en/latest/): `pipenv install`. This will install all dependencies as well as the local `src` package that contain some utility functions that are used in various notebooks.
# start jupyter lab to work with the notebooks
jupyter lab
```

An additional dependency (ImageMagick) is needed to generate GIFs. Please refer to the ImageMagick website for installation documentation.
> **NOTE:** You also need [ImageMagick](https://imagemagick.org) to generate
> GIFs, see their instructions on how to install it.

## Data
Data is collected from a variety of sources. Each notebook contains a source reference and a date for when the data was originally obtained.
Expand All @@ -19,7 +51,7 @@ Data is collected from a variety of sources. Each notebook contains a source ref
- **The Datastory Brand:** The Logo of Datastory and any other product names, trademarks or service marks are proprietary and are protected by applicable trademark and copyright laws. Nothing contained in this code base should be construed as granting any license or right to use any of the Datastory Marks without the express written permission of the owner of such Marks.

## Styling
To create your own style, make a copy of the `assets/datastory.mplstyle` stylesheet to the location of your local matplotlib configuration directory (which can be found with `matplotlib.get_configdir()`). Assuming the config dir is located at `~/.matplotlib/`, move the stylesheet to `~/.matplotlib/stylelib/your-name.mplstyle`. Now you can use `plt.style.use("your-style")` to create custom styled charts.
To adjust the style of the plots, modify `assets/datastory.mplstyle`.

Unfortunately, some styling options are not customizable via stylesheets and have to be configured in code, which is what the `ds_plot` (in src/plot) function is for. Whenever possible, initialize your plots with the command `fig, ax = ds_plot()` and all basic styling should be set up appropriately.

2 changes: 2 additions & 0 deletions apt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imagemagick

3 changes: 1 addition & 2 deletions notebooks/2019-01-23-educational-levels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"# Custom chart style\n",
"if 'datastory' in plt.style.available:\n",
" plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2019-01-30-parents-education.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"# Custom chart style\n",
"if 'datastory' in plt.style.available:\n",
" plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2019-02-06-income-inequality.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"# Custom chart style\n",
"if 'datastory' in plt.style.available:\n",
" plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2019-02-21-child-birth.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"plt.ioff()\n",
"\n",
"# Custom chart style\n",
"if 'datastory' in plt.style.available:\n",
" plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2019-02-28-migration-word-counts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
"\n",
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"if 'datastory' in plt.style.available:\n",
" plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2019-03-08-female-mps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"\n",
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"if 'datastory' in plt.style.available:\n",
" plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/2019-03-14-squad.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"from src.plot import ds_plot\n",
"\n",
"%config InlineBackend.figure_format = 'retina'\n",
"plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2019-03-20-urbanization-africa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"\n",
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"if 'datastory' in plt.style.available:\n",
" plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/2019-04-04-no-friends.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"\n",
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2019-04-10-state-budget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"%config InlineBackend.figure_format = 'retina'\n",
"pd.set_option('display.float_format', lambda x: '%.3f' % x)\n",
"\n",
"if 'datastory' in plt.style.available:\n",
" plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions notebooks/2019-04-25-age-of-leaders.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"%config InlineBackend.figure_format = 'retina'\n",
"pd.options.mode.chained_assignment = None\n",
"\n",
"if 'datastory' in plt.style.available:\n",
" plt.style.use('datastory')"
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion notebooks/2019-05-10-media-top-bottom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"import matplotlib.pyplot as plt\n",
"from matplotlib.colors import LinearSegmentedColormap\n",
"\n",
"%config InlineBackend.figure_format = 'retina'"
"%config InlineBackend.figure_format = 'retina'\n",
"\n",
"plt.style.use('../assets/datastory.mpltstyle')"
]
},
{
Expand Down