admin管理员组

文章数量:1609530

Python读取excel表格并通过折线图可视化显示

本文是通过pandas和matplotlib模块实现可视化的。如有不足请指正。
excel表格为


第一步
导入模块:

import pandas as pd
import matplotlib.pyplot as plt

第二步
使用pandas读取excel文件:

df = pd.read_excel("C:\\Users\\ASUS\\Desktop\\test.xlsx")

然后我们print读取的数据看一下

print(df)

结果如下:
导出money1这一列的数据:

print(df["money1"])


第三步:
plt显示:
横坐标为df[“time”],纵坐标1为df[“money1”],纵坐标2为df[“money2”],markerfacecolor='blue’为填充的颜色

plt.plot(df["time"],df["money1"],label='money1',linewidth=3,color='r',marker='o',
markerfacecolor='blue',markersize=12)
plt.plot(df["time"],df["money2"],label='money2',linewidth=3,color='y',marker='o',
markerfacecolor='blue',markersize=12)

标题显示

plt.xlabel("time")
plt.ylabel('money')
plt.title("summy of input")
plt.legend()
plt.grid()
plt.show()

折线图如下:

完整代码:

import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel("C:\\Users\\ASUS\\Desktop\\test.xlsx")
print(df)
print(df["money1"])

plt.plot(df["time"],df["money1"],label='money1',linewidth=3,color='r',marker='o',
markerfacecolor='blue',markersize=12)
plt.plot(df["time"],df["money2"],label='money2',linewidth=3,color='y',marker='o',
markerfacecolor='blue',markersize=12)
plt.xlabel("time")
plt.ylabel('money')
plt.title("summy of input")
plt.legend()
plt.grid()
plt.show()

本文标签: 表格折线图PythonExcel