From 59adf809769ecb65ef10edc7094f98e6fa6c4882 Mon Sep 17 00:00:00 2001 From: Mike Sawitzke Date: Tue, 16 Dec 2014 11:15:14 -0800 Subject: [PATCH 1/5] Fixed typo --- website/_posts/DataViz/2013-01-03-Part-2-Graph.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/_posts/DataViz/2013-01-03-Part-2-Graph.md b/website/_posts/DataViz/2013-01-03-Part-2-Graph.md index 34a9f7a5..676c080b 100644 --- a/website/_posts/DataViz/2013-01-03-Part-2-Graph.md +++ b/website/_posts/DataViz/2013-01-03-Part-2-Graph.md @@ -281,7 +281,7 @@ def visualize_type(): # by category # Set the labels which are based on the keys of our counter. - # Since order doesn't matter, we can just used counter.keys() + # Since order doesn't matter, we can just use counter.keys() # Set exactly where the labels hit the x-axis From 52fb258078380bf91ce89d1bfb1ca972cd52eb89 Mon Sep 17 00:00:00 2001 From: Mike Sawitzke Date: Tue, 16 Dec 2014 11:18:09 -0800 Subject: [PATCH 2/5] Made comments match from initial walkthrough to step-by-step. --- website/_posts/DataViz/2013-01-03-Part-2-Graph.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/_posts/DataViz/2013-01-03-Part-2-Graph.md b/website/_posts/DataViz/2013-01-03-Part-2-Graph.md index 676c080b..aa79f69e 100644 --- a/website/_posts/DataViz/2013-01-03-Part-2-Graph.md +++ b/website/_posts/DataViz/2013-01-03-Part-2-Graph.md @@ -157,7 +157,8 @@ If you are curious about the `plot()` function, open a `python` prompt in your t Just creating the variable `day_tuple` for our x-axis isn’t enough — we also have to assign it to our `plt` by using the method `xticks()`: ```python - # Assign labels to the plot + # create the amount of ticks needed for our x-axis, and assign + # the labels plt.xticks(range(len(day_tuple)), day_tuple) ``` From 32aca240abc94e885ffc4526f0aeb78d9388072f Mon Sep 17 00:00:00 2001 From: Mike Sawitzke Date: Tue, 16 Dec 2014 11:38:21 -0800 Subject: [PATCH 3/5] Added omiitted text so the sentence is complete. --- website/_posts/DataViz/2013-01-03-Part-2-Graph.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/_posts/DataViz/2013-01-03-Part-2-Graph.md b/website/_posts/DataViz/2013-01-03-Part-2-Graph.md index aa79f69e..183d943f 100644 --- a/website/_posts/DataViz/2013-01-03-Part-2-Graph.md +++ b/website/_posts/DataViz/2013-01-03-Part-2-Graph.md @@ -337,7 +337,7 @@ For the `plt.xticks()`, the first parameter should look similar to before, but h Notice how we can pass `xticks()` more parameters than we did before. If you read the [documentation](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xticks) of that function, you can pass it `*args` and `**kwargs`, or arguments and keyword arguments. It mentions that you can pass matplotlib-defined [text properties](http://matplotlib.org/api/artist_api.html#matplotlib.text.Text) for the labels — so that would explain the `**kwargs` element there. If nothing is passed in for `rotation` then it’s set to a default defined in their text properties documentation. -Next, we just add a little bit of spacing to the bottom of the graph so the labels (since some of them are long, like `Forgery/Counterfeiting`). We use the `.subplots_adjust()` function. In matplotlib, you have the ability to render multiple graphs on one window/function, called subplots. With one graph, subplots can be used to adjust the spacing around the graph itself. +Next, we just add a little bit of spacing to the bottom of the graph so the labels (since some of them are long, like `Forgery/Counterfeiting`) aren't cut off in the graph. We use the `.subplots_adjust()` function. In matplotlib, you have the ability to render multiple graphs on one window/function, called subplots. With one graph, subplots can be used to adjust the spacing around the graph itself. ```python # Give some more room so the labels aren't cut off in the graph From 8baec9aa5dc00034a9a6ae1e86f4ff97725964f1 Mon Sep 17 00:00:00 2001 From: Mike Sawitzke Date: Tue, 16 Dec 2014 11:42:47 -0800 Subject: [PATCH 4/5] Made walkthrough comments match --- website/_posts/DataViz/2013-01-03-Part-2-Graph.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/_posts/DataViz/2013-01-03-Part-2-Graph.md b/website/_posts/DataViz/2013-01-03-Part-2-Graph.md index 183d943f..8c704bc5 100644 --- a/website/_posts/DataViz/2013-01-03-Part-2-Graph.md +++ b/website/_posts/DataViz/2013-01-03-Part-2-Graph.md @@ -358,7 +358,7 @@ Again — here I just played with the numbers until I got something I liked. I e Finally, our favorite — rendering and closing the graph! ```python - # Save the plot! + # Save the graph! plt.savefig("Type.png") # Close figure From 873f3b71719603e6483008a838a625ac17e04735 Mon Sep 17 00:00:00 2001 From: Mike Sawitzke Date: Tue, 16 Dec 2014 11:48:45 -0800 Subject: [PATCH 5/5] Added some ommitted steps for the width variable and plt.bar() portion of the tutorial. --- website/_posts/DataViz/2013-01-03-Part-2-Graph.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/website/_posts/DataViz/2013-01-03-Part-2-Graph.md b/website/_posts/DataViz/2013-01-03-Part-2-Graph.md index 8c704bc5..a0996eeb 100644 --- a/website/_posts/DataViz/2013-01-03-Part-2-Graph.md +++ b/website/_posts/DataViz/2013-01-03-Part-2-Graph.md @@ -326,6 +326,16 @@ Next we finally use a bit of numpy magic (we had imported the numpy library as ` We have a new variable, `xlocations`, which will be used to help place the `plt.xticks()`. We’re using the `numpy` (aka `np`) library to access the `arange` function. This creates a list similar to what `range()` would make, into an array that you can manipulate a bit differently. Here, we're adding `0.5`. If you were to `print xlocations`, you would see `[0.5, 1.5, 2.5, ... , 16.5, 17.5]` where `0.5` was added to each int of the list. You’ll see why we need the `0.5` a bit later. +We need to set the width variable and assign data to the bar plot: + +```python + # Width of each bar + width = 0.5 + + # Assign data to a bar plot + plt.bar(xlocations, counter.values(), width=width) +``` + Now we assign our x- & y-ticks (should be familiar to `visualize_days()`): ```python