As a Python developer with over a decade of experience, I have found that visualizing data is one of the most powerful ways to understand and communicate insights. In this article, I’ll share practical methods to plot NumPy arrays with Matplotlib.
I’ll walk you through different types of plots, from simple line graphs to more advanced visualizations, all with clear examples you can apply to real-world-centric data.
Let’s get started!
Get Started: Basic Line Plot from a NumPy Array
The easiest way to start plotting is by creating a simple line plot. Imagine you want to visualize the monthly sales growth of a retail store in New York over a year.
import numpy as np
import matplotlib.pyplot as plt
# Monthly sales data (in thousands of dollars)
sales = np.array([23, 25, 27, 30, 35, 40, 38, 36, 34, 33, 31, 29])
# Plotting the sales data
plt.plot(sales)
plt.title('Monthly Sales Growth - New York Retail Store')
plt.xlabel('Month')
plt.ylabel('Sales (in $1000s)')
plt.grid(True)
plt.show()You can see the output in the screenshot below.

This simple plot gives a clear visual of sales trends across the year. Notice how NumPy arrays integrate seamlessly with Matplotlib’s plotting functions.
Plot Multiple NumPy Arrays on the Same Graph
Often, you need to compare data sets. Suppose you want to compare sales between two stores in California and Texas.
# Sales data for two stores
sales_ca = np.array([20, 22, 25, 28, 30, 35, 33, 31, 29, 28, 26, 24])
sales_tx = np.array([18, 20, 23, 27, 32, 37, 36, 34, 33, 31, 29, 27])
months = np.arange(1, 13)
plt.plot(months, sales_ca, label='California Store')
plt.plot(months, sales_tx, label='Texas Store')
plt.title('Monthly Sales Comparison')
plt.xlabel('Month')
plt.ylabel('Sales (in $1000s)')
plt.legend()
plt.grid(True)
plt.show()You can see the output in the screenshot below.

Using multiple arrays and labeling them helps you create informative comparative visualizations.
Check out the Matplotlib Pie Chart Tutorial
Customize Plots: Add Markers and Colors
To enhance readability, I often customize plots by adding markers and colors. Here’s how you can do it:
plt.plot(months, sales_ca, marker='o', color='blue', linestyle='-', label='California Store')
plt.plot(months, sales_tx, marker='s', color='green', linestyle='--', label='Texas Store')
plt.title('Monthly Sales Comparison with Markers')
plt.xlabel('Month')
plt.ylabel('Sales (in $1000s)')
plt.legend()
plt.grid(True)
plt.show()You can see the output in the screenshot below.

This approach makes each data series visually distinct, which is especially helpful in presentations.
Plot 2D NumPy Arrays: Heatmaps for Geographical Data
When working with data like average temperatures across US states, 2D arrays become useful. You can visualize such data using heatmaps.
import numpy as np
import matplotlib.pyplot as plt
# Example: Average temperatures (°F) for 5 US cities over 4 seasons
temps = np.array([
[30, 60, 85, 55], # New York
[45, 70, 95, 65], # Los Angeles
[40, 65, 90, 60], # Chicago
[50, 75, 100, 70], # Houston
[35, 60, 80, 50] # Miami
])
plt.imshow(temps, cmap='hot', interpolation='nearest')
plt.colorbar(label='Temperature (°F)')
plt.xticks(ticks=np.arange(4), labels=['Winter', 'Spring', 'Summer', 'Fall'])
plt.yticks(ticks=np.arange(5), labels=['NY', 'LA', 'Chicago', 'Houston', 'Miami'])
plt.title('Average Seasonal Temperatures in US Cities')
plt.show()Heatmaps are great for spotting trends or anomalies in multivariate data.
Read Matplotlib Update Plot in Loop
Bar Plots from NumPy Arrays
Bar plots are perfect for categorical data comparisons. For example, visualizing the number of electric vehicles sold in the top US states:
states = ['California', 'Texas', 'Florida', 'New York', 'Washington']
ev_sales = np.array([12000, 8000, 5000, 7000, 6500])
plt.bar(states, ev_sales, color='purple')
plt.title('Electric Vehicle Sales by State')
plt.xlabel('State')
plt.ylabel('Number of Vehicles Sold')
plt.show()This plot quickly communicates which states lead in EV adoption.
Scatter Plots for Correlation Analysis
If you want to analyze relationships, scatter plots are handy. For instance, plotting advertising spend vs. sales revenue:
advertising = np.array([1000, 1500, 2000, 2500, 3000])
sales_revenue = np.array([20000, 25000, 30000, 35000, 40000])
plt.scatter(advertising, sales_revenue, color='red')
plt.title('Advertising Spend vs Sales Revenue')
plt.xlabel('Advertising Spend ($)')
plt.ylabel('Sales Revenue ($)')
plt.grid(True)
plt.show()Scatter plots help detect correlations or outliers effectively.
Check out Matplotlib Scatter Plot Color
Save Plots to Files
After creating plots, you may want to save them for reports or presentations.
plt.plot(sales)
plt.title('Monthly Sales Growth')
plt.savefig('monthly_sales_growth.png') # Saves the plot as a PNG file
plt.close()Saving plots programmatically streamlines the workflow, especially when handling multiple datasets.
Plotting NumPy arrays with Matplotlib is a fundamental skill for any Python developer working with data. Whether you’re analyzing sales trends in US markets or visualizing scientific data, the methods I shared will help you create clear and insightful charts.
The beauty of Matplotlib lies in its flexibility; you can start with simple line plots and gradually explore more complex visualizations like heatmaps and scatter plots. Practice these examples with your data, and you’ll find yourself communicating insights more effectively in no time.
You may also like to read other Matplotlib articles:
- Matplotlib Set y Axis Range
- Module ‘matplotlib’ has no attribute ‘artist’
- Matplotlib Time Series Plot

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.