Back to Intro to Programming with Java

Lesson PreviewLesson 4 of 4 in this unit

1.4 Visualizing Data with Matplotlib

Part of Intro to Programming with Java in Data Science. Read the opening section, then create a free account for the full interactive lesson, practice, and progress tracking.

Matplotlib is a widely used Python library for creating static, animated, and interactive visualizations. It provides a flexible framework to generate various plots, including line graphs, bar charts, histograms, and scatter plots. With Matplotlib, users can customize every aspect of a plot, such as labels, colors, legends, and grid lines, making it a powerful tool for data exploration and presentation. It integrates well with libraries like Pandas and NumPy, allowing seamless visualization of datasets.

To create a simple line plot with Matplotlib, first import the library and define your data points:

python
import matplotlib.pyplot as plt

# Data
ages = [16, 17, 18, 19, 20]
scores = [75, 80, 85, 90, 95]

# Create a figure
plt.figure()

# Plot the data
plt.plot(ages, scores, marker='o', linestyle='-', color='b', label="Score Trend")

# Add labels and title
plt.xlabel("Age")
plt.ylabel("Score")
plt.title("Age vs. Score")
plt.legend()

# Show the plot
plt.show()

Output

#img coming soon!

Continue the full lesson in Stellar

Create a free account to unlock the remaining sections, checkpoints, course practice, and progress tracking for Data Science.