From 54d871a743c5de68ea70cf30a93d94b7795e9c94 Mon Sep 17 00:00:00 2001 From: Aditya Srivastava Date: Sat, 6 Jun 2015 16:42:09 +0530 Subject: [PATCH 1/3] Typos > Line 31 --- website/_containers/dataviz/2013-01-03-part-2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/_containers/dataviz/2013-01-03-part-2.md b/website/_containers/dataviz/2013-01-03-part-2.md index dfdd1c47..312fcd3e 100644 --- a/website/_containers/dataviz/2013-01-03-part-2.md +++ b/website/_containers/dataviz/2013-01-03-part-2.md @@ -28,7 +28,7 @@ Graph our sample data with matplotlib. - We include the parse function here so we build on the process of parse → plot. We need to parse the data into the list of dictionaries so that we can easily tell matplotlib what and how to plot. We could, however, imported it from `parse.py`. As a **challenge** to you, try editing away the parse function in `graph.py` and import it from your `parse.py`. ### Visualize Functions -Let’s first take a look at a chuck of data that we just parsed to get a better idea of what sort of data we’re working with: +Let’s first take a look at a chunk of data that we just parsed to get a better idea of what sort of data we’re working with: ```bash { From 7ad79bb0b535e950ab9750351fd2ea7cae7a055b Mon Sep 17 00:00:00 2001 From: Aditya Srivastava Date: Sat, 6 Jun 2015 17:35:45 +0530 Subject: [PATCH 2/3] Added challenge line 149 --- website/_containers/dataviz/2013-01-03-part-2.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/website/_containers/dataviz/2013-01-03-part-2.md b/website/_containers/dataviz/2013-01-03-part-2.md index 312fcd3e..1366fd93 100644 --- a/website/_containers/dataviz/2013-01-03-part-2.md +++ b/website/_containers/dataviz/2013-01-03-part-2.md @@ -121,7 +121,7 @@ item["DayOfWeek"] for item in data_file This is called a list comprehension. You can read it as, “iterate every dictionary value of every dictionary key set to ‘DayOfWeek’ for every line item in `data_file`.” A list comprehension just a for-loop put in a more elegant, “Pythonic” way.
-Challenge yourself: write out a for-loop for our counter variable. +Challenge yourself: Write out a for-loop for our counter variable.
@@ -145,6 +145,10 @@ The counter object is a dictionary with the keys as days of the week, and values Here, `data_list` takes each key of `counter` to grab the value associated with each day. Because we manually write out each `counter` key, we force the order that we want. **Note:** a dictionary does _not_ preserve order, but a list does; this is why we’re electing to manually key into each value of a dictionary to make a list of each value. +
+Challenge yourself: Write out the data_list variable code as a list comprehension. +
+ The `day_tuple` is just a tuple of strings that we will use for our x-axis labels. **A quick note:** we had to make our `day_tuple` variable a tuple because `plt.xticks()` only accepts tuples for labeling the x-axis. This is because tuples are an immutable type of data structure in Python’s library, meaning you can’t change it (not without making a copy of the variable onto a new variable), as well as it preserves order. We now tell `matplotlib` to use our `data_list` as data points to plot. The `pyplot` module, what we’ve renamed as `plt`, has a function called `plot()` which takes a list of data points to plot on the y-axis: From 39541143c2d7c29f431bf9153f65a554917526a8 Mon Sep 17 00:00:00 2001 From: Aditya Srivastava Date: Sat, 6 Jun 2015 17:41:07 +0530 Subject: [PATCH 3/3] Update 2013-01-03-part-2.md --- website/_containers/dataviz/2013-01-03-part-2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/_containers/dataviz/2013-01-03-part-2.md b/website/_containers/dataviz/2013-01-03-part-2.md index 1366fd93..66043a76 100644 --- a/website/_containers/dataviz/2013-01-03-part-2.md +++ b/website/_containers/dataviz/2013-01-03-part-2.md @@ -167,7 +167,7 @@ Just creating the variable `day_tuple` for our x-axis isn’t enough — we also plt.xticks(range(len(day_tuple)), day_tuple) ``` -We give `plt.xticks()` two parameters, one being a list and the other being our tuple, `labels`. +We give `plt.xticks()` two parameters, one being a list and the other being our tuple, `day_tuple`. The first parameter is `range(len(day_tuple))`. Here, we call `len()` on our `day_tuple` variable — `len()` returns an integer, a count of the number of items in our tuple `day_tuple`. Since we have seven items in our `day_tuple` (**pop quiz:** why do we have seven items?), the `len()` will return 7. Now we have `range()` on our length of the `day_tuple`. If you feed `range()` one parameter `x`, it will produce a list of integers from `0` to `x` (not including `x`). So, deconstructed, we fed `plt.xticks()` the following: