def PlotConfusionMatrix(cm, target_names, Title="Neuropeptides"): ''' Works! ''' import matplotlib as mpl np.set_printoptions(suppress=True) mpl.rc("figure", figsize=(12, 9)) hm = sns.heatmap( cm, cbar=True, annot=True, square=True, fmt='d', yticklabels=target_names, xticklabels=target_names, # cmap='Blues' ) plt.fig(dpi=200) plt.title('Confusion matrix: ' + Title) plt.ylabel('Actual class') plt.xlabel('Predicted class') plt.tight_layout() ## plt.savefig('./images/confmat.png', dpi=300) plt.show()
def visualize_source_distribution(sim, superpose=True, options=None): if not mp.am_master(): return options = options if options else def_src_options for ns, s in enumerate(sim.sources): sc, ss = s.center, s.size J2 = sum( [abs2(sim.get_source_slice(c, center=sc, size=ss)) for c in Exyz]) # M2=sum([abs2(sim.get_source_slice(c,center=sc,size=ss)) for c in Hxyz]) if superpose == False: if ns == 0: plt.ion() plt.figure() plt.title('Source regions') plt.fig().subplot(len(sim.sources), 1, ns + 1) plt.fig().title('Currents in source region {}'.format(ns)) # plot_data_curves(sim,superpose,[J2,M2],labels=['||J||','||M||'], # styles=['bo-','rs-'],center=sc,size=ssu plot_data_curves(sim, center=sc, size=ss, superpose=superpose, data=[J2], labels=['J'], options=options)
def plot_latent(vae_enc, vae_dec): # output axa images a = 30 # size of digit dig_sz = 28 # scale s = 2.0 # figure size fig_sz = 15 fig = npy.zeros((dig_sz * a, dig_sz * a)) # linear scaling x = npy.linspace(-s, s, a) y = npy.linspace(-s, s, a)[::-1] # for all rows and columns for c, col in enumerate(y): for r, row in enumerate(x): smpl = npy.array([[row, col]]) xd = vae_dec.predict(smpl) dig = xd[0].reshape(dig_sz, dig_sz) figure[ c * dig_sz : (c + 1) * dig_sz, r * dig_sz : (r + 1) * dig_sz, ] = dig # plot figure plot.fig(fig_sz=(fig_sz, fig_sz)) # start range st = dig_sz // 2 # end range en = a * dig_sz + 1 + st pixel_range = npy.arange(st, en, dig_sz) # sample range, x and y x_range = npy.round(x, 1) y_range = npy.round(y, 1) # show plot plot.imshow(fig, cmap="Greys_r") plot.show()
def detect_edge_display(path): # Load image as greyscale image_gray = cv2.imread(path, cv2.IMREAD_GRAYSCALE) # Calculate median intensity median_intensity = np.median(image_gray) # Set thresholds to be one standard deviation above and below median intensity lower_threshold = int(max(0, (1.0 - 0.33) * median_intensity)) upper_threshold = int(min(255, (1.0 + 0.33) * median_intensity)) # Apply canny edge detector image_canny = cv2.Canny(image_gray, lower_threshold, upper_threshold) # Show image plt.imshow(image_canny, cmap='gray'), plt.axis("off") plt.show() plt.fig()
def plot_data_samples(MNIST, fig=None): if fig is None: fig = plt.fig() img_indices = np.random.random_integers(0, 5000, 10) ax = fig.subplots(10, 10) for i in range(10): for j in range(10): ax[i, j].imshow(MNIST["train" + str(i)][img_indices[j]].reshape( (28, 28))) ax[i, j].axis('off') return fig, ax
def visualize_source_distribution(sim, superpose=True, options=None): if not mp.am_master(): return options=options if options else def_src_options for ns,s in enumerate(sim.sources): sc,ss=s.center,s.size J2=sum([abs2(sim.get_source_slice(c,center=sc,size=ss)) for c in Exyz]) # M2=sum([abs2(sim.get_source_slice(c,center=sc,size=ss)) for c in Hxyz]) if superpose==False: if ns==0: plt.ion() plt.figure() plt.title('Source regions') plt.fig().subplot(len(sim.sources),1,ns+1) plt.fig().title('Currents in source region {}'.format(ns)) # plot_data_curves(sim,superpose,[J2,M2],labels=['||J||','||M||'], # styles=['bo-','rs-'],center=sc,size=ssu plot_data_curves(sim,center=sc,size=ss, superpose=superpose, data=[J2], labels=['J'], options=options)
def plot(self): fig=plt.fig(figsize=(10,6)) fig.subtitle("Pendulo Invertido",fontsize=14,fontweight='bold') ax = a3d.Axes3D(fig,rect=[0,0,0.6,1]) ax.set_autoscale_on(False) ax.set_xlim3d((0,30)) ax.set_ylim3d((-1,1)) ax.set_zlim3d((-1,1)) ax.set_xlabel(r'$t$') ax.set_ylabel(r'$x$') ax.set_zlabel(r'$y$') ax.plot3D(self.tau, self.x(), self.y()) fig.subplots_adjust(left=0.66,bottom=0.05,top=0.95) bx = fig.add_subplot(211) bx.set_autoscale_on(True) bx.set_ylabel(r'$\theta$') bx.set_title('t') bx.plot(self.tau,self.theta()) cx = fig.add_subplot(212) cx.set_autoscale_on(True) cx.set_ylabel(r'$\omega$') cx.plot(self.tau,self.omega()) fig, dx = plt.subplots(4,1, figsize = (10,8), sharex=True) dx[0].plot(self.tau, self.x(), label="x", color="blue") dx[1].plot(self.tau, self.xprima(), label="x prima", color="green") dx[2].plot(self.tau, self.theta(), label="theta", color="blue") dx[3].plot(self.tau, self.thetap(), label=" theta prima", color="green") dx[0].set_ylabel("x (m)") dx[0].set_xlabel("tiempo (s)") dx[1].set_ylabel("x prima (m/s)") dx[1].set_xlabel("tiempo (s)") dx[2].set_ylabel("theta (radianes)") dx[2].set_xlabel("tiempo (s)") dx[3].set_ylabel("theta prima (rad/s)") dx[3].set_xlabel("tiempo (s)") plt.show()
def create_grid_category_bar_chart(self, out_file): # bar chart will show the block counts of the following: # 1. Total # 2. EoC != 0.5 # 3. EoC == 0.5 # 4. VoC == 0 # 5. VoC == 1 # 6. EoC == 0.5 & VoC == 1 bar_names = [ 'Total', 'EoC != 0.5', 'EoC == 0.5', 'VoC == 0', 'VoC == 1', 'EoC == 0.5 &\nVoC == 1' ] y = self.get_grid_category_counts() colors = ['green', 'blue', 'purple', 'grey', 'teal', 'red'] fig(figsize=(8, 4)) plt.bar(bar_names, y, color=colors) plt.title('Overall block categories') plt.xlabel('Category') plt.ylabel('Number of Blocks') plt.tight_layout() plt.savefig(out_file) plt.clf() print(f"wrote: {out_file}")
def PlotConfusionMatrix (cm,target_names,Title="Neuropeptides"): ''' Works! ''' import matplotlib as mpl np.set_printoptions(suppress=True) mpl.rc("figure", figsize=(12, 9)) hm = sns.heatmap(cm, cbar=True, annot=True, square=True, fmt='d', yticklabels=target_names, xticklabels=target_names, # cmap='Blues' ) plt.fig(dpi=200) plt.title('Confusion matrix: '+Title) plt.ylabel('Actual class') plt.xlabel('Predicted class') plt.tight_layout() ## plt.savefig('./images/confmat.png', dpi=300) plt.show()
def plot_acc(x, train, val): fig = plt.fig() fig.suptitle('training and validation accuracy') axis = fig.add_subplot(111) axis.set_ylim(0, 50) axis.set_xlim(0, 1) plt.plot(x, train, c='r', label='Training Accuracy') plt.plot(x, val, c='g', label='Validation Accuracy') axis.set_xlabel('Epochs') axis.set_ylabel('Accuracy') axis.legend() plt.savefig('/home/users/traviscwelch/cifarplot.png')
def plot_featured(*args, **kwargs): """ Wrapper for matplotlib.pyplot.plot() / errorbar(). Takes options: * 'error': if true, use :func:`matplotlib.pyplot.errorbar` instead of :func:`matplotlib.pyplot.plot`. *\*args* and *\*\*kwargs* passed through here. * 'fig': figure to use. * 'figlabel': figure label. * 'legend': legend location. * 'toplabel': top label of plot. * 'xlabel': x-label of plot. * 'ylabel': y-label of plot. """ # Strip off options specific to plot_featured toplabel = kwargs.pop('toplabel', None) xlabel = kwargs.pop('xlabel', None) ylabel = kwargs.pop('ylabel', None) legend = kwargs.pop('legend', None) error = kwargs.pop('error', None) # save = kwargs.pop('save', False) figlabel = kwargs.pop('figlabel', None) fig = kwargs.pop('fig', None) if figlabel is not None: fig = _figure(figlabel) elif fig is None: try: fig = _plt.gcf() except: fig = _plt.fig() # Pass everything else to plot if error is None: _plt.plot(*args, **kwargs) else: _plt.errorbar(*args, **kwargs) # Format plot as desired _addlabel(toplabel, xlabel, ylabel, fig=fig) if legend is not None: _plt.legend(legend) return fig
def plot_featured(*args,**kwargs): """Wrapper for matplotlib.pyplot.plot()/errorbar(). Example: plot_featured(x,y,[arguments to matplotlib.pyplot.plot()/errorbar()], [toplabel=],[xlabel=],[ylabel=], [legend=], [error=] ) """ # Strip off options specific to plot_featured toplabel = kwargs.pop('toplabel',None) xlabel = kwargs.pop('xlabel',None) ylabel = kwargs.pop('ylabel',None) legend = kwargs.pop('legend',None) error = kwargs.pop('error',None) save = kwargs.pop('save',False) figlabel = kwargs.pop('figlabel',None) fig = kwargs.pop('fig',None) if not (figlabel == None): fig=_figure(figlabel) elif fig==None: try: fig=_plt.gcf() except: fig=_plt.fig() # Pass everything else to plot if ( error == None ): _plt.plot(*args,**kwargs) else: _plt.errorbar(*args,**kwargs) # Format plot as desired _addlabel(toplabel,xlabel,ylabel) if ( legend != None ): _plt.legend(legend) return fig
import matplotlib.pyplot as plt def F(x, t): x, xp = X xpp = -wO**2 * x - w0 / Q * xp Xp = np.array([xp, xpp]) return Xp w0 = 10. Q = 1. X = np.array([1., 0.]) N = 1000 t0, t1 = 0., 10. t = np.linspace(t0, t1, N) Lx = np.zeros(N) #séquence pour x Lxp = np.zeros(N) #séquence pour xp Lx[0], Lxp[0] = X #CI for i in range(N): h = t[n] - t[n - 1] X = X + F(x, t[n - 1]) * h Lx[n] = X[0] Lxp[n] = X[1] fig = plt.fig() #Chronogramme plt.plot(t, Lx) plt.show() fig = plt.figure() #Portrait de phase plt.plot() plt.show()
Created on Sun Aug 13 22:19:22 2017 @author: VX """ # 圖像 import matplotlib.pyplot as plt import numpy as np def f(x): return x**2 x = np.linspace(-10, 10, 100) x1 = np.linspace(-10, 10, 5) '''plt.fig、plt.plot 用法 plt.fig(num=編號, figsize=(長,寬)) plt.plot(x, y, color='顏色' ,linewidth=線粗, linestyle='樣式') ''' plt.figure(num=2, figsize=(5, 8)) plt.plot(x, f(x), color='red', linewidth=5, linestyle='--') # 下面演示簡易打法 plt.figure(3, (5, 8)) plt.plot(x, f(x), 'g--', linewidth=10) # 在線上加上點,不需要分開打 # 太麻煩 plt.figure() plt.plot(x, f(x), 'r')
""" import numpy as np import matplotlib.pyplot as plt from info import Patch from binary_search import BFS patch = Patch('/Users/zhiyiwu/Documents/pharmfit/12061415.csv') patch.scan() cluster = patch[1] opening = cluster.open_period log_opening = np.log10(opening) plt.hist(log_opening) sep_open = sorted(BFS(log_opening[:, np.newaxis])) print(sep_open) shutting = cluster.shut_period plt.hist(np.log10(shutting)) log_shutting = np.log10(shutting) plt.hist(log_shutting) sep_shut = sorted(BFS(log_shutting[:, np.newaxis])) print(sep_shut) period = cluster.period fig = plt.fig() for i in range(10): ax = fig.add_subplot(10,1,i+1) plt
import matplotlib.pyplot as plt import sys import chrombits from matplotlib_venn import venn3, venn3_circles import fileinput import copy arr=chrombits.ChromosomeLocationBitArrays(sys.argv[1]) A_arr = copy.deepcopy(arr) B_arr = copy.deepcopy(arr) C_arr = copy.deepcopy(arr) A_arr.set_bits_from_file(sys.argv[2]) B_arr.set_bits_from_file(sys.argv[3]) C_arr.set_bits_from_file(sys.argv[4]) A_arr.Start_End_Bed(sys.argv[2]) B_arr.Start_End_Bed(sys.argv[3]) C_arr.Start_End_Bed(sys.argv[4]) union_table = A_arr.union(B_arr).union(C_arr) print union_table plt.fig() v = venn3(subsets = union_table, set_labels = ("CTCF, BEAF, Su(HW)")) plt.savefig("union_venn.png")
import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation import imageio import os data = np.loadtxt("rungekutta.dat") t = data[0] x = data[1] y = data[2] plt.fig() plt.plot(x, y) plt.title('Trayectoria de la particula') plt.xlabel('Coordenada X') plt.ylabel('Coordenada Y') plt.savefig('LaraDaniel_final_15.pdf') plt.show()