Read text file and plot by using Pandas and matplotlib.pyplot in Python

Here is a sample code.

import pandas as pd
import matplotlib.pyplot as plt


filename = 'a.txt'

data = pd.read_csv(filename, sep='\t', header=None)
plt.plot(data[0],data[1])
plt.xlabel('Raman shift (cm-1)', size=14)
plt.ylabel('Intensity', size=14)
plt.xlim(1000,3000)
plt.savefig('Raman.png', transparent=True)
plt.show()


This is the link on details of read_csv of pandas. (https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html)

This is the link on details of matplotlib.pyplot. (https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html)

Thanks,

JF

댓글