Exemplo n.º 1
0
    def plot_percentiles(self):
        if not self.train_outputs and not self.test_outputs:
            print("You need to fetch data first using fetch_range() or fetch_last().")
            return

        num_rows = len(self.blob_percentiles_keys) + len(self.weight_percentiles_keys)

        colormap = cm.brg(np.linspace(0.5, 0.8, self.num_percentiles))
        colormap = [colormap[4], colormap[2], colormap[0], colormap[2], colormap[4]]

        iterations = self.cache_log_train[:, 0].astype(int)

        fig, axes = plt.subplots(num_rows, 2)
        fig.set_size_inches(15, 2*num_rows, forward=True)
        fig.tight_layout()
        row = 0

        for layer in self.blob_percentiles_keys:
            blob_percentiles_data = np.array([x[layer][0] for x in self.cache_log_train[:, 3]])
            blob_percentiles_diff = np.array([x[layer][1] for x in self.cache_log_train[:, 3]])
            self.make_subplot(axes, row, 0, layer, iterations, blob_percentiles_data, colormap)
            self.make_subplot(axes, row, 1, layer, iterations, blob_percentiles_diff, colormap)
            row += 1

            if layer in self.weight_percentiles_keys:
                weight_percentiles_data = np.array([x[layer][0] for x in self.cache_log_train[:, 4]])
                weight_percentiles_diff = np.array([x[layer][1] for x in self.cache_log_train[:, 4]])

                self.make_subplot(axes, row, 0, layer, iterations, weight_percentiles_data, colormap, 'weights')
                self.make_subplot(axes, row, 1, layer, iterations, weight_percentiles_diff, colormap, 'weights')
                row += 1
Exemplo n.º 2
0
def draw_multigraph(G, plt):
    colors = cm.brg(np.linspace(0, 1, len(G.nodes()) + 1))
    for i, sg in enumerate(G.nodes()):
        xs = list()
        ys = list()
        for _, _, data in sg.edges_iter(data=True):
            draw_path(data["path"], color=colors[i],
                      linewidth=10)
        for node in sg.nodes():
            xs.append(node.x)
            ys.append(node.y)
        plt.scatter(xs, ys, color=colors[i], s=350,
                    edgecolors="k", linewidth=2, zorder=10)
Exemplo n.º 3
0
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import sys
import pandas as pd
import numpy as np


file = sys.argv[1]
data = pd.read_csv(file)

# separate by min resample limit
# Good RS nd PSC
bouts = list(set(data.number_of_bout))
colors = cm.brg(np.linspace(0, 1, len(bouts)))
legend_series_list = []
for bout in bouts:
    green_data = data.loc[(data.met_resamp_min >= data.min_resampled) &
                          (data.mean_rs_per_mrm >= data.min_times_resampled) & (data.number_of_bout == bout)
                          ]
    # Good RS only
    blue_data = data.loc[(data.met_resamp_min >= data.min_resampled) &
                         (data.mean_rs_per_mrm < data.min_times_resampled) & (data.number_of_bout == bout)
                         ]
    # Good RSC only
    yellow_data = data.loc[(data.met_resamp_min < data.min_resampled) &
                           (data.mean_rs_per_mrm >= data.min_times_resampled) & (data.number_of_bout == bout)
                           ]
    # No criteria met
    red_data = data.loc[(data.met_resamp_min < data.min_resampled) &
                        (data.mean_rs_per_mrm < data.min_times_resampled) & (data.number_of_bout == bout)
                        ]
