Typing and Data Visualization
Introduction
- Lecture 13 on Typing and Data Visualization from Department of Informatics, UC Irvine.
- Important: Duplication of course material for commercial purposes without permission is prohibited.
A3 Assignment Insights
- Admin Mode:
- Optional to keep; helps in decoupling tasks from user interaction. - Core Functionality:
- Most ideas for core functionality are from previous lectures. - Resources:
- Regularly check posts at the class website: https://ics32distributedsocial.com/
- Reminder to be polite as server logs address information to prevent DoS attacks on the server.
Code Quality Considerations
PEP8 Violations:
- Current testing focuses on PEP8 for style violations throughpycodestyle.Potential Issues Beyond PEP8:
- Bad variable/function naming (e.g., single letters like "f", "r").
- Lack of documentation – functions/classes must include docstrings.
- Excessive nested structures or branches.
- Improperly structured main block (too much logic insideif __name__ == "__main__":).
- No exception handling.Improvement Over Time:
- Discussed that avoiding these issues is easier with experience.Use of Code Linters:
- Recommended: Always run a linter likepylintbefore submitting assignments.
- Linting helps in identifying potential quality issues through static code analysis.
Example of Poor Code Submission
- Characteristics of Bad Code Submission:
- Code works but is hard to maintain and extend.
- Need to break code into smaller functions for better readability and management.
Typing in Python
- Type Inference:
- Python dynamically infers variable types and does not enforce them after initial assignment.
- Function usage defines how variables are treated.
- Concept of Duck Typing: An object’s suitability is determined by whether it behaves as expected, regardless of its type.
Inheritance and Abstract Classes
- Abstract Classes:
- A class that serves as a blueprint for other classes but is not instantiated itself.
- Example of abstract classes includes base types like "Number" and specific subclasses like "Integer", "Float", etc. - Abstract Methods:
- Methods that must be defined in child classes without an implementation in the abstract base class.
Data Visualization Fundamentals
- Importance of Visualization:
- Core task when dealing with data, can also apply to understanding software. - Visualization Methods:
- Libraries in Python provide different paradigms:
- 2D / 3D outputs
- Interactive vs. Non-interactive
- Local vs. Web-based. - Key Visualization Libraries:
-matplotlib,seaborn,plotnine,plot.ly, andBokeh.
- Installation: Usepip install <lib_name>.
Using Matplotlib for Visualization
- Creating Visuals with Matplotlib:
- Figure and Axis Creation:
- Begin by creating a figure and adjusting size/layout.
- Adding Data to Plot:
- Default plotting is a line viaax.plot().
- Labeling Axes:
- Essential to define X and Y axis labels.
- Rendering the Plot:
- Save or display the plot withplt.savefig()orplt.show().
Building a Simple Weather API Tool
- Example Tool:
- Tool for fetching daily weather data via a web API. - Data Extraction and Plotting Process:
- Use standard libraries (urllib,json) to retrieve and process weather data.
- Create figures reflecting temperature patterns alongside data timestamps. - Code Structure:
- Separate concerns (data fetching and plotting) into distinct functions for clarity and maintenance.