Introduction • This presentation covers essential intermediate Python topics. • We'll explore data visualization, numerical computing, concurrency, and networking. • Libraries covered: Matplotlib, NumPy, Threading, and Sockets.
Matplotlib: Data Visualization • Matplotlib is used for creating static, animated, and interactive visualizations. • Common plots: Line graphs, bar charts, histograms, scatter plots. • Key functions: plt.plot(), plt.bar(), plt.hist(), plt.scatter(). • Customization options for labels, colors, and styles.
Matplotlib Example Code ```python import matplotlib.pyplot as plt x = [1, 2, 3, 4] y = [10, 20, 25, 30] plt.plot(x, y, marker='o', linestyle='-') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Sample Line Plot') plt.show() ```
NumPy: Numerical Computing • NumPy is a powerful library for numerical operations. • Provides support for multi-dimensional arrays and matrices. • Optimized for performance compared to Python lists. • Common functions: np.array(), np.linspace(), np.mean(), np.std().
Threading: Concurrency in Python • The threading module allows parallel execution of tasks. • Useful for I/O-bound operations but not CPU-intensive tasks. • Key functions: threading.Thread(), start(), join(). • Avoids blocking operations by running multiple tasks concurrently.
Threading Example Code ```python import threading import time def print_numbers(): for i in range(5): print(i) time.sleep(1) t = threading.Thread(target=print_numbers) t.start() t.join() print('Thread finished') ```
Sockets: Networking in Python • The socket module allows network communication between computers. • Supports TCP and UDP protocols. • Common functions: socket(), bind(), listen(), accept(), send(), recv(). • Used in building servers, clients, and peer-to-peer applications.