Пример #1
0
def main():

    x = np.random.normal(0, 50, 50000)
    y = np.random.normal(0, 15, 50000)

    ranges = ([(-100, 0), (-50, 0)],
              [(0, 100), (-50, 0)],
              [(-100, 0), (0, 50)],
              [(0, 100), (0, 50)])
    types = ('reverse_bw', 'color', 'bw', 'area')
    bitmaps = (True, True, False, False)
    subplot_idxs = [(1, 0), (1, 1), (0, 0), (0, 1)]

    plot = Plot()
    mplot = MultiPlot(2, 2, width=r'.4\linewidth')

    for idx, r, t, b in zip(subplot_idxs, ranges, types, bitmaps):
        n, xbins, ybins = np.histogram2d(x, y, bins=15, range=r)
        plot.histogram2d(n, xbins, ybins, type=t, bitmap=b)
        p = mplot.get_subplot_at(*idx)
        p.histogram2d(n, xbins, ybins, type=t, bitmap=b)

    mplot.show_yticklabels_for_all([(1, 0), (0, 1)])
    mplot.show_xticklabels_for_all([(1, 0), (0, 1)])

    plot.save('histogram2d')
    mplot.save('multi_histogram2d')
Пример #2
0
def main():
    # data series
    x = [0, 40, 60, 69, 80, 90, 100]
    y = [0, 0, 0.5, 2.96, 2, 1, .5]

    # make graph
    graph = Plot()

    # make Plot
    graph.plot(x, y, mark=None, linestyle='smooth,very thick')

    # set labels and limits
    graph.set_xlabel(r"$f [\si{\mega\hertz}]$")
    graph.set_ylabel("signal strength")
    graph.set_xlimits(0, 100)
    graph.set_ylimits(0, 5)

    # set scale: 1cm equals 10 units along the x-axis
    graph.set_xscale(cm=10)
    # set scale: 1cm equals 1 unit along the y-axis
    graph.set_yscale(cm=1)

    # set ticks at every unit along the y axis
    graph.set_yticks(range(6))

    # set graph paper
    graph.use_graph_paper()

    # save graph to file
    graph.save('mm_paper')
Пример #3
0
def main():
    x, t25, t50, t75 = np.loadtxt('data/DIR-boxplot_arrival_times-1.txt')

    graph = Plot()
    graph.plot(x, t50, mark='*')
    graph.shade_region(x, t25, t75)
    graph.set_xlabel(r"Core distance [\si{\meter}]")
    graph.set_ylabel(r"Arrival time delay [\si{\nano\second}]")
    graph.set_ylimits(min=0)
    graph.save('shower-front')
Пример #4
0
def main():
    plot = Plot()

    size = 20
    x = np.linspace(1, 20, size)
    y = np.linspace(10, 50, size)
    y_random = y + np.random.uniform(-3, 1, size)

    err_l = np.random.uniform(0, 2, size)
    err_h = np.random.uniform(1, 5, size)
    err_x = [0.4] * size

    plot.plot(x, y, mark=None)
    plot.scatter(x, y_random, xerr=err_x, yerr=list(zip(err_l, err_h)))

    plot.set_xlabel("Value with symmetric error")
    plot.set_ylabel("Other value with asymmetric errors")
    plot.save("error_bars")
Пример #5
0
def main():
    leap = np.genfromtxt('data/leap-prot.dat', delimiter=',',
                         usecols=(0, 1), names=['E', 'F'])
    leap['E'] *= 1e6
    leap['F'] *= 1e3 * 2

    proton = read_data('data/proton', 1, 0)
    akeno_new_lo = read_data('data/akeno-new-lo', 0, 1)
    flys_eye = read_data('data/fe-new', 0, 1)
    yakutsk = read_data('data/yakustk', 1, 0)
    haverah = read_data('data/haverah', 1, 0)

    graph = Plot(axis='loglog', width=r'.5\linewidth', height=r'.65\linewidth')

    graph.plot(leap['E'], leap['F'], mark=None)
    graph.add_pin('LEAP', 'above right', use_arrow=True,
                  relative_position=.5)
    graph.plot(proton['E'], proton['F'], mark=None)
    graph.add_pin('PROTON', 'above right', use_arrow=True,
                  relative_position=.5)
    graph.plot(akeno_new_lo['E'], akeno_new_lo['F'], mark=None)
    graph.add_pin('AGASA', 'above right', use_arrow=True,
                  relative_position=.5)

    graph.plot(yakutsk['E'], yakutsk['F'], mark=None)
    graph.add_pin('Yakutsk', 'below left', use_arrow=True,
                  relative_position=.55)
    graph.plot(haverah['E'], haverah['F'], mark=None)
    graph.add_pin('Haverah Park', 'below left', use_arrow=True,
                  relative_position=.85)
    graph.plot(flys_eye['E'], flys_eye['F'], mark=None)
    graph.add_pin("Fly's Eye", 'below left', use_arrow=True,
                  relative_position=1.0)

    graph.set_xlabel(r"Energy [\si{\electronvolt}]")
    graph.set_ylabel(r"Flux [\si{\per\square\meter\per\steradian"
                     "\per\second\per\giga\electronvolt}]")

    x = np.logspace(11, 17)
    graph.plot(x, 1.5e29 * x ** -2.75, mark=None, linestyle='dashed')

    graph.set_logxticks(range(6, 22, 3))
    graph.save('spectrum')
