plotting a range of data that satisfies conditions in another column in matplotlib python
Question: I'm new to python. I have an array with four columns. I want to plot columns 2
and 3, pending that column 1 satisfies a condition. If column 1 does not
satisfy this range, it is plotted in the next subplot. I have seen that using
the where function can do this - just not sure exactly how to go about it.

For example:

    
    
    import numpy as np
    import scipy as sp
    import matplotlib.pyplot as plt
    
    data = np.array([[17., 18., 19., 20., 31., 46.],\
    [1.52,2.5,2.55,2.56,2.53,2.54],\
    [7.04,7.06,9.05,11.08,7.06,11.06],\
    [0.,0.,0.,0.,4.,4.]])
    

First round and replace the second column:

    
    
    dataRound = sp.round_(data,1)
    data[:,1] = dataRound[:,1]
    

Then locate/plot the two different conditions:

    
    
    if np.where(data[i]==1.5):
        subplot(211)
        plt.scatter(data[:,1],data[:,2])
    elif np.where(data[i] ==2.5):
        subplot(212)
        plt.scatter(data[:,1], data[:,2])
    


Answer: Here is a code snippet that answers your question:

    
    
    t=linspace(0,1000, 1000)
    y=sin(0.1*t)
    ii=find(t>100)
    plot(t[ii],y[ii])
    

Basically with `find` you generate a list of indexes that satisfy the logical
condition (t>100) and then use this list.

p.s. put np. and plt. where needed

Update:

Is this what you need? Note, you have to exchange [1,:] instead of [:,1].
Advice - print out what you are doing to be sure.

    
    
    import numpy as np
    import scipy as sp
    import matplotlib.pyplot as plt
    
    data = np.array([[17., 18., 19., 20., 31., 46.],\
    [1.52,2.5,2.55,2.56,2.53,2.54],\
    [7.04,7.06,9.05,11.08,7.06,11.06],\
    [0.,0.,0.,0.,4.,4.]])
    
    dataRound = sp.round_(data,1)
    data[1,:] = dataRound[1,:]
    ax1=plt.subplot(211)
    ax2=subplot(212)
    
    ax1.scatter(data[1,data[1,:]<=1.5], data[2,data[1,:]<=1.5], color = 'g')
    ax2.scatter(data[1,data[1,:]>=2.5], data[2,data[1,:]>=2.5], color = 'b')
    

if you want to plot 2rd and 3rd column, then:

    
    
    ax1.scatter(data[2,data[1,:]<=1.5], data[3,data[1,:]<=1.5], color = 'g')
    ax2.scatter(data[2,data[1,:]>=2.5], data[3,data[1,:]>=2.5], color = 'b')
    

