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()
版权声明:本文标题:Python读取excel表格并通过折线图可视化显示 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1728571755a1164272.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论