Exemple #1
0
def plotData(fileName):
    xVals, yVals = getData(fileName)
    xVals = numpy.array(xVals)
    yVals = numpy.array(yVals)
    xVals = xVals * 9.81  #acc. due to gravity
    numpy.plot(xVals, yVals, 'bo', label='Measured displacements')
    labelPlot()
Exemple #2
0
def plotDiffs(sampleSizes, diffs, title, label, color = 'b'):
    numpy.plot(sampleSizes, diffs, label = label,
               color = color)
    numpy.xlabel('Sample Size')
    numpy.ylabel('% Difference in SD')
    numpy.title(title)
    numpy.legend()
Exemple #3
0
def testFits(models, degrees, xVals, yVals, title):
    numpy.plot(xVals, yVals, 'o', label='Data')
    for i in range(len(models)):
        estYVals = numpy.polyval(models[i], xVals)
        error = rSquared(yVals, estYVals)
        numpy.plot(xVals, estYVals,
                   label = 'Fit of degree '\
                   + str(degrees[i])\
                   + ', R2 = ' + str(round(error, 5)))
    numpy.legend(loc='best')
    numpy.title(title)
Exemple #4
0
def fitData1(fileName):
    xVals, yVals = getData(fileName)
    xVals = numpy.array(xVals)
    yVals = numpy.array(yVals)
    xVals = xVals * 9.81  #get force
    numpy.plot(xVals, yVals, 'bo', label='Measured points')
    labelPlot()
    model = numpy.polyfit(xVals, yVals, 1)
    estYVals = numpy.polyval(model, xVals)
    numpy.plot(xVals,
               estYVals,
               'r',
               label='Linear fit, k = ' + str(round(1 / model[0], 5)))
    numpy.legend(loc='best')
Exemple #5
0
def fitData(fileName):
    xVals, yVals = getData(fileName)
    xVals = numpy.array(xVals)
    yVals = numpy.array(yVals)
    xVals = xVals * 9.81  #get force
    numpy.plot(xVals, yVals, 'bo', label='Measured points')
    labelPlot()
    a, b = numpy.polyfit(xVals, yVals, 1)
    estYVals = a * numpy.array(xVals) + b
    print('a =', a, 'b =', b)
    numpy.plot(xVals,
               estYVals,
               'r',
               label='Linear fit, k = ' + str(round(1 / a, 5)))
    numpy.legend(loc='best')
Exemple #6
0
def make_one_curve_plot(x_coords, y_coords, x_label, y_label, title):
    """
    Makes a plot of the x coordinates and the y coordinates with the labels
    and title provided.

    Args:
        x_coords (list of floats): x coordinates to graph
        y_coords (list of floats): y coordinates to graph
        x_label (str): label for the x-axis
        y_label (str): label for the y-axis
        title (str): title for the graph
    """
    pl.figure()
    pl.plot(x_coords, y_coords)
    pl.xlabel(x_label)
    pl.ylabel(y_label)
    pl.title(title)
    pl.show()
Exemple #7
0
def show_plot_compare_strategies(title, x_label, y_label):
    """
    Produces a plot comparing the two robot strategies in a 20x20 room with 80%
    minimum coverage.
    """
    num_robot_range = range(1, 11)
    times1 = []
    times2 = []
    for num_robots in num_robot_range:
        print("Plotting", num_robots, "robots...")
        times1.append(
            run_simulation(num_robots, 1.0, 1, 20, 20, 3, 0.8, 20,
                           StandardRobot))
        times2.append(
            run_simulation(num_robots, 1.0, 1, 20, 20, 3, 0.8, 20,
                           FaultyRobot))
    numpy.plot(num_robot_range, times1)
    numpy.plot(num_robot_range, times2)
    numpy.title(title)
    numpy.legend(('StandardRobot', 'FaultyRobot'))
    numpy.xlabel(x_label)
    numpy.ylabel(y_label)
    numpy.show()
Exemple #8
0
def show_plot_room_shape(title, x_label, y_label):
    """
    Produces a plot showing dependence of cleaning time on room shape.
    """
    aspect_ratios = []
    times1 = []
    times2 = []
    for width in [10, 20, 25, 50]:
        height = 300 / width
        print("Plotting cleaning time for a room of width:", width,
              "by height:", height)
        aspect_ratios.append(float(width) / height)
        times1.append(
            run_simulation(2, 1.0, 1, width, height, 3, 0.8, 200,
                           StandardRobot))
        times2.append(
            run_simulation(2, 1.0, 1, width, height, 3, 0.8, 200, FaultyRobot))
    numpy.plot(aspect_ratios, times1)
    numpy.plot(aspect_ratios, times2)
    numpy.title(title)
    numpy.legend(('StandardRobot', 'FaultyRobot'))
    numpy.xlabel(x_label)
    numpy.ylabel(y_label)
    numpy.show()
Exemple #9
0
def make_two_curve_plot(x_coords, y_coords1, y_coords2, y_name1, y_name2,
                        x_label, y_label, title):
    """
    Makes a plot with two curves on it, based on the x coordinates with each of
    the set of y coordinates provided.

    Args:
        x_coords (list of floats): the x coordinates to graph
        y_coords1 (list of floats): the first set of y coordinates to graph
        y_coords2 (list of floats): the second set of y-coordinates to graph
        y_name1 (str): name describing the first y-coordinates line
        y_name2 (str): name describing the second y-coordinates line
        x_label (str): label for the x-axis
        y_label (str): label for the y-axis
        title (str): the title of the graph
    """
    pl.figure()
    pl.plot(x_coords, y_coords1, label=y_name1)
    pl.plot(x_coords, y_coords2, label=y_name2)
    pl.legend()
    pl.xlabel(x_label)
    pl.ylabel(y_label)
    pl.title(title)
    pl.show()
Exemple #10
0
def fitData(fileName):
    xVals, yVals = getData(fileName)
    xVals = numpy.array(xVals)
    yVals = numpy.array(yVals)
    xVals = xVals*9.81 #get force
    numpy.plot(xVals, yVals, 'bo',
               label = 'Measured points')                 
    model = numpy.polyfit(xVals, yVals, 1)
    xVals = xVals + [2]
    yVals = yVals + []
    estYVals = numpy.polyval(model, xVals)
    numpy.plot(xVals, estYVals, 'r',
               label = 'Linear fit, r**2 = '
               + str(round(rSquared(yVals, estYVals), 5)))                
    model = numpy.polyfit(xVals, yVals, 2)
    estYVals = numpy.polyval(model, xVals)
    numpy.plot(xVals, estYVals, 'g--',
               label = 'Quadratic fit, r**2 = '
               + str(round(rSquared(yVals, estYVals), 5)))
    numpy.title('A Linear Spring')
    labelPlot()
    numpy.legend(loc = 'best')
Exemple #11
0
    for d in data:
        try:
            years[d.getYear()].append(d.getHigh())
        except:
            years[d.getYear()] = [d.getHigh()]
    for y in years:
        years[y] = sum(years[y])/len(years[y])
    return years
    
data = getTempData()
years = getYearlyMeans(data)
xVals, yVals = [], []
for e in years:
    xVals.append(e)
    yVals.append(years[e])
numpy.plot(xVals, yVals)
numpy.xlabel('Year')
numpy.ylabel('Mean Daily High (C)')
numpy.title('Select U.S. Cities')

def splitData(xVals, yVals):
    toTrain = random.sample(range(len(xVals)),
                            len(xVals)//2)
    trainX, trainY, testX, testY = [],[],[],[]
    for i in range(len(xVals)):
        if i in toTrain:
            trainX.append(xVals[i])
            trainY.append(yVals[i])
        else:
            testX.append(xVals[i])
            testY.append(yVals[i])
Exemple #12
0
    return popSD/sampleSize**0.5

sampleSizes = (25, 50, 100, 200, 300, 400, 500, 600)
numTrials = 50
population = getHighs()
popSD = numpy.std(population)
sems = []
sampleSDs = []
for size in sampleSizes:
   sems.append(sem(popSD, size))
   means = []
   for t in range(numTrials):
       sample = random.sample(population, size)
       means.append(sum(sample)/len(sample))
   sampleSDs.append(numpy.std(means))
numpy.plot(sampleSizes, sampleSDs,
          label = 'Std of ' + str(numTrials) + ' means')
numpy.plot(sampleSizes, sems, 'r--', label = 'SEM')
numpy.xlabel('Sample Size')
numpy.ylabel('Std and SEM')
numpy.title('SD for ' + str(numTrials) + ' Means and SEM')
numpy.legend()


def plotDistributions():
    uniform, normal, exp = [], [], []
    for i in range(100000):
        uniform.append(random.random())
        normal.append(random.gauss(0, 1))
        exp.append(random.expovariate(0.5))
    makeHist(uniform, 'Uniform', 'Value', 'Frequency')
    numpy.figure()