Skip to content

Commit c132f25

Browse files
committed
Plot, profile, animation and appendix
1 parent f3e8b2c commit c132f25

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,13 +2344,13 @@ Plot
23442344
----
23452345
```python
23462346
# $ pip3 install matplotlib
2347-
from matplotlib import pyplot
2348-
pyplot.plot(<y_data> [, label=<str>])
2349-
pyplot.plot(<x_data>, <y_data>)
2350-
pyplot.legend() # Adds a legend.
2351-
pyplot.savefig(<path>) # Saves the figure.
2352-
pyplot.show() # Displays the figure.
2353-
pyplot.clf() # Clears the figure.
2347+
import matplotlib.pyplot as plt
2348+
plt.plot(<y_data> [, label=<str>])
2349+
plt.plot(<x_data>, <y_data>)
2350+
plt.legend() # Adds a legend.
2351+
plt.savefig(<path>) # Saves the figure.
2352+
plt.show() # Displays the figure.
2353+
plt.clf() # Clears the figure.
23542354
```
23552355

23562356

@@ -2557,18 +2557,18 @@ Line # Hits Time Per Hit % Time Line Contents
25572557
=======================================================
25582558
1 @profile
25592559
2 def main():
2560-
3 1 1128.0 1128.0 27.4 a = [*range(10000)]
2561-
4 1 2994.0 2994.0 72.6 b = {*range(10000)}
2560+
3 1 955.0 955.0 43.7 a = [*range(10000)]
2561+
4 1 1231.0 1231.0 56.3 b = {*range(10000)}
25622562
```
25632563

25642564
```text
25652565
$ python3 -m memory_profiler test.py
25662566
Line # Mem usage Increment Line Contents
25672567
=======================================================
2568-
1 35.387 MiB 35.387 MiB @profile
2568+
1 37.668 MiB 37.668 MiB @profile
25692569
2 def main():
2570-
3 35.734 MiB 0.348 MiB a = [*range(10000)]
2571-
4 36.160 MiB 0.426 MiB b = {*range(10000)}
2570+
3 38.012 MiB 0.344 MiB a = [*range(10000)]
2571+
4 38.477 MiB 0.465 MiB b = {*range(10000)}
25722572
```
25732573

25742574
### Call Graph
@@ -2766,7 +2766,7 @@ Animation
27662766
---------
27672767
#### Creates a GIF of a bouncing ball:
27682768
```python
2769-
# $ pip3 install pillow imageio
2769+
# $ pip3 install imageio
27702770
from PIL import Image, ImageDraw
27712771
import imageio
27722772
WIDTH, R = 126, 10
@@ -3486,7 +3486,7 @@ $ pyinstaller script.py --add-data '<path>:.' # Adds file to the root of the ex
34863486
#
34873487

34883488
from sys import argv, exit
3489-
from collections import Counter, defaultdict, namedtuple
3489+
from collections import defaultdict, namedtuple
34903490
from dataclasses import make_dataclass
34913491
from enum import Enum
34923492
import functools, itertools, operator as op, re

index.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,13 +2059,13 @@
20592059

20602060

20612061
<div><h2 id="plot"><a href="#plot" name="plot">#</a>Plot</h2><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install matplotlib</span>
2062-
<span class="hljs-keyword">from</span> matplotlib <span class="hljs-keyword">import</span> pyplot
2063-
pyplot.plot(&lt;y_data&gt; [, label=&lt;str&gt;])
2064-
pyplot.plot(&lt;x_data&gt;, &lt;y_data&gt;)
2065-
pyplot.legend() <span class="hljs-comment"># Adds a legend.</span>
2066-
pyplot.savefig(&lt;path&gt;) <span class="hljs-comment"># Saves the figure.</span>
2067-
pyplot.show() <span class="hljs-comment"># Displays the figure.</span>
2068-
pyplot.clf() <span class="hljs-comment"># Clears the figure.</span>
2062+
<span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt
2063+
plt.plot(&lt;y_data&gt; [, label=&lt;str&gt;])
2064+
plt.plot(&lt;x_data&gt;, &lt;y_data&gt;)
2065+
plt.legend() <span class="hljs-comment"># Adds a legend.</span>
2066+
plt.savefig(&lt;path&gt;) <span class="hljs-comment"># Saves the figure.</span>
2067+
plt.show() <span class="hljs-comment"># Displays the figure.</span>
2068+
plt.clf() <span class="hljs-comment"># Clears the figure.</span>
20692069
</code></pre></div>
20702070

