|
2059 | 2059 |
|
2060 | 2060 |
|
2061 | 2061 | <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(<y_data> [, label=<str>]) |
2064 |
| -pyplot.plot(<x_data>, <y_data>) |
2065 |
| -pyplot.legend() <span class="hljs-comment"># Adds a legend.</span> |
2066 |
| -pyplot.savefig(<path>) <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(<y_data> [, label=<str>]) |
| 2064 | +plt.plot(<x_data>, <y_data>) |
| 2065 | +plt.legend() <span class="hljs-comment"># Adds a legend.</span> |
| 2066 | +plt.savefig(<path>) <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> |
2069 | 2069 | </code></pre></div>
|
2070 | 2070 |
|
2071 | 2071 | <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 | 2228 | =======================================================
|
2229 | 2229 | 1 @profile
|
2230 | 2230 | 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)} |
2233 | 2233 | </code></pre>
|
2234 | 2234 | <pre><code class="text language-text">$ python3 -m memory_profiler test.py
|
2235 | 2235 | Line # Mem usage Increment Line Contents
|
2236 | 2236 | =======================================================
|
2237 |
| - 1 35.387 MiB 35.387 MiB @profile |
| 2237 | + 1 37.668 MiB 37.668 MiB @profile |
2238 | 2238 | 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)} |
2241 | 2241 | </code></pre>
|
2242 | 2242 | <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>
|
2243 | 2243 | <span class="hljs-keyword">from</span> pycallgraph <span class="hljs-keyword">import</span> output, PyCallGraph
|
|
2385 | 2385 | <li><strong>Use <code class="python hljs"><span class="hljs-string">'outline=<color>'</span></code> to set the secondary color.</strong></li>
|
2386 | 2386 | <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>
|
2387 | 2387 | </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> |
2389 | 2389 | <span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image, ImageDraw
|
2390 | 2390 | <span class="hljs-keyword">import</span> imageio
|
2391 | 2391 | WIDTH, R = <span class="hljs-number">126</span>, <span class="hljs-number">10</span>
|
|
2972 | 2972 | <span class="hljs-comment">#</span>
|
2973 | 2973 |
|
2974 | 2974 | <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 |
2976 | 2976 | <span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> make_dataclass
|
2977 | 2977 | <span class="hljs-keyword">from</span> enum <span class="hljs-keyword">import</span> Enum
|
2978 | 2978 | <span class="hljs-keyword">import</span> functools, itertools, operator <span class="hljs-keyword">as</span> op, re
|
|
0 commit comments