Exemplo n.º 1
0
def legend(status=True, pos=None, fontsize=None):
    """ legend(status=True): Show/Hide legend.\n status = True if legend must be shown, False otherwise.\n pos = Legend position.\n fontsize = Font size """
    plt = getPlot()
    if not plt:
        return
    plt.legend = status
    if pos:
        plt.legPos = pos
    if fontsize:
        plt.legSiz = fontsize
    # Hide all legends
    for axes in plt.axesList:
        axes.legend_ = None
    # Legend must be activated on last axes
    axes = plt.axesList[-1]
    if status:
        # Setup legend handles and names
        lines = series()
        handles = []
        names = []
        for l in lines:
            if l.name != None:
                handles.append(l.line)
                names.append(l.name)
        # Show the legend
        l = axes.legend(handles, names, bbox_to_anchor=plt.legPos)
        for t in l.get_texts():
            t.set_fontsize(plt.legSiz)
    plt.update()
Exemplo n.º 2
0
def save(path, figsize=None, dpi=None):
    """Save plot.

    Keyword arguments:
    path -- Destination file path.
    figsize -- w,h figure size tuple in inches.
    dpi -- Dots per inch.
    """
    plt = getPlot()
    if not plt:
        return
    # Backup figure options
    fig = plt.fig
    sizeBack = fig.get_size_inches()
    dpiBack = fig.get_dpi()
    # Save figure with new options
    if figsize:
        fig.set_size_inches(figsize[0], figsize[1])
    if dpi:
        fig.set_dpi(dpi)
    plt.canvas.print_figure(path)
    # Restore figure options
    fig.set_size_inches(sizeBack[0], sizeBack[1])
    fig.set_dpi(dpiBack)
    plt.update()
Exemplo n.º 3
0
def save(path, figsize=None, dpi=None):
    """Save plot.

    Keyword arguments:
    path -- Destination file path.
    figsize -- w,h figure size tuple in inches.
    dpi -- Dots per inch.
    """
    plt = getPlot()
    if not plt:
        return
    # Backup figure options
    fig = plt.fig
    sizeBack = fig.get_size_inches()
    dpiBack = fig.get_dpi()
    # Save figure with new options
    if figsize:
        fig.set_size_inches(figsize[0], figsize[1])
    if dpi:
        fig.set_dpi(dpi)
    plt.canvas.print_figure(path)
    # Restore figure options
    fig.set_size_inches(sizeBack[0], sizeBack[1])
    fig.set_dpi(dpiBack)
    plt.update()
Exemplo n.º 4
0
def legend(status=True, pos=None, fontsize=None):
	""" legend(status=True): Show/Hide legend.\n status = True if legend must be shown, False otherwise.\n pos = Legend position.\n fontsize = Font size """
	plt = getPlot()
	if not plt:
		return
	plt.legend = status
	if pos:
		plt.legPos = pos
	if fontsize:
		plt.legSiz = fontsize
	# Hide all legends
	for axes in plt.axesList:
		axes.legend_ = None
	# Legend must be activated on last axes
	axes = plt.axesList[-1]
	if status:
		# Setup legend handles and names
		lines   = series()
		handles = []
		names   = []
		for l in lines:
			if l.name != None:
				handles.append(l.line)
				names.append(l.name)
		# Show the legend
		l = axes.legend(handles, names, bbox_to_anchor=plt.legPos)
		for t in l.get_texts():
			t.set_fontsize(plt.legSiz)
	plt.update()
Exemplo n.º 5
0
def ylabel(string):
	""" ylabel(string): Setup y label.\n string = Title to set. """
	plt = getPlot()
	if not plt:
		return
	axes = plt.axes
	axes.set_ylabel(string)
	plt.update()
Exemplo n.º 6
0
def title(string):
	""" title(string): Setup plot title.\n string = Title to set. """
	plt = getPlot()
	if not plt:
		return
	axes = plt.axes
	axes.set_title(string)
	plt.update()
Exemplo n.º 7
0
def title(string):
    """ title(string): Setup plot title.\n string = Title to set. """
    plt = getPlot()
    if not plt:
        return
    axes = plt.axes
    axes.set_title(string)
    plt.update()
Exemplo n.º 8
0
def ylabel(string):
    """ ylabel(string): Setup y label.\n string = Title to set. """
    plt = getPlot()
    if not plt:
        return
    axes = plt.axes
    axes.set_ylabel(string)
    plt.update()