20712071
<div><h2 id="table"><a href="#table" name="table">#</a>Table</h2><div><h4 id="printsacsvfileasanasciitable">Prints a CSV file as an ASCII table:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install tabulate</span>
@@ -2228,16 +2228,16 @@
22282228
=======================================================
22292229
1 @profile
22302230
2 def main():
2231-
3 1 1128.0 1128.0 27.4 a = [*range(10000)]
2232-
4 1 2994.0 2994.0 72.6 b = {*range(10000)}
2231+
3 1 955.0 955.0 43.7 a = [*range(10000)]
2232+
4 1 1231.0 1231.0 56.3 b = {*range(10000)}
22332233
</code></pre>
22342234
<pre><code class="text language-text">$ python3 -m memory_profiler test.py
22352235
Line # Mem usage Increment Line Contents
22362236
=======================================================
2237-
1 35.387 MiB 35.387 MiB @profile
2237+
1 37.668 MiB 37.668 MiB @profile
22382238
2 def main():
2239-
3 35.734 MiB 0.348 MiB a = [*range(10000)]
2240-
4 36.160 MiB 0.426 MiB b = {*range(10000)}
2239+
3 38.012 MiB 0.344 MiB a = [*range(10000)]
2240+
4 38.477 MiB 0.465 MiB b = {*range(10000)}
22412241
</code></pre>
22422242
<div><h3 id="callgraph">Call Graph</h3><div><h4 id="generatesapngimageofacallgraphwithhighlightedbottlenecks">Generates a PNG image of a call graph with highlighted bottlenecks:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install pycallgraph</span>
22432243
<span class="hljs-keyword">from</span> pycallgraph <span class="hljs-keyword">import</span> output, PyCallGraph
@@ -2385,7 +2385,7 @@
23852385
<li><strong>Use <code class="python hljs"><span class="hljs-string">'outline=&lt;color&gt;'</span></code> to set the secondary color.</strong></li>
23862386
<li><strong>Color can be specified as an int, tuple, <code class="python hljs"><span class="hljs-string">'#rrggbb[aa]'</span></code> string or a color name.</strong></li>
23872387
</ul>
2388-
<div><h2 id="animation"><a href="#animation" name="animation">#</a>Animation</h2><div><h4 id="createsagifofabouncingball">Creates a GIF of a bouncing ball:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install pillow imageio</span>
2388+
<div><h2 id="animation"><a href="#animation" name="animation">#</a>Animation</h2><div><h4 id="createsagifofabouncingball">Creates a GIF of a bouncing ball:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install imageio</span>
23892389
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image, ImageDraw
23902390
<span class="hljs-keyword">import</span> imageio
23912391
WIDTH, R = <span class="hljs-number">126</span>, <span class="hljs-number">10</span>
@@ -2972,7 +2972,7 @@
29722972
<span class="hljs-comment">#</span>
29732973

29742974
<span class="hljs-keyword">from</span> sys <span class="hljs-keyword">import</span> argv, exit
2975-
<span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> Counter, defaultdict, namedtuple
2975+
<span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> defaultdict, namedtuple
29762976
<span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> make_dataclass
29772977
<span class="hljs-keyword">from</span> enum <span class="hljs-keyword">import</span> Enum
29782978
<span class="hljs-keyword">import</span> functools, itertools, operator <span class="hljs-keyword">as</span> op, re

0 commit comments

Comments
 (0)