Exemplo n.º 4
0
	def showGraph(self, selected):
		f = plt.figure()
		a = f.add_subplot(111)
		a2 = a.twinx()

		f.canvas.mpl_connect('pick_event', self.onpick)

		# a tk.DrawingArea
		self.canvas = FigureCanvasTkAgg(f, self.master)
		self.canvas.show()
		self.canvas.get_tk_widget().pack(side=LEFT, fill=BOTH, expand=1)

		averageTimes = [[], []]

		[colorTop, top] = self.getLengthAndColors()
		colors = cm.brg(np.linspace(0, 1, colorTop))

		# add half the color value
		colorAdd = (colorTop-1)/2

		SE = None

		for i in range(10, top):
			data = self.readData(i)
			if data[0]:
				
				# set marker size, extra large if selected
				s = 30
				if i == selected:
					s = 50
					SE, = a.plot((i, i), (100, 1100), 'r--', zorder=-1)

				# totalLengths errorbar
				x = [i] * len(data[0])
				y = data[0]
				a.errorbar(x, y, zorder=-1, c='k')

				# totalLengths errorbar
				x = i
				y = (sum(data[0])/float(len(data[0])))

				if i == 10:
					TL = a.scatter(x, y, c=colors[data[3][0] + colorAdd], s=s, zorder=3)
				else:
					a.scatter(x, y, c=colors[data[3][0] + colorAdd], s=s, zorder=0, picker=True)
				
				# save times
				averageTimes[0].append(i)
				averageTimes[1].append((sum(data[1])/float(len(data[1]))))

				#  constraint relaxation scatter
				x = i
				y = (sum(data[2])/float(len(data[2])))
				CR = a.scatter(x, y, c="blue", s=s, zorder=0, picker=True)

		# plot the average time
		Ti, = a2.plot(averageTimes[0], averageTimes[1], c="#cc9900", zorder=2, picker=True)

		plt.legend((TL, CR, Ti, SE),
		   ('Total Length (more red -> lower successrate)', 'Theoretical Minimum', 'Time', 'Selected Netlist'),
		   scatterpoints=1,
		   loc='upper left',
		   ncol=1,
		   fontsize=8)

		plt.title("Results of Random Netlists on Print " + self.printvar.get())

		a.set_xlabel('Amount of connections')
		a.set_ylabel('Average Total Length')
		a2.set_ylabel('Average Time(s)')

		a2.set_ylim(bottom=0)
Exemplo n.º 5
0
    "outputs_gc_mb/bins.txt",
    np.transpose([
        0.5 * (z0bins + zfbins), 0.5 * (zfbins - z0bins),
        sphz_red(0.5 * (z0bins + zfbins))
    ]))

ib_off = 7
if plot_stuff:
    plt.figure()
    for i in nbins - 1 - np.arange(nbins):
        if i >= ib_off:
            nz = nz_bins[i]
            ran = np.where(nz > 1E-3 * np.amax(nz))[0]
            plt.plot(zarr[ran],
                     nz[ran],
                     color=cm.brg((nbins - ib_off - i + ib_off - 0.5) /
                                  (nbins - ib_off + 0.)),
                     lw=2)
    plt.plot(zarr, nzarr, 'k-', lw=2)
    plt.ylim([0, 1.05 * np.amax(nzarr)])
    plt.xlim([0, 1.2 * zedge_hi])
    plt.xlabel('$z$', fontsize=18)
    plt.ylabel('$N(z)\\,\\,[{\\rm arcmin}^{-2}]$', fontsize=18)
    plt.savefig('../Draft/Figs/nz_lsst_mb.pdf', bbox_inches='tight')

data_dd = cgf.read_cls_class("outputs_gc_mb/run_dens_denscl.dat")
data_mm = cgf.read_cls_class("outputs_gc_mb/run_mb_mbcl.dat")
data_dm = cgf.read_cls_class("outputs_gc_mb/run_dens_mbcl.dat")

