示例#1
0
def plot_error_hist_per_model():
    fig = plt.figure()
    for (model, sub_idx) in zip(["*esn*", "*arima_r*", "*arima_ind*", "*wavelet*", "*CBR*"], 
                                (1, 2, 3, 4, 5)):
        ax = fig.add_subplot(3, 2, sub_idx, projection='3d')
        wildcards = ["_run_[0-9]*_bc-data.txt"]
        model_path = os.path.join(SG_SIM_PATH, "isgt-env-replace-3-of-7", model)
        matrix = _get_errors_as_dataframe(model_path, *wildcards).as_matrix()
        #bins = np.array(range(0, 11000, 100) + [35000])
        bins = np.array(range(0, 2100, 100))
        colors = [cm.flag(i) for i in np.linspace(0, 1, len(bins-1))]
        for pred in range(matrix.shape[1] - 1, -1, -1):
            (hist, _) = np.histogram(matrix[:,pred], bins=bins)
            x = np.array(range(len(bins[:-1])))
            x = np.array(bins[:-1])
            ax.bar(x, hist, pred, zdir='y', color=colors, edgecolor=colors)
            #ax.set_xticks(x + 0.5)
            #ax.set_xticklabels([str(bin) for bin in bins[:-1]])
        ax.set_xlabel('Error with model ' + model)
        ax.set_ylabel('Predictor number')
        ax.set_zlabel('Number of days with error')
示例#2
0
def plot_watersheds_3d(nodes_in_watersheds, landscape, ds):
    """
    Plot all or some watersheds in the landscape using different colors for different watersheds in 3D. Using the
    standard method.
    :param nodes_in_watersheds: List of arrays. Each array have all indices in the watershed.
    :param landscape: Landscape object with all data.
    :param ds: Downsampling factor for only plotting every ds point.
    :return: Plot watersheds in 3D using the standard method.
    """

    # Construct the (x, y)-coordinate system
    x_grid = np.linspace(landscape.x_min, landscape.x_max, landscape.num_of_nodes_x)
    y_grid = np.linspace(landscape.y_max, landscape.y_min, landscape.num_of_nodes_y)
    x_landscape, y_landscape = np.meshgrid(x_grid[0::ds], y_grid[0::ds])
    z_landscape = landscape.arr[0::ds, 0::ds]

    # Plot the landscape in 3D
    fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
    ax.plot_surface(x_landscape, y_landscape, z_landscape, cmap=plt.get_cmap('terrain'), zorder=0)

    # Plot all watersheds with over n nodes
    large_watersheds = ([watershed for watershed in nodes_in_watersheds
                        if len(watershed) > 5000])
    nr_of_large_watersheds = len(large_watersheds)

    colors = iter(cm.flag(np.linspace(0, 1, nr_of_large_watersheds)))

    # Plot all watersheds on top of the terrain
    for i in range(len(large_watersheds)):
        row_col = util.get_row_and_col_from_indices(large_watersheds[i], landscape.num_of_nodes_x)
        x = landscape.x_min + row_col[0::ds, 1] * landscape.step_size
        y = landscape.y_max - row_col[0::ds, 0] * landscape.step_size
        z = landscape.arr[row_col[0::ds, 0], row_col[0::ds, 1]]

        ax.scatter(x, y, z, c=next(colors), s=30, lw=0, zorder=1)

    plt.show()
示例#3
0
targetx = 0.7800808571829128
targety = 0.2944330689467324

# for thick, realistic cups
targetx = 0.7279635069051532
targety = 0.403791382614881

for zoom in xrange(110):
    tfile = '/media/scratch/cuptemp_wada'
    N = 1024
    
    width = size0 * 0.8**zoom

    print zoom, width, targetx - width/2, targety - width/2

    args = ['./cupgame-nowait-mapgen', N, 2.0, 1.00,
            targetx - width/2, targetx + width/2,
            targety - width/2, targety + width/2, tfile]
    
    check_call([str(a) for a in args])
    tt = np.fromfile(tfile, dtype='int32').reshape(N,N)

    # for thin cups
    #out = cm.flag(Normalize(vmin=-3000, vmax=3000)(tt))

    # for thick cups
    out = cm.flag(Normalize(vmin=-20, vmax=20)(tt))

    out[tt == 0] = [1.0,1.0,1.0,1.0]
    imsave(join(outdir, 'wada_%04d.png' % zoom), out)
示例#4
0
#!/usr/bin/env python
# coding: utf-8

# In[2]:

import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np

fig, (ax1, ax2, ax3, ax4, ax5, ax6, ax7) = plt.subplots(nrows=7, sharex=True)

x = np.linspace(0, 2 * np.pi, 100)
for i in range(30):
    y = i * np.sin(x)
    ax1.plot(x, y, color=cm.rainbow(i / 30.0))
    ax2.plot(x, y, color=cm.Reds(i / 30.0))
    ax3.plot(x, y, color=cm.binary(i / 30.0))
    ax4.plot(x, y, color=cm.PiYG(i / 30.0))
    ax5.plot(x, y, color=cm.twilight(i / 30.0))
    ax6.plot(x, y, color=cm.Pastel1(i / 30.0))
    ax7.plot(x, y, color=cm.flag(i / 30.0))

ax1.set_xlim(0, 2 * np.pi)
fig.show()

# In[ ]: