Skip to content

Commit

Permalink
06-func.md: redraw and cleanup python function figure
Browse files Browse the repository at this point in the history
Pull Request: #573

* Redraw python-function.svg in Inkscape
* Add an indicator for the function body
* Use generic fonts: "monospace" for code and "sans-serif" for text
* Use colors that match the ones used for the code on the page.
* 06-func.md: Remove a comment about the procedure to generate the figure automatically.
* clean up (and slim down) produced SVG even further with
 ```
svgcleaner --indent 2 --ungroup-defs no --coordinates-precision 1 --properties-precision 1 --paths-coordinates-precision 1 <input.svg> <output.svg>
```
and
```
svgcleaner --indent 2 --ungroup-defs no --multipass --coordinates-precision 1 --properties-precision 1 --paths-coordinates-precision 1 <input.svg> <output.svg>
```
  • Loading branch information
leouieda authored and maxim-belkin committed Sep 6, 2018
1 parent 902b720 commit 7b72fbb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
12 changes: 5 additions & 7 deletions _episodes/06-func.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ def fahr_to_celsius(temp):

![The Blueprint for a Python Function](../fig/python-function.svg)

<!--- see https://gist.github.com/wd15/2b4ffbe5ce0d0ddb8a5b to
regenerate the above figure --->

The function definition opens with the keyword `def` followed by the
name of the function (`fahr_to_celsius`) and a parenthesized list of parameter names (`temp`). The
Expand Down Expand Up @@ -266,9 +264,9 @@ but there are a few simple tests that will reassure us:
~~~
print('original min, mean, and max are:', numpy.min(data), numpy.mean(data), numpy.max(data))
offset_data = offset_mean(data, 0)
print('min, mean, and max of offset data are:',
numpy.min(offset_data),
numpy.mean(offset_data),
print('min, mean, and max of offset data are:',
numpy.min(offset_data),
numpy.mean(offset_data),
numpy.max(offset_data))
~~~
{: .language-python}
Expand Down Expand Up @@ -301,7 +299,7 @@ but we probably wouldn't notice if they were different in the sixth decimal plac
Let's do this instead:

~~~
print('difference in standard deviations before and after:',
print('difference in standard deviations before and after:',
numpy.std(data) - numpy.std(offset_data))
~~~
{: .language-python}
Expand All @@ -323,7 +321,7 @@ The usual way to put documentation in software is
to add [comments]({{ page.root }}/reference/#comment) like this:

~~~
# offset_mean(data, target_mean_value):
# offset_mean(data, target_mean_value):
# return a new array containing the original data with its mean offset to match the desired value.
def offset_mean(data, target_mean_value):
return (data - numpy.mean(data)) + target_mean_value
Expand Down
26 changes: 24 additions & 2 deletions fig/python-function.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7b72fbb

Please sign in to comment.