Ejemplo n.º 1
0
 def bandPowerHistogram(cls, df, figure):
     figure.canvas.flush_events()
     ax = figure.add_subplot(111)
     ax.clear()
     ax.plot(df)
     ax.set_title('Band Power (dB)')
     ax.set_ylim([0, 80])
     figure.canvas.draw()
     plt.pause(0.001)
     plt.show()
Ejemplo n.º 2
0
 def draw_graph(self, country, lastdays):
     api = basic.Retriever()
     dates, cases = basic.Retriever.get_sinceDayone(api, country)
     lastdays = -1 * lastdays
     dates = dates[lastdays:]
     cases = cases[lastdays:]
     plt.figure(figsize=(1, 1))
     data = {'Dates': dates, 'Cases': cases}
     df = DataFrame(data, columns=['Dates', 'Cases'])
     figure = plt.Figure(figsize=(6, 6), dpi=70)
     ax = figure.add_subplot(111)
     chart_type = FigureCanvasTkAgg(figure, root)
     chart_type.get_tk_widget().grid(row=6, column=0, padx=0, pady=0)
     df = df[['Dates', 'Cases']].groupby('Dates').sum()
     df.plot(kind='line', legend=True, ax=ax)
     ax.set_title('Cases in the last %s days in %s' % (-lastdays, country))
Ejemplo n.º 3
0
    def plotRawEEG(self, figure=None, chunk=None, offset=200, plotTitle='eeg'):
        """
        this version spits out a figure window for use in the UI
        :param title: title of the figure
        :param offset: DC offset between eeg channels
        :return: plot with all 14 eeg channels
        """
        if chunk is None:
            chunk = self.chunk
        # define time axis
        tAxis = np.arange(0, len(chunk))  # create time axis w same length as the data matrix
        tAxis = tAxis / self.sampleRate  # adjust time axis to 256 sample rate

        # use eeg matrix as y axis
        yAxis = chunk + offset * (self.nchannels-1)

        # add offset to display all channels
        for i in range(0, len(chunk[0, :])):
            yAxis[:, i] -= offset * i

        # plot figure
        if figure is None:
            figure = Figure()

        figure.canvas.flush_events()
        ax = figure.add_subplot(111)
        ax.clear()
        ax.set_title(plotTitle)
        ax.set_ylim(-300, offset * 20)
        ax.legend(self.eegChannels)
        ax.set_xlabel('time')
        ax.plot(tAxis, yAxis)
        figure.canvas.draw()
        plt.pause(0.001)

        return figure
    parser = ArgumentParser(description="generate random coordinates for the lighthouse problem and find the original a,b parameters by using the Metropolis(-Hastings) algorithm")
    parser.add_argument('-a', dest='a', metavar='x', action='store', type=float, default=-0.5, help="x-coordinate of the lighthouse (default: %(default)s)")
    parser.add_argument('-b', dest='b', metavar='y', action='store', type=float, default=0.7, help="y-coordinate of the lighthouse (default: %(default)s)")
    parser.add_argument('-s', '--samples', metavar='N', dest='samples', action='store', type=int, default=100, help="the number of measurement samples to generate (default: %(default)s)")
    parser.add_argument('-m', '--minsteps', metavar='N', dest='minsteps', action='store', type=int, default=100, help="the minimal number of steps in each of the random-walks in the Metropolis algorithm (default: %(default)s)")
    parser.add_argument('-w', '--walks', metavar='N', dest='walks', action='store', type=int, default=100, help="the number of random walks in the Metropolis algorithm (default: %(default)s)")
    args = parser.parse_args()

    # generate random x
    x = randomX(args.a, args.b, args.samples)

    ab_s = map(lambda ab: metropolisWalk(x, ab, args.minsteps), [1j]*args.walks)

    from matplotlib.pyplot import hist, show, figure

    figure = figure()
    subp = figure.add_subplot(311)
    subp.hist(x, histtype='step', bins=40)
    subp.set_xlabel("simulated measurements")
    subp = figure.add_subplot(312)
    subp.hist(real(ab_s), histtype='step', bins=40)
    subp.axvline(x=args.a, color='g', linewidth=2)
    subp.set_xlabel("recovered x-coordinate of the lighthouse")
    subp = figure.add_subplot(313) 
    subp.hist(imag(ab_s), histtype='step', bins=40)
    subp.axvline(x=args.b, color='g', linewidth=2)
    subp.set_xlabel("recovered y-coordinate of the lighthouse")

    show()


