` 6th bite of Python

Python VI

Mary PW Chin 钱碧慧博士
PhD (Wales), MSc (Surrey)
E-mail:

1st bite of Python

Getting started

2nd bite of Python

Dice

3rd bite of Python

Circles

4th bite of Python

Statistics & histograms

5th bite of Python

More loops

6th bite of Python

Pretty nets

7th bite of Python

Jumping man

8th bite of Python

Medical scans

9th bite of Python

Handwriting recognition

10th bite of Python

Flower recognition

6th BYTE OF PYTHON

Pretty nets

We shall plot out some pretty plots -- each consists of mathematically staggered straight lines, arranged using different number sequences. A beautiful showcase of loops and number sequences. Nothing but straight lines!

Here are the ingredients you need. Let us say we have two points. One point at coordinates (x,y) = (x1,y1). Another point at coordinates (x,y) = (x2,y2). To plot a straight line joining the two points, we use:
import matplotlib.pyplot as plt
plt.plot( [ x1, x2 ], [ y1, y2 ] )
plt.savefig('myfilename.png')

As an example, if we want to plot a straight line joining point (3,5) to point (17,2), we shall have:
plt.plot( [3, 17], [5, 2] )

Pretty nets with a square frame

Where do we begin?

  1. Divide the plot into 4 banks:
    • lines extending from points along x=0 to points along y=0;
    • lines extending from points along x=50 to points along y=0.
    • lines extending from points along x=0 to points along y=50;
    • lines extending from points along x=50 to points along y=50;
  2. For each bank, construct a 4-column table, with each row on your table corresponding to one straight line of the bank.
    x1y1x2y2
  3. The 'manual' way of plotting would be to have a line
    plt.plot( [ x1, x2 ], [ y1, y2 ] )
    for each of the line we wish to plot. This is the first step.
  4. The next step would be to put the above into 4 loops. A loop for each bank.
  5. The next step would be to condense the 4 loops you already have into a single loop containing 4 lines of
    plt.plot( [ x1, x2 ], [ y1, y2 ] )

Pretty nets with a circular frame

This will require some trigonometry, which is presented in the slides.

Pretty nets with a triangular frame

This will require some trigonometry, which is presented in the slides.

1st bite of Python

Getting started

2nd bite of Python

Dice

3rd bite of Python

Circles

4th bite of Python

Statistics & histograms

5th bite of Python

More loops

6th bite of Python

Pretty nets

7th bite of Python

Jumping man

8th bite of Python

Medical scans

9th bite of Python

Handwriting recognition

10th bite of Python

Flower recognition