python - Python显示excel值图
问题描述
我正在使用此代码->
import xlrd
import matplotlib.pylab as plt
loc = ("file path")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)
for i in range(sheet.nrows):
x = sheet.cell_value(i, 0)
y = sheet.cell_value(i, 1)
print(x, y)
plt.bar(x, y)
plt.xticks(rotation=50, horizontalalignment='right', weight='bold', size='large')
plt.xlabel('Date', weight='bold', size='large')
plt.ylabel('Total Bad Ports', weight='bold', size='large')
plt.show()
从两列 .xls 文件中读取数据并使用其数据显示绘图。我有一个包含两个错误的图表。1. y 轴不显示数值。2. 尝试显示折线图时,我的绘图为空。该图使用 plot.bar 或 plt.plot(x, y, 'ro') 成功(没有 y 轴值)。
*数据形式为
2020 01 28 1900 875
2020 01 29 0700 844
2020 01 29 1300 580
2020 01 29 1900 587
2020 01 30 0700 589
2020 01 30 1300 582
(列 1->2020 01 30 1900、2020 01 29 0700 等和列 2->875、844 等)
提前致谢:)
解决方案
愚蠢的 1. 问题已解决。.xls 文件中有一个空的起始行,显然不允许正确显示 y 轴值。
尽管我有一个足够好的 plt.bar 图,但我仍然无法使用 plt.plot 命令绘制折线图。任何提示表示赞赏:)
推荐阅读
- c# - 图像未出现在 Winforms 用户控件设计器中
- ruby-on-rails - FactoryGirl 关联 ID 为 nil
- web - 新的 Gmail 用户界面是使用哪种前端编程语言构建的?
- java - Springboot嵌入式mongo测试
- neo4j - Neo4j - 查询分析器 - 了解一些事情
- spring - 在 Spring Data JPA 中加入多个表的查询
- python - 在 python 中使用 selenium 打开 Firefox
- java - 在 MainActivity 中未使用 getResources().openRawResource 时出错
- machine-learning - 一个简单的神经网络可以学习应用于四个数字总和的 sin 函数吗?
- python - 解决数组任务python