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

您所在的位置:网站首页 dataframe读取excel的图片 Python读取excel表格并通过折线图可视化显示

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

2024-06-23 03:40| 来源: 网络整理| 查看: 265

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()


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3