【问题标题】:Plot data from Excel in Python在 Python 中绘制 Excel 中的数据
【发布时间】:2019-10-08 04:29:57
【问题描述】:

我必须从我的 excel 文件中读取和绘制数据的代码是这样的:

import pandas as pd
import matplotlib.pyplot as plt
excel_file = 'file1.xlsx'
file1 = pd.read_excel(excel_file)

file1.head()

plt.plot(x,y1,y2)

plt.xlabel('wavelenghts')
plt.ylabel('reflectivity')
plt.legend(loc='upper left')
plt.show

有效。

问题是:

  1. 我有更多列,但是当我想添加y3, y4,... 时,我收到y3 is undefined. 的错误

  2. 在传说中,我想将y1 的名称更改为CK4/5-PCA82500 以及其他名称。有什么办法吗?

【问题讨论】:

    标签: excel pandas matplotlib


    【解决方案1】:
    f, ax = figure()
    plt.plot(file1.x,file1.y1,label='')
    plt.plot(file1.x,file1.y2)
    plt.plot(file1.x,file1.y3)
    .....
    
    plt.xlabel('wavelenghts')
    plt.ylabel('reflectivity')
    plt.legend(loc='upper left')
    plt.show
    

    【讨论】:

    • 谢谢@gen。有效。如果我能改变我在图中的传说的名称,你能做到吗?
    • 您只需要像我在第二行代码中所做的那样在 plt.plot() 中更改/添加“标签”
    猜你喜欢
    • 2017-12-12
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多