larr = np.arange(2001)[2:1001]
cl_dd = data_dd['cl_dd'][2:1001, ib_off:, ib_off:]
cl_mm = data_mm['cl_dd'][2:1001, ib_off:, ib_off:]
Exemplo n.º 6
0
def comparison_table(adata,
                     name_keys,
                     group=None,
                     color_thresholds=None,
                     n_genes=70):
    ## Very early: Take list of keys for which to search adata.uns.
    ## Then build a table of all included genes, see which w
    ## Trick: Map only the top 20/30 or so, color green/yellow/orange/red for top 40/ 60 / below
    ##TODO: Add functionality for group, color thresholds.

    ## Assume all annotations have the same length
    name_list = {}
    for i, j in enumerate(name_keys):
        name_list[i] = adata.uns[j]

    # We dont need rank list as we assume that name list is ordered.

    length = len(name_list[0])
    width = len(name_list)
    # we create one large table (still no memory issue (realistic max. 10000*10--> 1 Mbyte approx). Truncuate later
    rank_table = length * np.ones((length * width, width))
    # Create full name list
    full_name_list = list()
    n = -1

    for key in name_list:
        for k, l in enumerate(name_list[key]):
            # Only plot for each group the top 20 genes to avoid that the table becomes to large. Max_n should be
            # a parameter in the future
            # Problem: We should add everything, but only plot a certain truncu
            if l not in full_name_list:
                full_name_list.append(l)
                n = n + 1
                m = n
            else:
                m = full_name_list.index(l)
            rank_table[m, key] = k

    # Create table with all entries
    if max_n < n:
        n = max_n
    trunc_table = rank_table[0:n + 1, :]
    # Do the colorings:
    colors = trunc_table.copy()
    for i in range(n + 1):
        # Here, for now we use the convention that the respective levels are true if the minimum rank is larger
        # than the specified number
        top20 = True
        top50 = True
        top100 = True
        for j in range(width):
            if colors[i, j] >= 100:
                top20 = top50 = top100 = False
            elif colors[i, j] >= 51:
                top20 = top50 = False
            elif colors[i, j] >= 21:
                top20 = False
        # Now depending on the boolean values, define colors.
        if top100 is False:
            colors[i, :] = 0
        elif top50 is False:
            colors[i, :] = 0.5
        elif top20 is False:
            colors[i, :] = 0.8
        else:
            colors[i, :] = 1
    fig, ax = plt.subplots(1, 1)
    ax.table(cellText=trunc_table,
             rowLabels=full_name_list[0:n + 1],
             colLabels=name_keys,
             cellColours=cm.brg(colors))
    plt.tight_layout()
    plt.show()

path = 'X:\\Images\\150824_JVZ20_wrt2GFP_250x250x20\\'
worm = 'C10'

cells1 = ['b.','6.','c.','5.','4.','1.','2.']
cell2 = '3.'
cside = 'L'

fig = plt.figure(figsize = (5.8,5.8))
# plt.title(cell1+'-'+cell2)
ax = fig.add_subplot(111)
ax.set_xlim((-10000,10000))
ax.set_ylim((-10000,10000))

colors = np.array( [cm.brg(int(i)) for i in np.arange(len(cells1))*254./(len(cells1)-1)] )
colors = colors[::-1]

### find deviation from V3

dev = []
for idx, cell1 in enumerate( cells1 ):
    c1Raw, c2Raw, c1Filt, c2Filt = loadData(path, worm, cell1, cell2, cside)
    dev.append( getDeviation( c1Raw, c2Raw ) )

### sort the data according to deviation from V3

cells1sorted = [x for (y,x) in sorted(zip(dev,cells1))][::-1]
devsorted = [y for (y,x) in sorted(zip(dev,cells1))][::-1]