Exemplo n.º 9
0
def grid(status=True):
	""" grid(status=True): Show/Hide grid.\n status = True if grid must be shown, False otherwise. """
	plt = getPlot()
	if not plt:
		return
	plt.grid = status
	axes = plt.axes
	axes.grid(status)
	plt.update()
Exemplo n.º 10
0
def grid(status=True):
    """ grid(status=True): Show/Hide grid.\n status = True if grid must be shown, False otherwise. """
    plt = getPlot()
    if not plt:
        return
    plt.grid = status
    axes = plt.axes
    axes.grid(status)
    plt.update()
Exemplo n.º 11
0
def ylabel(string):
    """Setup the y label.

    Keyword arguments:
    string -- Title to set.
    """
    plt = getPlot()
    if not plt:
        return
    axes = plt.axes
    axes.set_ylabel(string)
    plt.update()
Exemplo n.º 12
0
def title(string):
    """Setup the plot title.

    Keyword arguments:
    string -- Plot title.
    """
    plt = getPlot()
    if not plt:
        return
    axes = plt.axes
    axes.set_title(string)
    plt.update()
Exemplo n.º 13
0
def title(string):
    """Setup the plot title.

    Keyword arguments:
    string -- Plot title.
    """
    plt = getPlot()
    if not plt:
        return
    axes = plt.axes
    axes.set_title(string)
    plt.update()
Exemplo n.º 14
0
def ylabel(string):
    """Setup the y label.

    Keyword arguments:
    string -- Title to set.
    """
    plt = getPlot()
    if not plt:
        return
    axes = plt.axes
    axes.set_ylabel(string)
    plt.update()
Exemplo n.º 15
0
def grid(status=True):
    """Show/Hide the grid from the active plot.

    Keyword arguments:
    status -- True if grid must be shown, False otherwise.
    """
    plt = getPlot()
    if not plt:
        return
    plt.grid = status
    axes = plt.axes
    axes.grid(status)
    plt.update()
Exemplo n.º 16
0
def grid(status=True):
    """Show/Hide the grid from the active plot.

    Keyword arguments:
    status -- True if grid must be shown, False otherwise.
    """
    plt = getPlot()
    if not plt:
        return
    plt.grid = status
    axes = plt.axes
    axes.grid(status)
    plt.update()
Exemplo n.º 17
0
def legend(status=True, pos=None, fontsize=None):
    """Show/Hide the legend from the active plot.

    Keyword arguments:
    status -- True if legend must be shown, False otherwise.
    pos -- Legend position.
    fontsize -- Font size
    """
    plt = getPlot()
    if not plt:
        return
    plt.legend = status
    if fontsize:
        plt.legSiz = fontsize
    # Hide all legends
    for axes in plt.axesList:
        axes.legend_ = None
    # Legend must be activated on last axes
    axes = plt.axesList[-1]
    if status:
        # Setup legend handles and names
        lines = series()
        handles = []
        names = []
        for l in lines:
            if l.name is not None:
                handles.append(l.line)
                names.append(l.name)
        # Show the legend (at selected position or at best)
        if pos:
            l = axes.legend(handles, names, bbox_to_anchor=pos)
            plt.legPos = pos
        else:
            l = axes.legend(handles, names, loc='best')
            # Update canvas in order to compute legend data
            plt.canvas.draw()
            # Get resultant position
            try:
                fax = axes.get_frame().get_extents()
            except:
                fax = axes.patch.get_extents()
            fl = l.get_frame()
            plt.legPos = (
                (fl._x + fl._width - fax.x0) / fax.width,
                (fl._y + fl._height - fax.y0) / fax.height)
        # Set fontsize
        for t in l.get_texts():
            t.set_fontsize(plt.legSiz)
    plt.update()
