2

The code I have to read and plot data from my excel file is this:

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

It works.

The questions are:

  1. I have more columns, but when I want to add y3, y4,... I get the error that y3 is undefined.

  2. In legend I want to change the name of y1 to CK4/5-PCA82500 and others as well. Is there any way to do it?

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you @gen. It worked. Do you if alo I can change the name of my legends in the figure?
You just need to change/add "label" in plt.plot() like I did in second row of codes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.