Python Forum

Full Version: User input numpy array with color mapping & mouse click events
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Members!

I am new to the forum and looking for some help with a project related coding question.

I am tasked with making a 2d numpy array which would be based on the user inputing the number of rows and columns. Once the array is made, random values are to be inserted into them which would then be normalized between 0 & 1. To this I am supposed to add color mapping as well as a mouse click event counter which would select one column when the mouse button is pressed and highlight it as "HIGH" and display it in red while other cells remain in other colours except red.

Looking at some online resources this looks like a slider window problem to me but being a newbie I am not exactly sure how to do that here.

My code so far is as follows:


## Sliding window iterator over a 2d mxn array with a color grid
## Added mouse click events


### import all necessary modules
import time
import numpy as np
from itertools import islice
from pylab import arange, cm, draw, rand
from matplotlib import pylab as plt
from time import sleep
from numpy import random
import random

## program start
plt.ion()


# user input variables
numOfSignals = int(input("Enter Number of Signals (Rows): "))
numOfSamples = int(input("Enter Number of Samples (Columns): "))
#RunTime = int(input("Enter Desired Time: "))

start_time = time.time()

## initialize the 2d array

def user_matrix():
    matrix = []; columns = []
    for i in range(0,numOfSignals):
        matrix.append([])
        for j in range(0,numOfSamples):
            matrix[i].append(0)

    data = rand(numOfSignals*200)
    data = data.reshape(numOfSignals,200)
    return data

    ## random value input for matrix
        ## display matrix with random value

    ## Randomise betn 0 & 1

    ## add color mapping to this matrix
        ## return color mapped matrix

    ## add time variable and get the matrix to run for user input time
        ## return the color mapped moving matrix

#def user_event():

    ## mouseclick event
        ## show event register

    ## integrate mouseclick with rolling array from above

    ## show mouseclick as a high event or red

    




print("--- %s seconds ---" %(time.time() - start_time))