Пример #6
0
def main():
    gamma = np.genfromtxt('data/showere15-proton.t2001', usecols=(1, 2))
    e = np.genfromtxt('data/showere15-proton.t2205', usecols=(1, 2))
    mu = np.genfromtxt('data/showere15-proton.t2207', usecols=(1, 2))

    graph = Plot(axis='loglog')

    graph.plot(gamma[:, 0], gamma[:, 1], mark=None)
    graph.add_pin(r'$\gamma$')

    graph.plot(e[:, 0], e[:, 1], mark=None)
    graph.add_pin('e')

    graph.plot(mu[:, 0], mu[:, 1], mark=None)
    graph.add_pin(r'$\mu$')

    graph.set_xlabel(r"Core distance [\si{\meter}]")
    graph.set_ylabel(r"Particle density [\si{\per\square\meter}]")
    graph.set_logyticks(range(-6, 3, 2))
    graph.save('eas-lateral')
Пример #7
0
def main():
    locations = np.genfromtxt(
        'data/SP-DIR-plot_sciencepark_cluster-detectors.txt',
        names=['x', 'y'])
    stations = np.genfromtxt(
        'data/SP-DIR-plot_sciencepark_cluster-stations.txt',
        names=['id', 'x', 'y'])

    graph = Plot()

    graph.scatter(locations['x'], locations['y'])
    graph.set_axis_equal()

    locations = ['right'] * len(stations)
    locations[0] = 'left'
    locations[5] = 'above right'
    locations = iter(locations)
    for num, x, y in stations:
        graph.add_pin_at_xy(x, y, int(num), location=next(locations),
                            use_arrow=False, style='gray,label distance=1ex')

    x = [stations['x'][u] for u in [0, 2, 5]]
    y = [stations['y'][u] for u in [0, 2, 5]]
    x.append(x[0])
    y.append(y[0])
    graph.plot(x, y, mark=None, linestyle='dashed')

    graph.add_pin_at_xy([x[0], x[1]], [y[0], y[1]], r'\SI{128}{\meter}',
                        relative_position=.4, location='below right',
                        use_arrow=False)
    graph.add_pin_at_xy([x[0], x[2]], [y[0], y[2]], r'\SI{151}{\meter}',
                        relative_position=.5, location='left',
                        use_arrow=False)
    graph.add_pin_at_xy([x[2], x[1]], [y[2], y[1]], r'\SI{122}{\meter}',
                        relative_position=.5, location='above right',
                        use_arrow=False)

    graph.set_xlabel(r"Distance [\si{\meter}]")
    graph.set_ylabel(r"Distance [\si{\meter}]")

    graph.save('sciencepark')
Пример #8
0
def main():
    x = np.arange(10)
    y = (x / 2.0) - 3.0
    colors = ["black", "red", "blue", "yellow", "purple"]
    plot = Plot()

    for i in range(5):
        plot.plot(x, y - i, mark="", linestyle=colors[i])

    plot.set_axis_options(
        "yticklabel pos=right,\n"
        "grid=major,\n"
        "legend entries={$a$,[red]$b$,[green]$c$,$d$,$a^2$},\n"
        "legend pos=north west"
    )

    plot.set_xlabel("Something important")
    plot.set_ylabel("A related thing")
    plot.save("any_option")

    x = np.linspace(0.6 * np.pi, 10 * np.pi, 150)
    y = np.sin(x) / x
    plot = MultiPlot(1, 2, width=r".4\linewidth", height=r".25\linewidth")

    subplot = plot.get_subplot_at(0, 0)
    subplot.plot(x, y, mark=None)

    subplot = plot.get_subplot_at(0, 1)
    subplot.plot(x, y, mark=None)

    plot.show_xticklabels_for_all([(0, 0), (0, 1)])
    plot.show_yticklabels(0, 1)
    plot.set_axis_options(0, 1, "yticklabel pos=right, grid=major")

    plot.set_axis_options_for_all(None, r"enlargelimits=false")

    plot.set_xlabel("Something important")
    plot.set_ylabel("A related thing")
    plot.save("multi_any_option")
