Fundamentals 7 min read

Generating Ten Types of Charts from Excel Data Using Python, Pandas, and Matplotlib

This tutorial explains how to install Python, Pandas, and Matplotlib, prepare an Excel file, and then create ten different chart types—including bar, scatter, pie, line, box, area, heatmap, polar, contour, and 3D charts—using concise code examples to visualize data effectively.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Generating Ten Types of Charts from Excel Data Using Python, Pandas, and Matplotlib

Hello everyone! In this article I will introduce how to use Python and common libraries to generate ten different types of charts from Excel data, enabling multidimensional visualization to better understand patterns, trends, and relationships.

1. Preparation

First, install the required software and libraries.

Python: Ensure Python is installed and added to the system PATH.
Pandas: pip install pandas
Matplotlib: pip install matplotlib

2. Data Preparation

Prepare an Excel file (e.g., data.xlsx ) containing columns such as Age, Gender, City Distribution, Purchase Quantity, and Repurchase Rate. Example rows:

Age    Gender    City    PurchaseQty    RepurchaseRate
25    Male      Beijing   10            0.6
30    Female    Shanghai  15            0.8
35    Male      Guangzhou 20            0.7
40    Female    Shenzhen  12            0.5

3. Creating Charts

a. Bar Chart – compares categories.

import pandas as pd
import matplotlib.pyplot as plt
# Read Excel data
df = pd.read_excel('data.xlsx')
# Create bar chart
plt.bar(df['年龄'], df['购买数量'])
plt.title('购买数量按年龄分布')
plt.xlabel('年龄')
plt.ylabel('购买数量')
plt.show()

b. Scatter Plot – shows relationship between two variables.

plt.scatter(df['年龄'], df['复购率'])
plt.title('复购率与年龄的关系')
plt.xlabel('年龄')
plt.ylabel('复购率')
plt.show()

c. Pie Chart – displays proportion of categories.

plt.pie(df['购买数量'], labels=df['城市分布'], autopct='%1.1f%%')
plt.title('购买数量城市分布')
plt.show()

d. Line Chart – shows trends over a dimension.

plt.plot(df['年龄'], df['购买数量'], marker='o')
plt.title('购买数量随年龄的变化')
plt.xlabel('年龄')
plt.ylabel('购买数量')
plt.show()

e. Box Plot – visualizes distribution, median, quartiles, outliers.

plt.boxplot(df['购买数量'])
plt.title('购买数量分布')
plt.ylabel('购买数量')
plt.show()

f. Area Chart – shows cumulative values over a dimension.

plt.stackplot(df['年龄'], df['购买数量'], df['复购率'], labels=['购买数量', '复购率'])
plt.title('购买数量和复购率随年龄的变化')
plt.xlabel('年龄')
plt.ylabel('数量')
plt.legend()
plt.show()

g. Heatmap – visualizes correlation between variables using color.

import seaborn as sns
sns.heatmap(df[['购买数量', '复购率']].corr(), annot=True)
plt.title('购买数量和复购率的相关性')
plt.show()

h. Polar Chart – represents data in radial coordinates.

plt.polar(df['年龄'], df['购买数量'])
plt.title('购买数量的极坐标表示')
plt.show()

i. Contour Plot – displays contour lines for 2‑D data.

plt.contour(df['购买数量'])
plt.title('购买数量的等高线图')
plt.show()

j. 3D Chart – visualizes three‑dimensional relationships.

from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(df['年龄'], df['购买数量'], df['复购率'])
ax.set_title('购买数量、复购率与年龄的关系')
ax.set_xlabel('年龄')
ax.set_ylabel('购买数量')
ax.set_zlabel('复购率')
plt.show()

4. Summary

By using Python's Pandas and Matplotlib libraries, we can easily create ten different chart types from Excel data—bar, scatter, pie, line, box, area, heatmap, polar, contour, and 3D charts—helping us gain deeper insights, discover patterns, and communicate information more effectively.

data-visualizationexcelMatplotlibpandasCharting
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.