Exemplo n.º 18
0
def legend(status=True, pos=None, fontsize=None):
    """Show/Hide the legend from the active plot.

    Keyword arguments:
    status -- True if legend must be shown, False otherwise.
    pos -- Legend position.
    fontsize -- Font size
    """
    plt = getPlot()
    if not plt:
        return
    plt.legend = status
    if fontsize:
        plt.legSiz = fontsize
    # Hide all legends
    for axes in plt.axesList:
        axes.legend_ = None
    # Legend must be activated on last axes
    axes = plt.axesList[-1]
    if status:
        # Setup legend handles and names
        lines = series()
        handles = []
        names = []
        for l in lines:
            if l.name is not None:
                handles.append(l.line)
                names.append(l.name)
        # Show the legend (at selected position or at best)
        if pos:
            l = axes.legend(handles, names, bbox_to_anchor=pos)
            plt.legPos = pos
        else:
            l = axes.legend(handles, names, loc='best')
            # Update canvas in order to compute legend data
            plt.canvas.draw()
            # Get resultant position
            try:
                fax = axes.get_frame().get_extents()
            except Exception:
                fax = axes.patch.get_extents()
            fl = l.get_frame()
            plt.legPos = ((fl._x + fl._width - fax.x0) / fax.width,
                          (fl._y + fl._height - fax.y0) / fax.height)
        # Set fontsize
        for t in l.get_texts():
            t.set_fontsize(plt.legSiz)
    plt.update()
Exemplo n.º 19
0
def removeSerie(index):
    """ removeSerie(index): Removes a serie from plot.\n index = Index of serie to remove. """
    # Get active series
    plt = getPlot()
    if not plt:
        return
    plots = plt.series
    if not plots:
        return
    # Remove line from plot
    axes = plots[index].axes
    axes.lines.pop(plots[index].lid)
    # Remove serie from list
    del plt.series[index]
    # Update GUI
    plt.update()
Exemplo n.º 20
0
def removeSerie(index):
	""" removeSerie(index): Removes a serie from plot.\n index = Index of serie to remove. """
	# Get active series
	plt = getPlot()
	if not plt:
		return
	plots = plt.series
	if not plots:
		return
	# Remove line from plot
	axes = plots[index].axes
	axes.lines.pop(plots[index].lid)
	# Remove serie from list
	del plt.series[index]
	# Update GUI
	plt.update()
Exemplo n.º 21
0
def addNewAxes(rect=None, frameon=True, patchcolor='none'):
    """ addNewAxes(pos=None, frameon=True): Add new axes to plot, setting it as active one.\n rect = Axes area, None to copy last axes data.\n frameon = True to show frame, False otherwise.\n patchcolor = Patch color, 'none' for transparent plot. """
    plt = getPlot()
    if not plt:
        return None
    fig = plt.fig
    if rect == None:
        rect = plt.axes.get_position()
    ax = fig.add_axes(rect, frameon=frameon)
    ax.xaxis.set_ticks_position('bottom')
    ax.spines['top'].set_color('none')
    ax.yaxis.set_ticks_position('left')
    ax.spines['right'].set_color('none')
    ax.patch.set_facecolor(patchcolor)
    plt.axesList.append(ax)
    plt.setActiveAxes(-1)
    plt.update()
    return ax
Exemplo n.º 22
0
def addNewAxes(rect=None, frameon=True, patchcolor='none'):
	""" addNewAxes(pos=None, frameon=True): Add new axes to plot, setting it as active one.\n rect = Axes area, None to copy last axes data.\n frameon = True to show frame, False otherwise.\n patchcolor = Patch color, 'none' for transparent plot. """
	plt = getPlot()
	if not plt:
		return None
	fig = plt.fig
	if rect == None:
		rect = plt.axes.get_position()
	ax = fig.add_axes(rect, frameon=frameon)
	ax.xaxis.set_ticks_position('bottom')
	ax.spines['top'].set_color('none')
	ax.yaxis.set_ticks_position('left')
	ax.spines['right'].set_color('none')
	ax.patch.set_facecolor(patchcolor)
	plt.axesList.append(ax)
	plt.setActiveAxes(-1)
	plt.update()
	return ax
Exemplo n.º 23
0
def removeSerie(index):
    """Remove a data serie from the active plot.

    Keyword arguments:
    index -- Index of the serie to remove.
    """
    # Get active series
    plt = getPlot()
    if not plt:
        return
    plots = plt.series
    if not plots:
        return
    # Remove line from plot
    axes = plots[index].axes
    axes.lines.pop(plots[index].lid)
    # Remove serie from list
    del plt.series[index]
    # Update GUI
    plt.update()
