forked from ehmatthes/pcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ehmatthes#10 from ehmatthes/pygal_update
Pygal update
- Loading branch information
Showing
14 changed files
with
211 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pygal | ||
|
||
from die import Die | ||
|
||
# Create two D6 dice. | ||
die_1 = Die() | ||
die_2 = Die() | ||
|
||
# Make some rolls, and store results in a list. | ||
results = [] | ||
for roll_num in range(1000): | ||
result = die_1.roll() + die_2.roll() | ||
results.append(result) | ||
|
||
# Analyze the results. | ||
frequencies = [] | ||
max_result = die_1.num_sides + die_2.num_sides | ||
for value in range(2, max_result+1): | ||
frequency = results.count(value) | ||
frequencies.append(frequency) | ||
|
||
# Visualize the results. | ||
hist = pygal.Bar() | ||
hist.force_uri_protocol = 'http' | ||
|
||
hist.title = "Results of rolling two D6 dice 1000 times." | ||
hist.x_labels = ['2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'] | ||
hist.x_title = "Result" | ||
hist.y_title = "Frequency of Result" | ||
|
||
hist.add('D6 + D6', frequencies) | ||
hist.render_to_file('dice_visual.svg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from random import randint | ||
|
||
class Die(): | ||
"""A class representing a single die.""" | ||
|
||
def __init__(self, num_sides=6): | ||
"""Assume a six-sided die.""" | ||
self.num_sides = num_sides | ||
|
||
def roll(self): | ||
""""Return a random value between 1 and number of sides.""" | ||
return randint(1, self.num_sides) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pygal | ||
|
||
from die import Die | ||
|
||
# Create a D6. | ||
die = Die() | ||
|
||
# Make some rolls, and store results in a list. | ||
results = [] | ||
for roll_num in range(1000): | ||
result = die.roll() | ||
results.append(result) | ||
|
||
# Analyze the results. | ||
frequencies = [] | ||
for value in range(1, die.num_sides+1): | ||
frequency = results.count(value) | ||
frequencies.append(frequency) | ||
|
||
# Visualize the results. | ||
hist = pygal.Bar() | ||
hist.force_uri_protocol = 'http' | ||
|
||
hist.title = "Results of rolling one D6 1000 times." | ||
hist.x_labels = ['1', '2', '3', '4', '5', '6'] | ||
hist.x_title = "Result" | ||
hist.y_title = "Frequency of Result" | ||
|
||
hist.add('D6', frequencies) | ||
hist.render_to_file('die_visual.svg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from die import Die | ||
|
||
import pygal | ||
|
||
# Create a D6 and a D10. | ||
die_1 = Die() | ||
die_2 = Die(10) | ||
|
||
# Make some rolls, and store results in a list. | ||
results = [] | ||
for roll_num in range(50000): | ||
result = die_1.roll() + die_2.roll() | ||
results.append(result) | ||
|
||
# Analyze the results. | ||
frequencies = [] | ||
max_result = die_1.num_sides + die_2.num_sides | ||
for value in range(2, max_result+1): | ||
frequency = results.count(value) | ||
frequencies.append(frequency) | ||
|
||
# Visualize the results. | ||
hist = pygal.Bar() | ||
hist.force_uri_protocol = 'http' | ||
|
||
hist.title = "Results of rolling a D6 and a D10 50,000 times." | ||
hist.x_labels = ['2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', | ||
'13', '14', '15', '16'] | ||
hist.x_title = "Result" | ||
hist.y_title = "Frequency of Result" | ||
|
||
hist.add('D10 + D10', frequencies) | ||
hist.render_to_file('dice_visual.svg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Chapter 17 | ||
=== | ||
|
||
Updates | ||
--- | ||
|
||
As you probably saw in [Chapter 15](chapter_15/README.md#updates) and [Chapter 16](chapter_16/README.md#updates), you'll need to add a line each time you make a chart in order to render tooltips correctly: | ||
|
||
<pre> | ||
chart = pygal.Bar() | ||
<b>chart.force_uri_protocol = 'http'</b> | ||
</pre> | ||
|
||
Page by page updates | ||
--- | ||
|
||
### p. 384-385, python_repos.py | ||
|
||
<pre> | ||
chart = pygal.Bar(style=my_style, x_label_rotation=45, show_legend=False) | ||
<b>chart.force_uri_protocol = 'http'</b> | ||
</pre> | ||
|
||
### p. 387-388, bar_descriptions.py | ||
|
||
<pre> | ||
chart = pygal.Bar(style=my_style, x_label_rotation=45, show_legend=False) | ||
<b>chart.force_uri_protocol = 'http'</b> | ||
</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters