Ejemplo n.º 1
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()
Ejemplo n.º 2
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()
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
def showErrorBars(population, sizes, numTrials):
    xVals = []
    sizeMeans, sizeSDs = [], []
    for sampleSize in sizes:
        xVals.append(sampleSize)
        trialMeans = []
        for t in range(numTrials):
            sample = random.sample(population, sampleSize)
            popMean, sampleMean, popSD, sampleSD =\
               getMeansAndSDs(population, sample)
            trialMeans.append(sampleMean)
        sizeMeans.append(sum(trialMeans)/len(trialMeans))
        sizeSDs.append(numpy.std(trialMeans))
    print(sizeSDs)
    numpy.errorbar(xVals, sizeMeans,
                   yerr = 1.96*numpy.array(sizeSDs), fmt = 'o',
                   label = '95% Confidence Interval')
    numpy.title('Mean Temperature ('
                + str(numTrials) + ' trials)')
    numpy.xlabel('Sample Size')
    numpy.ylabel('Mean')
    numpy.axhline(y = popMean, color ='r', label = 'Population Mean')
    numpy.xlim(0, sizes[-1] + 10)
    numpy.legend()
Ejemplo n.º 7
0
def labelPlot():
    numpy.title('Measured Displacement of Spring')
    numpy.xlabel('|Force| (Newtons)')
    numpy.ylabel('Distance (meters)')
Ejemplo n.º 8
0
            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])
    return trainX, trainY, testX, testY
Ejemplo n.º 9
0
def makeHist(data, title, xlabel, ylabel, bins = 20):
    numpy.hist(data, bins = bins)
    numpy.title(title)
    numpy.xlabel(xlabel)
    numpy.ylabel(ylabel)
Ejemplo n.º 10
0
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()
    makeHist(normal, 'Gaussian', 'Value', 'Frequency')
    numpy.figure()
    numpy.show()