Exemplo n.º 24
0
def removeSerie(index):
    """Remove a data serie from the active plot.

    Keyword arguments:
    index -- Index of the serie to remove.
    """
    # Get active series
    plt = getPlot()
    if not plt:
        return
    plots = plt.series
    if not plots:
        return
    # Remove line from plot
    axes = plots[index].axes
    axes.lines.pop(plots[index].lid)
    # Remove serie from list
    del plt.series[index]
    # Update GUI
    plt.update()
Exemplo n.º 25
0
def tempvis(csv_file, tmax, tmin, cmap, showortell='show'):
    """This function converts the csv file into a black-and-white picture. It does not at present
    have a colorbar to indicate the temperature scale."""
    csv = np.genfromtxt(csv_file, delimiter=',')
    title = '\n Heat map of ' + csv_file.split("/")[-1][:-4] + '\n'
    fig = plt.figure()
    ax1 = fig.add_subplot(121)
    ax1.imshow(csv)
    ax1.set(title=title)
    ax2 = fig.add_subplot(122)
    ax2.imshow(np.zeros_like(csv))
    plt.subplots_adjust()

    x, y = np.meshgrid(np.arange(csv.shape[1]), np.arange(csv.shape[0]))
    pix = np.vstack((x.flatten(), y.flatten())).T
    saved_localmax = []
    saved_localmaxavg = []
    saved_localmin = []
    saved_localavg = []
    saved_labels = []

    def onselect(verts):
        #Driver for lasso selection on images
        p = Path(verts)
        ind = p.contains_points(pix, radius=1)
        selected = np.zeros_like(csv)
        selected.flat[ind] = csv.flat[ind]
        data = csv.flat[ind]
        ax2.imshow(selected)
        fig.canvas.draw_idle()
        save = input("Save data in selection?[y/n]: ")
        if (save == "y"):
            cached_paths.append(p)
            max = np.amax(data)
            maxavg = np.average(heapq.nlargest(10, data))
            min = np.amin(data)
            avg = np.average(data)
            saved_localmax.append(max)
            saved_localmaxavg.append(maxavg)
            saved_localmin.append(min)
            saved_localavg.append(avg)
            lab = input("Label for this region: ")
            saved_labels.append(lab)

    plt.show()
    volt = float(input("Voltage: "))
    curr = float(input("Current: "))
    if (input("Use same regions as last image?[y/n]: ") == "y"):
        for i, p in enumerate(cached_paths):
            ind = p.contains_points(pix, radius=1)
            data = csv.flat[ind]
            max = np.amax(data)
            maxavg = np.average(heapq.nlargest(10, data))
            min = np.amin(data)
            avg = np.average(data)
            saved_localmax.append(max)
            saved_localmaxavg.append(maxavg)
            saved_localmin.append(min)
            saved_localavg.append(avg)
            saved_labels.append(cached_labels[i])
        print("Done with processing")
        print("--------------------------------------")
        return (saved_localmax, saved_localmaxavg, saved_localmin,
                saved_localavg, saved_labels, volt, curr)
    else:
        cached_paths = []
        cached_labels = []
    lasso = LassoSelector(ax1, onselect)
    plt.update()
    print("Done with processing")
    print("--------------------------------------")
    return (saved_localmax, saved_localmaxavg, saved_localmin, saved_localavg,
            saved_labels, volt, curr)
Exemplo n.º 26
0
    #fftData=abs(np.fft.rfft(mic))**2
    #print(fftData.__len__())
    #x = np.arange(0, 4097, 1)
    line, = ax.plot(fftx, ffty)
    #plt.plot(fftx, ffty, 'k')
    ani = animation.FuncAnimation(fig, animate, fftx, interval=25, blit=True)
    plt.show()

    while True:
        time.sleep(0.2)
        mic_data = mic_chunks.pop(0)
        mic = np.array(struct.unpack("%dB" % (200), mic_data[:200]))
        fftData = abs(np.fft.rfft(mic))**2
        plt.plot(fftData, 'k')
        plt.update()

    close()

    f = open("Code.txt", "w")
    time.sleep(0.2)
    for i in range(15):
        mic_data = mic_chunks.pop(0)
        mic = np.array(struct.unpack("%dB" % (bufferSize * 4), mic_data))
        fftData = abs(np.fft.rfft(mic))**2
        stream.write(mic_data)
        #s="["
        #for q in mic:
        #    s+=str(q) + ","
        #s=s[:-1] + "]"
        #print(s)