Link Search Menu Expand Document

In-class programming—Altair

Due 2023-09-26, 11:59pm EST 3pts 40min

Please ask any questions about this assignment in class, or later today on Slack.

You are welcome to work with other students on this assignment.

Table of contents

Change log

  • N/A.

Aim of the assignment

Altair is a declarative statistical visualization library for Python, based on Vega and Vega-Lite. In this tutorial you will learn how to use Jupyter Lab and Altair.

Instructions

If you run into problems see the tips, tricks, and troubleshooting section below.

Setup instructions

  1. Install Inkscape from https://inkscape.org/

  2. Accept the GitHub Classroom assignment invitation by clicking this link to get your repository:

    https://classroom.github.com/a/4qWn2rqn

    For reference, this is the template repository your repository is being created from: https://github.com/NEU-DS-4200-F23/In-Class_Programming--Altair.

    Recall our general instructions and policies on GitHub Classroom assignments.

  3. Clone your GitHub-Classroom-generated repository to your local machine.

    E.g., in your terminal / command prompt CD to where you want the folder for this activity to be. Then run: git clone <YOUR_REPO_URL>

  4. CD or open a terminal / command prompt window into the cloned folder.
  5. Create and activate a virtual environment for this project. You may need to modify the code you use depending on what Python you have installed and how your machine is configured. To do so, run the setup commands below.

    • On macOS or Linux, run these three commands separately in case there are errors:

        python3 -m venv env
      
        source env/bin/activate
      
        which python
      
    • On Windows, run these three commands separately in case there are errors:

        python -m venv env
      
        .\env\Scripts\activate.bat
      
        where.exe python
      

    Check the path(s) provided by which python or where.exe python—the first one listed should be inside the env folder you just created.

  6. Install necessary packages.

     python -m pip install -r requirements.txt
    

    This may take a few minutes.

Run Jupyter Lab and create a notebook

  1. Run python -m jupyter lab. It should open Jupyter Lab in your default browser.
  2. Create a new Jupyter Notebook named south_end.ipynb.
  3. Follow along with the in-class tutorial. Once you have written code in a cell you can run it with ctrl+enter. In the menu you can run all cells and restart the kernel to clear variables. If you get lost, you can look at south_end_complete.ipynb.
  4. You will need to also do the infographic creation in Inkscape or Adobe Illustrator. Save your infographic as infographic.svg.

When we are done with the tutorial, if you have time…

  1. Start working through the Altair data visualization curriculum.

At the end of the exercise…

Optionally clear your output

  1. I used to warn folks to clear the outputs of all cells before commiting .ipynb files. This decreases file size, removes unnecessary metadata, and makes diffs easier to understand. In Jupyter Lab you can use the GUI: Edit->Clear All Outputs. But here, we’re using the jupytext package to automatically create a twin .py file you can run using normal Python! It is much easier to diff.

Quit Jupyter Lab and the virtual environment

  1. Make sure to save your .ipynb file and shutdown Jupyter Lab properly through the file menu. Otherwise, you need to use jupyter notebook stop. ​
  2. Deactivate the venv to return to your terminal using deactivate.

Commit and push your code (but first…)

  1. Only if you have made any changes to the required packages (you probably didn’t), first export a list of all installed packages and their versions:

    pip freeze > requirements.txt
    
  2. Make sure to add all your required files, including the .ipynb file and any images to the git repo.

  3. Finally, commit all your local files and push them to the remote repository on GitHub.

Submission instructions

  1. Ensure that:

    1. You cleared all cell outputs.
    2. All of your required files including south_end.ipynb and infographic.svg are committed and pushed to the remote repository on GitHub which was generated by GitHub Classroom. We will grade based on what is available in that repository.

Grading

This is a satisfactory grading assignment. If you followed the instructions you receive full marks and if not you receive a 0. Your submission is satisfactory if you completed the main goal part of the activity, including uploading infographic.svg to your repo.

Criteria Points
Satisfactory? 3

Tips, tricks, and troubleshooting

If you run into trouble, first look at our relevant tutorials which have tips & tricks:


© 2023 Cody Dunne. Released under the CC BY-SA license.