Menu

Data Visualization with Matplotlib

Data Visualization with Matplotlib

Matplotlib is a Python library for creating charts and graphs, helping you understand data patterns before building a machine learning model.

Creating a Simple Line Plot

Line plots show trends, such as how a value changes over time.

import matplotlib.pyplot as plt


x = [1, 2, 3, 4, 5]

y = [10, 20, 25, 30, 40]


plt.plot(x, y)

plt.title("Sample Line Plot")

plt.xlabel("X Axis")

plt.ylabel("Y Axis")

plt.show()

Creating a Bar Chart

Bar charts are useful for comparing values across different categories.

categories = ["A", "B", "C"]

values = [25, 40, 15]


plt.bar(categories, values)

plt.title("Sample Bar Chart")

plt.show()

Creating a Scatter Plot

Scatter plots help you see the relationship between two numerical variables, which is useful when checking correlations before modeling.

x = [5, 10, 15, 20]

y = [12, 18, 25, 30]


plt.scatter(x, y)

plt.title("Sample Scatter Plot")

plt.show()

Creating a Histogram

Histograms show how data is distributed across different ranges of values.

data = [22, 25, 25, 30, 35, 35, 35, 40, 45]


plt.hist(data, bins=5)

plt.title("Sample Histogram")

plt.show()

Matplotlib gives you the basic visualization tools you need to explore data visually, making patterns and outliers much easier to spot before training a model.


Machine Learning Tutorial

AP

Abhishek Pati



Learn via Video Course

Artificial Intelligence and Machine Learning Course Logo

Artificial Intelligence and Machine Learning Course

55 hrs



Get in Touch For Details