[Tutor] Plotting subsets of data

2014-12-08 Thread Colin Ross
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

xminorLocator=AutoMinorLocator()
yminorLocator=AutoMinorLocator()

# 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)
ax.xaxis.set_minor_locator(xminorLocator)
ax.yaxis.set_minor_locator(yminorLocator)

#Plotting commands.

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

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

show()

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.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Plotting subsets of data

2014-12-08 Thread Danny Yoo
On Mon, Dec 8, 2014 at 7:48 AM, Colin Ross colin.ross@gmail.com wrote:
 Good afternoon,

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

Hi Colin,

Matplotlib is a third-party library, so you may also consider asking
the matplotlib folks.

From a brief look at:


http://matplotlib.org/1.4.2/users/pyplot_tutorial.html#working-with-multiple-figures-and-axes

it appears that you can override the default axis, and specify xmin,
ymin, xmax, and ymax values.

http://matplotlib.org/1.4.2/api/pyplot_api.html#matplotlib.pyplot.axis

For your particular case, you may want to just limit your x axis, in
which case xlim() might be appropriate.

http://matplotlib.org/1.4.2/api/pyplot_api.html#matplotlib.pyplot.xlim


If all else fails, just filter your data before submitting it to the
grapher.  The program loads data here, using loadtxt
(http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html):

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

and it's just a numpy array: you can manipulate numpy arrays.   See:

http://stackoverflow.com/questions/26154711/filter-rows-of-a-numpy-array

as an example of an approach.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Plotting subsets of data

2014-12-08 Thread Colin Ross
Perfect, thank you Danny!

On Mon, Dec 8, 2014 at 3:49 PM, Danny Yoo d...@hashcollision.org wrote:

 On Mon, Dec 8, 2014 at 7:48 AM, Colin Ross colin.ross@gmail.com
 wrote:
  Good afternoon,
 
  I am using the following to code to plot the output from an optical
 encoder:

 Hi Colin,

 Matplotlib is a third-party library, so you may also consider asking
 the matplotlib folks.

 From a brief look at:


 http://matplotlib.org/1.4.2/users/pyplot_tutorial.html#working-with-multiple-figures-and-axes

 it appears that you can override the default axis, and specify xmin,
 ymin, xmax, and ymax values.

 http://matplotlib.org/1.4.2/api/pyplot_api.html#matplotlib.pyplot.axis

 For your particular case, you may want to just limit your x axis, in
 which case xlim() might be appropriate.

 http://matplotlib.org/1.4.2/api/pyplot_api.html#matplotlib.pyplot.xlim


 If all else fails, just filter your data before submitting it to the
 grapher.  The program loads data here, using loadtxt
 (http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html):

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

 and it's just a numpy array: you can manipulate numpy arrays.   See:


 http://stackoverflow.com/questions/26154711/filter-rows-of-a-numpy-array

 as an example of an approach.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor