Quickly Plot in Python with Text File Values

Python has this wonderful command in numpy, np.loadtxt.
In this case, I use np.loadtxt to load a file consisting of several ADC real values to do a quick plot for visualization. The rule is that each row in the text file has to have the same number of elements. In this case it is simply.

and so on...


import matplotlib.pyplot as plt
import numpy as np

data = np.loadtxt('/path/to/your/file')

# get x-axis bins
x_axis = np.arange(data.size) * 960 / data.size

#plot time domain

# plot frequency domain
spc = np.fft.fft(data)
plt.plot(x_axis, 20*np.log10(abs(spc)))

That’s all. Pretty quick and nifty!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s