First-Week Lab Instructions

Note: If your monitor doesn’t show a Mac login screen, let Steve Goryl or me know right away so we can fix it. Otherwise, go ahead and log in using your W&L account. (Long-time Mac users will might worry that the Mac command key ⌘ is missing, but on our keyboards its equivalent is the Windows key between CTRL and ALT.)

The purpose of this lab is to

  1. Pick a lab partner to work with for the term
  2. Get familiar with the IDLE3 environment for Python
  3. Get familiar with the NumPy and Matplotlib Python packages
  4. Make sure we can use Sakai turnins

The deliverable for this lab will be a single PDF document, copied into the Sakai turnin folders of you and your lab partner.

If you’re reading this, you’ve probably already logged into one of the Mac computers in the lab. Move your mouse to a free area on the desktop, click the right mouse button, and choose New Folder. Create a folder called lab1, which is where you’ll save your work for this lab before uploading the deliverable to Sakai. I suggest doing this for every lab from now on.

Next, click on the little Spotlight Search (magnifying glass) icon in the upper right of the display, and type IDLE. You’ll get a choice between IDLE – Python 2.7 and IDLE – Python 3.6. Choose 3.6. by double-clicking on it. The Python Shell should now appear, meaning that you are now ready to type your first Python commands.

Here are the commands to make a simple sine-wave plot. Note that the triple-arrow >>> is the Python prompt, which you should not include when typing in your commands. (Pro tip: Copying-and-pasting commands is usually less error-prone than trying to type them yourself: left-drag to highlight; right-click/copy; move to IDLE; right-click/paste; Enter)

>>> from numpy import *
>>> from matplotlib.pyplot import *
>>> x = linspace(0, 2*pi, 1000)
>>> y = sin(x)
>>> plot(x, y)
>>> show()

Once you’re comfortable typing commands, you’ll want to set up a couple of shortcuts to speed up your workflow. First, find the IDLE/Python app icon in the dock at the bottom of the screen. Right clock on it, then do Options/Keep in Dock. Next, add a couple of IDLE keyboard shortcuts to save time re-typing. At the top of the IDLE3 window, choose Options/Configure IDLE. A little dialog window will pop up with a bunch of tabs at the top. Choose the Keys tab. In the white area toward the bottom you’ll see an alphabetized list of Custom Key Bindings. Scroll down to history-next, and select it. Then click the big button Get New Keys for Selection. (If you’re asked for a name under which to save the custom bindings, enter something simple like custom.) Another little dialog will pop up, allowing you scroll to the name of the key you want. Choose Down Arrow. Click Ok, then repeat this process for the history-previous key, for which you should choose Up Arrow. Once you’ve set up these two keys, choose Ok to exit the main dialog.

Once you’ve got a nice plot to show off, go to the figure window (usually titled Figure 1), and click the little floppy-disk button at the bottom of the figure to save the plot inPNG format. Make sure to save it in the lab1 folder that you created for this lab, and call it something sensible, like sineplot.png.

To produce your writeup, do a Spotlight search for Pages, the Mac equivalent of Microsoft Word. Use Pages to create an empty document, then put your names, the date, and other identifying information (name of this class, Lab #1) at the top. Then save this document in the same lab1 folder, naming it (of course) lab1. Drag your figure PNG into the document, then right-click on it to add a little caption. To finish up, add a brief explanation of the linspace function that you used to generate the x values. You can get the explanation by doing

>>> help(linspace)

in the Python shell, or by goolging linspace.

Once you’ve got a nice-looking writeup, export the document to PDF format and upload it to Sakai. Make sure you only upload this PDF: you will get no credit for a document in any other format. In this lab and future labs, I encourage you to check with me right away to make sure that you’ve uploaded the material in the correct format.