[Tutor] Plotting subsets of data

Colin Ross colin.ross.dal at gmail.com
Mon Dec 8 16:48:41 CET 2014

Good afternoon,

I am using the following to code to plot the output from an optical encoder:

import numpy as np
from numpy import ma, logical_or
import pylab
from pylab import *
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator
import sys

# Defining x and y minorlocator


# Load data from .txt file

data = np.loadtxt('2014_12_04-16_30_03.txt',skiprows = 0 ,usecols = (0,1))

print "\n Chopper Test for X-SPEC Prototype"
print "\n  Time (sec)     Pos (deg)"
print data

# Place column data in array to be plotted

time = np.array(data[:,0])
print "Time (sec):"
#print time

pos = np.array(data[:,1])
print "Position (deg):"
print pos

# Setting minor ticks

ax = plt.subplot(111)

#Plotting commands.

plot(time, pos, 'ro')
title('Encoder Output')
ylabel('Pos (deg)')

plot(t_small, pos, 'ro')
xlabel('Time (sec)')
ylabel('Pos (deg)')


The desired result is a square wave, but this is not readily available from
the plot (see attached). For the subplot(2,1,2) I would like to plot the
output over a 5 second interval so that the behaviour becomes more evident.
Can someone please advise me as to the easiest way isolate the first 5
seconds of data?

Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141208/644cb8e1/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: encoder_output.png
Type: image/png
Size: 49710 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20141208/644cb8e1/attachment-0001.png>

More information about the Tutor mailing list