DATA VISUALIZATION WITH MATPLOTLIB

Matplotlib is a powerful data visualization library in Python that allows you to create a wide range of static, interactive, and animated visualizations. It provides a high-level interface for generating various types of plots, including line plots, scatter plots, bar plots, histograms, pie charts, and more. Let's explore some common data visualization techniques using Matplotlib:

1. Line Plot: Line plots are used to visualize the trend of data points over a continuous variable (e.g., time, temperature).

python
import matplotlib.pyplot as plt # Data x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] # Create a line plot plt.plot(x, y) # Add labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Line Plot') # Display the plot plt.show()

2. Scatter Plot: Scatter plots are useful for visualizing the relationship between two numerical variables.

python
# Data x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] # Create a scatter plot plt.scatter(x, y) # Add labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Scatter Plot') # Display the plot plt.show()

3. Bar Plot: Bar plots are used to compare categories of data.

python
# Data categories = ['A', 'B', 'C', 'D'] values = [10, 15, 8, 12] # Create a bar plot plt.bar(categories, values) # Add labels and title plt.xlabel('Categories') plt.ylabel('Values') plt.title('Bar Plot') # Display the plot plt.show()

4. Histogram: Histograms display the distribution of numerical data.

python
# Data data = [10, 12, 15, 18, 20, 22, 25, 28, 30, 32] # Create a histogram plt.hist(data, bins=5) # Add labels and title plt.xlabel('Value') plt.ylabel('Frequency') plt.title('Histogram') # Display the plot plt.show()

5. Pie Chart: Pie charts show the proportion of different categories in a dataset.

python
# Data categories = ['A', 'B', 'C', 'D'] sizes = [30, 25, 20, 15] # Create a pie chart plt.pie(sizes, labels=categories, autopct='%1.1f%%') # Add title plt.title('Pie Chart') # Display the plot plt.show()

These are just a few examples of the visualizations you can create with Matplotlib. The library offers extensive customization options, including colors, styles, annotations, and legends, allowing you to create publication-quality plots for data exploration and presentation. Matplotlib is a versatile tool for data visualization, and it is often used in combination with Pandas for seamless integration with data analysis workflows.