Пример #9
0
def main():
    # Draw random numbers from the normal distribution
    np.random.seed(1)
    N = np.random.normal(size=2000)

    # define bin edges
    edge = 5
    bin_width = .1
    bins = np.arange(-edge, edge + .5 * bin_width, bin_width)

    # build histogram and x, y values at the center of the bins
    n, bins = np.histogram(N, bins=bins)
    x = (bins[:-1] + bins[1:]) / 2
    y = n

    # fit normal distribution pdf to data
    f = lambda x, N, mu, sigma: N * scipy.stats.norm.pdf(x, mu, sigma)
    popt, pcov = scipy.optimize.curve_fit(f, x, y)
    print("Parameters from fit (N, mu, sigma):", popt)

    # make graph
    graph = Plot()

    # graph histogram
    graph.histogram(n, bins)

    # graph model with fit parameters
    x = np.linspace(-edge, edge, 100)
    graph.plot(x, f(x, *popt), mark=None)

    # set labels and limits
    graph.set_xlabel("value")
    graph.set_ylabel("count")
    graph.set_label("Fit to data")
    graph.set_xlimits(-6, 6)

    # save graph to file
    graph.save('histogram-fit')
Пример #10
0
def main():
    stations = np.genfromtxt("data/cluster-utrecht-stations.txt", names=["x", "y"])
    image = Image.open("data/cluster-utrecht-background.png")

    graph = Plot(width=r".75\linewidth", height=r".5\linewidth")

    graph.scatter(stations["x"], stations["y"])
    graph.draw_image(image)

    graph.set_axis_equal()

    nw = ["%.4f" % i for i in (52.10650519075632, 5.053710938)]
    se = ["%.4f" % i for i in (52.05249047600099, 5.185546875)]

    graph.set_xlabel("Longitude [$^\circ$]")
    graph.set_xticks([0, image.size[0]])
    graph.set_xtick_labels([nw[1], se[1]])

    graph.set_ylabel("Latitude [$^\circ$]")
    graph.set_yticks([0, image.size[1]])
    graph.set_ytick_labels([se[0], nw[0]])

    graph.save("utrecht")
Пример #11
0
def main():
    plot = Plot(width=r'.5\linewidth', height=r'.5\linewidth')
    r = linspace(1, 5, 100)
    phi = linspace(0, 4.5 * pi, 100)
    x = r * cos(phi)
    y = r * sin(phi)
    plot.plot(x, y, mark=None)
    plot.add_pin('start', relative_position=0, use_arrow=True)
    plot.add_pin('half', relative_position=.5, use_arrow=True)
    plot.add_pin('46\%', relative_position=.46, use_arrow=True,
                 location='above')
    plot.add_pin('end', relative_position=1, use_arrow=True, location='below')

    phi = linspace(0, 2 * pi, 10)
    x = 6 * cos(phi)
    y = 6 * sin(phi)
    plot.plot(x, y, mark=None, linestyle='thick, gray')
    plot.add_pin('start', relative_position=0, use_arrow=True,
                 location='above right')
    plot.add_pin('half', relative_position=.5, use_arrow=True,
                 location='above left')
    plot.add_pin('70\%', relative_position=.7, use_arrow=True,
                 location='below')
    plot.add_pin('end', relative_position=1, use_arrow=True,
                 location='below right')

    plot.plot([-5, 2, 5], [-7.5, -7.5, -7.5], linestyle='lightgray')
    plot.add_pin('50\%', relative_position=.5, use_arrow=True,
                 location='above right')

    plot.set_xlimits(-8, 8)
    plot.set_ylimits(-8, 8)
    plot.save('relative_pin')

    # With one logarithmic axis
    plot = Plot(axis='semilogy')

    x = [2, 2, 2]
    y = [1, 10, 100]
    plot.plot(x, y)
    for xi, yi in zip(x, y):
        plot.add_pin_at_xy(xi, yi, '(%d,%d)' % (xi, yi),
                           location='below right')
    plot.add_pin('half', relative_position=.5, use_arrow=True,
                 location='right')

    x = [4, 5, 6]
    y = [3, 3, 3]
    plot.plot(x, y)
    for xi, yi in zip(x, y):
        plot.add_pin_at_xy(xi, yi, '(%d,%d)' % (xi, yi), location='below')
    plot.add_pin('half', relative_position=.5, use_arrow=True,
                 location='above')

    x = [3, 4, 5]
    y = [1, 10, 100]
    plot.plot(x, y)
    for xi, yi in zip(x, y):
        plot.add_pin_at_xy(xi, yi, '(%d,%d)' % (xi, yi), location='above left')
    plot.add_pin('half', relative_position=.5, use_arrow=True,
                 location='right')

    plot.save('relative_pin_log')