for idx, cell1 in enumerate(cells1sorted):
Exemplo n.º 8
0
    def showGraph(self, selected):

        f = plt.figure()
        # a tk.DrawingArea
        self.canvas = FigureCanvasTkAgg(f, self.master)
        self.canvas.show()
        self.canvas.get_tk_widget().pack(side=LEFT, fill=BOTH, expand=1)

        a = f.add_subplot(111)
        a2 = a.twinx()

        def OnClick(event):
            self.cons = int(round(event.xdata, 0))
            self.showInfoAndGraph()

        cid = f.canvas.mpl_connect('button_press_event', OnClick)

        averageTimes = [[], []]

        [self.colorTop, top] = self.getLengthAndColors()
        colors = cm.brg(np.linspace(0, 1, self.colorTop * 2 + 1))

        # add half the color value
        colorAdd = ((self.colorTop * 2 + 1) - 1) / 2

        SE = None

        for i in range(10, top):
            data = self.readData(i)
            if data[0]:

                # set marker size, extra large if selected
                s = 30
                if i == selected:
                    s = 50
                    SE, = a.plot((i, i), (100, 1100), 'r--', zorder=-1)

                # totalLengths errorbar
                x = [i] * len(data[0])
                y = data[0]
                a.errorbar(x, y, zorder=1, c='k')

                # totalLengths errorbar
                x = i
                y = (sum(data[0]) / float(len(data[0])))

                if i == 10:
                    TL = a.scatter(x,
                                   y,
                                   c=colors[data[3][0] + colorAdd],
                                   s=s,
                                   zorder=2)
                else:
                    a.scatter(x,
                              y,
                              c=colors[data[3][0] + colorAdd],
                              s=s,
                              zorder=2)

                # save times
                averageTimes[0].append(i)
                averageTimes[1].append((sum(data[1]) / float(len(data[1]))))

                #  constraint relaxation scatter
                x = i
                y = (sum(data[2]) / float(len(data[2])))
                CR = a.scatter(x, y, c="blue", s=s, zorder=2)

        # plot the average time
        Ti, = a2.plot(averageTimes[0], averageTimes[1], c="#cc9900", zorder=2)

        plt.legend((TL, CR, Ti, SE),
                   ('Total Length (more red -> lower successrate)',
                    'Theoretical Minimum', 'Time', 'Selected Netlist'),
                   scatterpoints=1,
                   loc='upper left',
                   ncol=1,
                   fontsize=8)

        plt.title("Results of Random Netlists on Print " + self.printvar.get())

        a.set_xlabel('Amount of connections')
        a.set_ylabel('Average Total Length')
        a2.set_ylabel('Average Time(s)')

        a.set_xlim(left=9.8)
        a.set_xlim(right=50.2)
        a2.set_ylim(bottom=0)
    plt.ylabel("log Peak Temperature Ratio")
    plt.xticks([0.1, 1], [-1, 0])
    plt.yticks([0.1, 1], [-1, 0])
    plt.legend(loc="upper left")

    # contour
    H, xedges, yedges = np.histogram2d(p21,
                                       r21,
                                       bins=100,
                                       range=([10**-1.2,
                                               10**0.7], [10**-1.2, 10**0.7]))
    extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
    plt.contour(H / H.max() * 100,
                levels=[8, 16, 32, 64, 96],
                extent=extent,
                colors=[cm.brg(i / 2.5)],
                zorder=1,
                linewidths=2.5,
                alpha=1.0,
                label=galname.replace("ngc", "NGC "))

    histo.extend(p21 / r21)
    r21_all.extend(r21)
    p21_all.extend(p21)
    r21err_all.extend(r21err)
    p21err_all.extend(p21err)

plt.legend(low="lower right")

p2r = np.array(p21_all) / np.array(r21_all)
r21err_all = np.array(r21err_all)
Exemplo n.º 10
0
list_3627 = list_master[1]
list_4321 = list_master[2]
np.savetxt(dir_proj + "eps/ngc0628_noise.txt", list_0628)
np.savetxt(dir_proj + "eps/ngc3627_noise.txt", list_3627)
np.savetxt(dir_proj + "eps/ngc4321_noise.txt", list_4321)

fig = plt.figure(figsize=(10, 10))
ax1 = fig.add_subplot(111)
plt.rcParams["font.size"] = 22
plt.subplots_adjust(bottom=0.10, left=0.19, right=0.99, top=0.90)

ax1.plot(list_0628[:, 0],
         np.log10(list_0628[:, 1] * 1.222e6 / list_0628[:, 0]**2 /
                  115.27120**2),
         "-",
         color=cm.brg(0 / 2.5),
         markeredgewidth=0,
         markersize=10,
         alpha=0.5,
         lw=7,
         label="NGC 0628 CO(1-0)")
ax1.plot(list_0628[:, 0],
         np.log10(list_0628[:, 2] * 1.222e6 / list_0628[:, 0]**2 /
                  230.53800**2),
         "--",
         color=cm.brg(0 / 2.5),
         markeredgewidth=0,
         markersize=10,
         alpha=0.5,
         lw=7,
         label="NGC 0628 CO(2-1)")