Python 使用 Pandas 和 Matplotlib 绘制 Excel 数据散点图
以下是使用 Python 读取 Excel 两列数据并绘制散点图的示例代码:
import pandas as pd
import matplotlib.pyplot as plt
# 读取 Excel 文件
df = pd.read_excel('data.xlsx')
# 提取需要绘制的两列数据
x = df['Column1']
y = df['Column2']
# 绘制散点图
plt.scatter(x, y)
# 显示图形
plt.show()
在上面的代码中,我们首先使用 pandas 库的 read_excel() 函数读取 Excel 文件中的数据。然后,我们使用 'Column1' 和 'Column2' 两列数据来绘制散点图。最后,使用 matplotlib 库的 scatter() 函数和 show() 函数来显示图形。
原文地址: https://www.cveoy.top/t/topic/f0bW 著作权归作者所有。请勿转载和采集!