![A Beginner’s Guide to Data Visualization with Matplotlib [2025] 1 Post thumbnail](https://www.guvi.in/blog/wp-content/uploads/2025/07/data-visualization.webp)
A Beginner’s Guide to Data Visualization with Matplotlib [2025]
Jul 01, 2025 4 Min Read 167 Views
(Last Updated)
You interact with data every day on social media trends, fitness stats, or even shopping preferences. But rows of numbers don’t tell the story—the charts, graphs, and heatmaps do. That’s where data visualization comes in: the art and science of transforming raw data into clear, powerful visuals.
In this guide, you’ll learn why data visualization matters, explore top Python tools like Matplotlib and Seaborn, and discover step-by-step techniques to turn CSV files into compelling visual insights—all designed to be beginner-friendly and SEO-smart. Let’s get started!
Table of contents
- What is Data Visualization?
- Why Use Python for Data Visualization?
- Why Matplotlib?
- Getting Started with Matplotlib
- Visualization Types with Examples
- 1) Scatter Plot
- 2) Line Chart
- 3) Histogram
- 4) Pie Chart
- 5) Heatmap
- 6) Subplot
- Concluding Thoughts…
What is Data Visualization?
Data visualization is the process of converting structured data into a graphical format that helps in identifying relationships, trends, correlations, and outliers. It’s one of the most essential steps in data analysis, machine learning, and reporting.
Imagine having a dataset with one lakh rows. Understanding it by reading line by line is impossible. But by plotting just a 6×6 graph, you can reveal patterns that could take hours to find otherwise.
Why Use Python for Data Visualization?
Python has become the go-to language for data science, and it excels in visualization thanks to rich libraries like:
- Matplotlib – Fully customizable and versatile
- Seaborn – Built on Matplotlib, but offers statistical plots and better aesthetics
- Plotly – Interactive graphs for dashboards
- Bokeh – High-performance streaming and real-time visualization
- Altair, VisPy, and more
Hence, Python is the go-to language for all things data, including visualization. In this article, we focus on Matplotlib, as it is beginner-friendly and extremely powerful.
Why Matplotlib?
Here’s why Matplotlib is widely used:
Feature | Benefit |
Open-source | Free to use for personal and commercial purposes |
Highly customizable | Control every element of your graph |
Community support | Thousands of tutorials, solutions, and open-source contributions |
Compatibility | Works well with Pandas, Numpy, and other libraries |
Publication-ready output | Export visuals in high-resolution formats (PNG, SVG, PDF) |
Getting Started with Matplotlib
1) Install Matplotlib (if not already):
pip install matplotlib
2) Import the necessary module:
import matplotlib.pyplot as plt
Let’s understand some core customization functions:
3) Matplotlib Methods:
There are various methods to customize the Outer part of the graphs. Some of the important matplotlib methods are:
- title( ): title( ) method allows us to give whatever title we need to give to that plot. We can also customize our titles’ color, size, alignment, etc. It takes the Title as a positional argument.
- xlabel( ): The xlabel( ) method allows us to give labels to the x-axis. It takes the label as a positional argument.
- ylabel( ): The ylabel( ) method allows us to give a label to the y-axis. It takes the label as a positional argument.
- legend( ): This method allows us to place legends in our graph.
- axis( ): This method is used to set the coordinates of the plot. It takes an array as input [x_min, x_max, y_min, y_max].
Let’s see them in action:
style.use("grayscale")
plt.title("TITLE")
plt.xlabel("X-AXIS")
plt.ylabel("Y-AXIS")
plt.legend(loc="upper right",title="Legend",title_fontsize="small")
plt.axis([0,10,0,10])
Output:
Visualization Types with Examples
There are four types of Visualization plots. They are:
- Relationship Charts
- Comparison Charts
- Distribution Charts
- Composition Charts
In this article, we are going to see one example from each category as well as discuss its importance. The table given below represents the characters that represent different styles of marker, line, color.
1) Scatter Plot
A scatter plot helps you visualize the relationship between two variables by plotting data points on the X and Y axes. Each dot represents an observation, making it easy to identify correlations, clusters, and outliers.
This type of chart is ideal for large datasets and is commonly used in fields like marketing, health, and finance to detect trends and patterns quickly.
Syntax:
plt.scatter(x, y, data, c, marker)
x = array or series.
y = array or series.
data = Dataframe, where the data is present.
c = Colour of the datapoints.
marker = Shape of the marker.
df = pd.read_csv("Data.csv")
plt.scatter("Age","Salary",c="c", marker="D", data=df)
plt.annotate("Maximum", ha="left", va="center", xytext=(45,84000), xy=(50,83000), arrowprops={"facecolor":"red"})
plt.legend(loc="upper right", fontsize="x-small", title="Legend", title_fontsize="small")
plt.title("Age vs Estimated Salary")
plt.xlabel("Age")
plt.ylabel("Estimated Salary")
Output:
2) Line Chart
Line charts are best for showing how data changes over time. They connect a sequence of data points with lines, making trends and fluctuations easy to track.
You can also plot multiple lines on the same chart to compare variables, such as sales across regions or user activity across different platforms.
Syntax:
plt.plot(x, y, fmt, data, alpha)
Fmt = fmt is a combination of linestyle, marker style, and color. The order of combinations is “marker-line-color” or “color-marker-line”.
Alpha = Transparency of the line can be adjusted using this parameter.
plt.plot("Age", "Salary", "^-r", data=df, alpha=1)
plt.annotate("Least", ha="center", va="bottom", xytext=(27,55000), xy=(27,48000), arrowprops={"facecolor":"yellow"})
plt.title("Age vs Estimated Salary")
plt.xlabel("Age")
plt.ylabel("Estimated Salary")
Output:
3) Histogram
A histogram displays how frequently data falls within specific ranges or “bins.” It’s great for understanding the distribution and spread of continuous numerical data.
You’ll often use histograms to visualize age groups, test scores, or salary ranges. They help spot skewness, outliers, and overall distribution shape quickly.
Syntax:
Plt.hist(x, bins, range, histtype, color, align, orientation, data)
bins = Number of bins.
range = x-label range.
histtype = type of histogram can be given using the parameter. Valid options are bar, barstacked, step, and stepfilled.
align = used to align the graph
orientation = orientation of the graph is given as either horizontal or vertical.
plt.hist("Age",bins=10, histtype="barstacked", color="grey", align="right", orientation="vertical", range=(10,50), data=df)
plt.title("Age vs Estimated Salary")
plt.xlabel("Age")
plt.ylabel("Estimated Salary")
Output:
4) Pie Chart
Pie charts show how a whole is divided into parts using slices of a circle. Each slice represents a category’s proportion of the total, making it visually intuitive.
They work best when you have a limited number of categories and want to highlight dominant ones, such as user location or product share.
Syntax:
plt.pie(x, labels, colors, shadow, startangle, radius, explode)
labels = a list of labels for each wedge.
colors = colors for each wedge.
startangle = can rotate the pie using this parameter.
radius = size of the pie, can be provided.
explode = any wedge can be extruded from the pie.
df = pd.read_csv("Country.csv")
country = ["India","USA","UK","Russia"]
plt.pie(df.Country.value_counts(), labels=country, colors=["blue","green","red","brown"], shadow = True, startangle=45.0, radius=0.75, explode=[0.1,0,0,0] )
plt.legend()
Output:
5) Heatmap
A heatmap uses color gradients to display values across a matrix or grid, making it perfect for comparing variables or showing correlations.
It’s especially useful in data science to find feature relationships, or in performance dashboards to monitor activity levels at a glance.
Syntax:
sns.heatmap(data)
# importing seaborn library
import seaborn as sns
# Dataset
players = ["Virat Kohli", "Rohit Sharma", "Surya Kumar Yadav", "Rishab Pant"]
df = pd.DataFrame({"AUS":[991, 872, 567, 1011], "NZ":[893, 956, 670, 1006], "SA":[343, 541, 297, 444], "WI":[671, 583, 546, 917]}, index=players)
sns.heatmap(df)
plt.title("Runs scored against countries")
plt.xlabel("Country")
plt.ylabel("Player")
Output:
6) Subplot
A subplot allows you to display multiple plots in a single figure by arranging them in a grid. This is especially helpful when comparing different types of visualizations side by side.
It improves analysis by letting you observe multiple relationships or patterns simultaneously, saving space and making comparisons more intuitive for the viewer.
Syntax:
subplot(m,n,p)
plt.subplot(1,2,1)
plt.scatter("Age","Salary",c="c", marker="D", data=df)
plt.annotate("Maximum", ha="right", va="center", xytext=(45,84000), xy=(50,83000), arrowprops={"facecolor":"red"})
plt.legend(loc="lower right", fontsize="x-small", title="Legend", title_fontsize="small")
plt.title("Age vs Estimated Salary")
plt.xlabel("Age")
plt.ylabel("Estimated Salary")
plt.subplot(1,2,2)
plt.plot("Age", "Salary", "^-r", data=df, alpha=1)
plt.annotate("Least", ha="center", va="bottom", xytext=(27,55000), xy=(27,48000), arrowprops={"facecolor":"yellow"})
plt.legend(loc="lower right", fontsize="x-small", title="Legend", title_fontsize="small")
plt.title("Age vs Estimated Salary")
plt.xlabel("Age")
plt.ylabel("Estimated Salary")
Output:
Want to master data visualization and build a career in Data Science? Check out GUVI’s Data Science Course with IIT-M certification which is a beginner-friendly, industry-relevant program with hands-on projects, mentorship, and placement support to help you land your dream role.
Concluding Thoughts…
As we conclude, I’d like to highlight that data visualization is one of the most powerful tools for understanding, explaining, and communicating data. With Python libraries like Matplotlib, you can convert boring spreadsheets into beautiful, informative plots with just a few lines of code.
In today’s data-oriented tech world, learning data visualization will give you an edge. So, go ahead, load that dataset, and start plotting your way to insight! And if you have any doubts, reach out to me in the comments section below.
Did you enjoy this article?