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 through
pycodestyle.
- Current testing focuses on PEP8 for style violations through
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 inside
if __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 like
pylintbefore submitting assignments. - Linting helps in identifying potential quality issues through static code analysis.
- Recommended: Always run a linter like
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.
- Libraries in Python provide different paradigms:
- Key Visualization Libraries:
matplotlib,seaborn,plotnine,plot.ly, andBokeh.- Installation: Use
pip 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 via
ax.plot().
- Default plotting is a line via
- Labeling Axes:
- Essential to define X and Y axis labels.
- Rendering the Plot:
- Save or display the plot with
plt.savefig()orplt.show().
- Save or display the plot with
- Figure and Axis Creation:
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.
- Use standard libraries (
- Code Structure:
- Separate concerns (data fetching and plotting) into distinct functions for clarity and maintenance.