def friedman_func(y, a, omega):
    return [-1 / sqrt(omega / a + (1 - omega) * a ** 2), y[0] / a]


if __name__ == "__main__":
    from argparse import ArgumentParser

    parser = ArgumentParser(description="integrate and plot the Friedman equations")
    parser.add_argument(
        "-o", "--omega", dest="omega", action="store", type=float, default=1.0, help="the omega parameter"
    )
    parser.add_argument("-t", "--time", dest="time", action="store", type=float, default=1.0, help="initial time")
    parser.add_argument("-r", "--radius", dest="radius", action="store", type=float, default=1.0, help="initial radius")
    args = parser.parse_args()

    from scipy import arange
    from scipy.integrate import odeint
    from matplotlib.pyplot import plot, show, figure

    a = arange(0.1, 1.0, 0.001)
    y = odeint(friedman_func, [args.time, args.radius], a, (args.omega,))

    figure = figure()
    subp = figure.add_subplot(2, 1, 1)
    subp.plot(a, y[:, 0])
    subp = figure.add_subplot(2, 1, 2)
    subp.plot(a, y[:, 1])
    show()
Ejemplo n.º 6
0
    pred_error = pred - y
    pred_z_error = np.multiply(pred, (1 - pred))
    squarebracket = np.multiply(pred_error, pred_z_error)

    dW = np.zeros(W.shape)
    # Gradient of MSE with respect to W
    for i in range(x.shape[0]):
        dW = np.add(dW, np.outer(squarebracket[i], x[i]))

    dw_0 = np.sum(squarebracket, axis=0)

    return ((W - alpha * dW), (w_0 - alpha * dw_0))


figure = plt.figure()
axis = figure.add_subplot(1, 1, 1)

# Arrays for storing plot values
plot_iteration = []
train_errors = []
test_errors = []

error_rate = 1


def get_error_rate(x, y, W, w_0):
    pred = prediction(x, W, w_0)

    mistakes = 0

    for i in range(pred.shape[0]):
Ejemplo n.º 7
0
bottomframe = Frame(window) 
bottomframe.grid( row=6, column=1 ) 

displayframe = Frame(window)
displayframe.grid( row = 11, column= 1)

tkvar = StringVar(window)
choices = Locations
tkvar.set("United States")

popupMenu = OptionMenu(bottomframe, tkvar, *choices)
popupMenu.grid(row = 1,column=2)
popupMenu.configure(width=25, bg = "LightSalmon2")

figure = plt.Figure(figsize=(8,7), dpi=100)
ax1 = figure.add_subplot(111)
chart_type = FigureCanvasTkAgg(figure, frame)
chart_type.get_tk_widget().grid(row=3, column = 1)
df1 = data[['Location','Cases per 1 million people']].groupby('Location').sum()
df1.plot(kind='barh', legend=True, ax=ax1, fontsize = 7, color = "red")
ax1.set_title('Cases Per Million People')

 
figure = plt.Figure(figsize=(8,7), dpi=100)
ax2 = figure.add_subplot(111)
chart_type = FigureCanvasTkAgg(figure, frame)
chart_type.get_tk_widget().grid(row=3, column = 3)
df2 = data[['Location','Confirmed']].groupby('Location').sum()
df2.plot(kind='bar', legend=True, ax=ax2, fontsize = 6)
ax2.set_title('Confirmed Cases')