Пример #12
0
def main():
    """Event display for an event of station 503

    Date        Time      Timestamp   Nanoseconds
    2012-03-29  10:51:36  1333018296  870008589

    Number of MIPs
    35.0  51.9  35.8  78.9

    Arrival time
    15.0  17.5  20.0  27.5

    """
    # Detector positions in ENU relative to the station GPS
    x = [-6.34, -2.23, -3.6, 3.46]
    y = [6.34, 2.23, -3.6, 3.46]

    # Scale mips to fit the graph
    n = [35.0, 51.9, 35.8, 78.9]

    # Make times relative to first detection
    t = [15., 17.5, 20., 27.5]
    dt = [ti - min(t) for ti in t]

    plot = Plot()
    plot.scatter([0], [0], mark='triangle')
    plot.add_pin_at_xy(0, 0, 'Station 503', use_arrow=False, location='below')
    plot.scatter_table(x, y, dt, n)

    plot.set_scalebar(location="lower right")
    plot.set_colorbar('$\Delta$t [ns]')
    plot.set_axis_equal()
    plot.set_mlimits(max=16.)
    plot.set_slimits(min=10., max=100.)

    plot.set_xlabel('x [m]')
    plot.set_ylabel('y [m]')

    plot.save('event_display')


    # Add event by Station 508
    # Detector positions in ENU relative to the station GPS
    x508 = [6.12, 0.00, -3.54, 3.54]
    y508 = [-6.12, -13.23, -3.54, 3.54]

    # Event GPS timestamp: 1371498167.016412100
    # MIPS
    n508 = [5.6, 16.7, 36.6, 9.0]
    # Arrival Times
    t508 = [15., 22.5, 22.5, 30.]
    dt508 = [ti - min(t508) for ti in t508]

    plot = MultiPlot(1, 2, width=r'.33\linewidth')
    plot.set_xlimits_for_all(min=-10, max=15)
    plot.set_ylimits_for_all(min=-15, max=10)
    plot.set_mlimits_for_all(min=0., max=16.)
    plot.set_colorbar('$\Delta$t [ns]', False)
    plot.set_colormap('blackwhite')
    plot.set_scalebar_for_all(location="upper right")

    p = plot.get_subplot_at(0, 0)
    p.scatter([0], [0], mark='triangle')
    p.add_pin_at_xy(0, 0, 'Station 503', use_arrow=False, location='below')
    p.scatter_table(x, y, dt, n)
    p.set_axis_equal()

    p = plot.get_subplot_at(0, 1)
    p.scatter([0], [0], mark='triangle')
    p.add_pin_at_xy(0, 0, 'Station 508', use_arrow=False, location='below')
    p.scatter_table(x508, y508, dt508, n508)
    p.set_axis_equal()

    plot.show_yticklabels_for_all([(0, 0)])
    plot.show_xticklabels_for_all([(0, 0), (0, 1)])

    plot.set_xlabel('x [m]')
    plot.set_ylabel('y [m]')

    plot.save('multi_event_display')
X = np.linspace(0., 2 * L, num=1000)
Y_sqr = [square(x) for x in X]
Y = lambda n: [fourier(x, n) for x in X]

graph = Plot()
graph.set_title("Fourier approximation")

graph.plot(x=X, y=Y(3), linestyle='red', mark=None, legend='n=3')
graph.plot(x=X, y=Y(5), linestyle='yellow', mark=None, legend='n=5')
graph.plot(x=X, y=Y(8), linestyle='green', mark=None, legend='n=8')
graph.plot(x=X, y=Y(13), linestyle='blue', mark=None, legend='n=13')
graph.plot(x=X, y=Y(55), linestyle='cyan', mark=None, legend='n=55')
graph.plot(x=X, y=Y_sqr, linestyle='black', mark=None, legend='square')

graph.save('fourier_with_legend')

graph = Plot()
graph.set_title("Fourier approximation")

graph.plot(x=X, y=Y(3), mark=None, linestyle='black!20')
add_custom_pin(graph, X, Y(3), 3)
graph.plot(x=X, y=Y(5), mark=None, linestyle='black!30')
add_custom_pin(graph, X, Y(5), 5)
graph.plot(x=X, y=Y(8), mark=None, linestyle='black!40')
add_custom_pin(graph, X, Y(8), 8)
graph.plot(x=X, y=Y(13), mark=None, linestyle='black!60')
add_custom_pin(graph, X, Y(13), 13, distance='5ex')
graph.plot(x=X, y=Y(55), mark=None, linestyle='black!80')
add_custom_pin(graph, X, Y(55), 55)
graph.plot(x=X, y=Y_sqr, mark=None, linestyle='thick')