Python matplotlib.pyplot.hist() Examples
The following are 30
code examples of matplotlib.pyplot.hist().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.pyplot
, or try the search function
.
Example #1
Source File: dataset.py From TheCannon with MIT License | 6 votes |
def diagnostics_SNR(self): """ Plots SNR distributions of ref and test object spectra """ print("Diagnostic for SNRs of reference and survey objects") fig = plt.figure() data = self.test_SNR plt.hist(data, bins=int(np.sqrt(len(data))), alpha=0.5, facecolor='r', label="Survey Objects") data = self.tr_SNR plt.hist(data, bins=int(np.sqrt(len(data))), alpha=0.5, color='b', label="Ref Objects") plt.legend(loc='upper right') #plt.xscale('log') plt.title("SNR Comparison Between Reference and Survey Objects") #plt.xlabel("log(Formal SNR)") plt.xlabel("Formal SNR") plt.ylabel("Number of Objects") return fig
Example #2
Source File: poincare.py From HRV with MIT License | 6 votes |
def plotRRintHist(RRints): """ Histogram distribution of poincare points projected onto the x-axis Input : - RRints: [list] of RR intervals Output : - RR interval histogram plot """ plt.hist(RRints, bins = 'auto') plt.xlabel('RR Interval') plt.ylabel('Number of RR Intervals') plt.title('RR Interval Histogram') plt.show()
Example #3
Source File: poincare.py From HRV with MIT License | 6 votes |
def plotWidthHist(RRints): """ Histogram distribution of poincare points projected along the direction of line-of-identity, or along the line perpendicular to the line-of-identity. Input : - RRints: [list] of RR intervals Output : - 'Width', or delta-RR interval, histogram plot """ ax1 = RRints[:-1] ax2 = RRints[1:] x1 = (np.cos(np.pi / 4) * ax1) - (np.sin(np.pi / 4) * ax2) plt.hist(x1, bins = 'auto') plt.title('Width (Delta-RR Interval) Histogram') plt.show()
Example #4
Source File: poincare.py From HRV with MIT License | 6 votes |
def plotLengthHist(RRints): """ Histogram distribution of poincare points projected along the line-of-identty. Input : - RRints: [list] of RR intervals Output : - 'Length' histogram plot """ ax1 = RRints[:-1] ax2 = RRints[1:] x2 = (np.sin(np.pi / 4) * ax1) + (np.cos(np.pi / 4) * ax2) plt.hist(x2, bins = 'auto') plt.title('Length Histogram') plt.show()
Example #5
Source File: SpectraLearnPredict.py From SpectralMachine with GNU General Public License v3.0 | 6 votes |
def formatClass(rootFile, Cl): import sklearn.preprocessing as pp print('==========================================================================\n') print(' Running basic TensorFlow. Creating class data in binary form...') Cl2 = pp.LabelBinarizer().fit_transform(Cl) import matplotlib.pyplot as plt plt.hist([float(x) for x in Cl], bins=np.unique([float(x) for x in Cl]), edgecolor="black") plt.xlabel('Class') plt.ylabel('Occurrances') plt.title('Class distibution') plt.savefig(rootFile + '_ClassDistrib.png', dpi = 160, format = 'png') # Save plot if tfDef.plotClassDistribTF == True: print(' Plotting Class distibution \n') plt.show() return Cl2 #********************************************************************************
Example #6
Source File: references.py From qmpy with MIT License | 6 votes |
def journal_view(request, journal_id): journal = Journal.objects.get(id=journal_id) dates = journal.references.values_list('year', flat=True) plt.hist(dates) plt.xlabel('Year') plt.ylabel('# of publications with new materials') img = StringIO.StringIO() plt.savefig(img, dpi=75, bbox_inches='tight') data_uri = 'data:image/jpg;base64,' data_uri += img.getvalue().encode('base64').replace('\n', '') plt.close() some_entries = Entry.objects.filter(reference__journal=journal)[:20] data = get_globals() data.update({'journal':journal, 'hist':data_uri, 'entries':some_entries}) return render_to_response('data/reference/journal.html', data, RequestContext(request))
Example #7
Source File: analysis.py From metal with Apache License 2.0 | 6 votes |
def plot_probabilities_histogram(Y_probs, title=None): """Plot a histogram from a numpy array of probabilities Args: Y_probs: An [n] or [n, 1] np.ndarray of probabilities (floats in [0,1]) """ if Y_probs.ndim > 1: print("Plotting probabilities from the first column of Y_probs") Y_probs = Y_probs[:, 0] plt.hist(Y_probs, bins=20) plt.xlim((0, 1.025)) plt.xlabel("Probability") plt.ylabel("# Predictions") if isinstance(title, str): plt.title(title) plt.show()
Example #8
Source File: analysis.py From metal with Apache License 2.0 | 6 votes |
def plot_predictions_histogram(Y_preds, Y_gold, title=None): """Plot a histogram comparing int predictions vs true labels by class Args: Y_gold: An [n] or [n, 1] np.ndarray of gold labels Y_preds: An [n] or [n, 1] np.ndarray of predicted int labels """ labels = list(set(Y_gold).union(set(Y_preds))) edges = [x - 0.5 for x in range(min(labels), max(labels) + 2)] plt.hist([Y_preds, Y_gold], bins=edges, label=["Predicted", "Gold"]) ax = plt.gca() ax.set_xticks(labels) plt.xlabel("Label") plt.ylabel("# Predictions") plt.legend(loc="upper right") if isinstance(title, str): plt.title(title) plt.show()
Example #9
Source File: demo.py From Clustering with MIT License | 6 votes |
def plot_histogram(lfw_dir): """ Function to plot the distribution of cluster sizes in LFW. """ filecount_dict = {} for root, dirs, files in os.walk(lfw_dir): for dirname in dirs: n_photos = len(os.listdir(os.path.join(root, dirname))) filecount_dict[dirname] = n_photos print("No of unique people: {}".format(len(filecount_dict.keys()))) df = pd.DataFrame(filecount_dict.items(), columns=['Name', 'Count']) print("Singletons : {}\nTwo :{}\n".format((df['Count'] == 1).sum(), (df['Count'] == 2).sum())) plt.hist(df['Count'], bins=max(df['Count'])) plt.title('Cluster Sizes') plt.xlabel('No of images in folder') plt.ylabel('No of folders') plt.show()
Example #10
Source File: analyze_data.py From Machine-Translation with Apache License 2.0 | 6 votes |
def analyze_en(): translation_path = os.path.join(train_translation_folder, train_translation_en_filename) with open(translation_path, 'r') as f: sentences = f.readlines() sent_lengths = [] for sentence in tqdm(sentences): sentence_en = sentence.strip().lower() tokens = [normalizeString(s) for s in nltk.word_tokenize(sentence_en)] seg_list = list(jieba.cut(sentence.strip())) # Update word frequency sent_lengths.append(len(seg_list)) num_bins = 100 n, bins, patches = plt.hist(sent_lengths, num_bins, facecolor='blue', alpha=0.5) title = 'English Sentence Lengths Distribution' plt.title(title) plt.show()
Example #11
Source File: analyze_data.py From Machine-Translation with Apache License 2.0 | 6 votes |
def analyze_zh(): translation_path = os.path.join(train_translation_folder, train_translation_zh_filename) with open(translation_path, 'r') as f: sentences = f.readlines() sent_lengths = [] for sentence in tqdm(sentences): seg_list = list(jieba.cut(sentence.strip())) # Update word frequency sent_lengths.append(len(seg_list)) num_bins = 100 n, bins, patches = plt.hist(sent_lengths, num_bins, facecolor='blue', alpha=0.5) title = 'Chinese Sentence Lengths Distribution' plt.title(title) plt.show()
Example #12
Source File: utils.py From DeepLung with GNU General Public License v3.0 | 6 votes |
def plothistdiameter(trainpath='/media/data1/wentao/tianchi/preprocessing/newtrain/', testpath='/media/data1/wentao/tianchi/preprocessing/newtest/'): diameterlist = [] for fname in os.listdir(trainpath): if fname.endswith('_label.npy'): label = np.load(trainpath+fname) for lidx in xrange(label.shape[0]): diameterlist.append(label[lidx, -1]) for fname in os.listdir(testpath): if fname.endswith('_label.npy'): label = np.load(testpath+fname) for lidx in xrange(label.shape[0]): diameterlist.append(label[lidx, -1]) fig = plt.figure() plt.hist(diameterlist, 50) plt.xlabel('Nodule Diameter') plt.ylabel('# Nodules') plt.title('Nodule Size Histogram') plt.savefig('processnodulesizehist.png')
Example #13
Source File: Sklearn_SVM_Regression.py From Machine-Learning-for-Beginner-by-Python3 with MIT License | 6 votes |
def huitu(suout, shiout, c=['b', 'k'], sign='训练', cudu=3): # 绘制原始数据和预测数据的对比 plt.subplot(2, 1, 1) plt.plot(list(range(len(suout))), suout, c=c[0], linewidth=cudu, label='%s:算法输出' % sign) plt.plot(list(range(len(shiout))), shiout, c=c[1], linewidth=cudu, label='%s:实际值' % sign) plt.legend(loc='best') plt.title('原始数据和向量机输出数据的对比') # 绘制误差和0的对比图 plt.subplot(2, 2, 3) plt.plot(list(range(len(suout))), suout - shiout, c='r', linewidth=cudu, label='%s:误差' % sign) plt.plot(list(range(len(suout))), list(np.zeros(len(suout))), c='k', linewidth=cudu, label='0值') plt.legend(loc='best') plt.title('误差和0的对比') # 需要添加一个误差的分布图 plt.subplot(2, 2, 4) plt.hist(suout - shiout, 50, facecolor='g', alpha=0.75) plt.title('误差直方图') # 显示 plt.show()
Example #14
Source File: utils.py From DeepLung with GNU General Public License v3.0 | 6 votes |
def plotnoduledist(annopath): import pandas as pd df = pd.read_csv(annopath+'train/annotations.csv') diameter = df['diameter_mm'].reshape((-1,1)) df = pd.read_csv(annopath+'val/annotations.csv') diameter = np.vstack([df['diameter_mm'].reshape((-1,1)), diameter]) df = pd.read_csv(annopath+'test/annotations.csv') diameter = np.vstack([df['diameter_mm'].reshape((-1,1)), diameter]) fig = plt.figure() plt.hist(diameter, normed=True, bins=50) plt.ylabel('probability') plt.xlabel('Diameters') plt.title('Nodule Diameters Histogram') plt.savefig('nodulediamhist.png')
Example #15
Source File: distribution_check.py From hydrology with GNU General Public License v3.0 | 6 votes |
def plot(fcts, data): import matplotlib.pyplot as plt import numpy as np # plot data plt.hist(data, normed=True, bins=max(10, len(data)/10)) # plot fitted probability for fct in fcts: params = eval("scipy.stats."+fct+".fit(data)") f = eval("scipy.stats."+fct+".freeze"+str(params)) x = np.linspace(f.ppf(0.001), f.ppf(0.999), 500) plt.plot(x, f.pdf(x), lw=3, label=fct) plt.legend(loc='best', frameon=False) plt.title("Top "+str(len(fcts))+" Results") plt.show()
Example #16
Source File: validation_plots.py From TheCannon with MIT License | 6 votes |
def chisq_dist(): fig = plt.figure(figsize=(6,4)) ivar = np.load("%s/val_ivar_norm.npz" %DATA_DIR)['arr_0'] npix = np.sum(ivar>0, axis=1) chisq = np.load("%s/val_chisq.npz" %DATA_DIR)['arr_0'] redchisq = chisq/npix nbins = 25 plt.hist(redchisq, bins=nbins, color='k', histtype="step", lw=2, normed=False, alpha=0.3, range=(0,3)) plt.legend() plt.xlabel("Reduced $\chi^2$", fontsize=16) plt.tick_params(axis='both', labelsize=16) plt.ylabel("Count", fontsize=16) plt.axvline(x=1.0, linestyle='--', c='k') fig.tight_layout() #plt.show() plt.savefig("chisq_dist.png")
Example #17
Source File: draw_plot.py From TaobaoAnalysis with MIT License | 6 votes |
def draw_quality_histogram(items): """ 画质量直方图 """ from analyze.quality import get_item_quality qualities = [get_item_quality(item) for item in items if len(item.reviews) >= 20] plt.title('质量直方图') plt.xlabel('质量') plt.ylabel('分布密度') plt.hist(qualities, bins=100, range=(0, 1), density=True) # 拟合正态分布 mean = np.mean(qualities) std = np.std(qualities) x = np.arange(0, 1, 0.01) y = stats.norm.pdf(x, loc=mean, scale=std) plt.plot(x, y) plt.text(0, 5, r'$N={},\mu={:.3f},\sigma={:.3f}$' .format(len(qualities), mean, std))
Example #18
Source File: draw_plot.py From TaobaoAnalysis with MIT License | 6 votes |
def draw_sold_quality_plot(items): """ 画销量-质量图 """ from analyze.quality import get_item_quality items = list(filter(lambda item: len(item.reviews) >= 20, items)) qualities = [get_item_quality(item) for item in items] sold_counts = [item.sold_count for item in items] x_limit = (0, 1) y_limit = (0, 1000) ax_histx, ax_histy, ax_scatter = init_scatter_hist(x_limit, y_limit) plt.xlabel('质量') plt.ylabel('销量') # 画图 ax_histx.hist(qualities, bins=100, range=x_limit) ax_histy.hist(sold_counts, bins=100, range=y_limit, orientation='horizontal') ax_scatter.scatter(qualities, sold_counts)
Example #19
Source File: validation_plots.py From TheCannon with MIT License | 6 votes |
def snr_dist(): fig = plt.figure(figsize=(6,4)) tr_snr = np.load("../tr_SNR.npz")['arr_0'] snr = np.load("../val_SNR.npz")['arr_0'] nbins = 25 plt.hist(tr_snr, bins=nbins, color='k', histtype="step", lw=2, normed=True, alpha=0.3, label="Training Set") plt.hist(snr, bins=nbins, color='r', histtype="step", lw=2, normed=True, alpha=0.3, label="Validation Set") plt.legend() plt.xlabel("S/N", fontsize=16) plt.tick_params(axis='both', labelsize=16) plt.ylabel("Normalized Count", fontsize=16) fig.tight_layout() plt.show() #plt.savefig("snr_dist.png")
Example #20
Source File: utils.py From pruning_yolov3 with GNU General Public License v3.0 | 6 votes |
def plot_test_txt(): # from utils.utils import *; plot_test() # Plot test.txt histograms x = np.loadtxt('test.txt', dtype=np.float32) box = xyxy2xywh(x[:, :4]) cx, cy = box[:, 0], box[:, 1] fig, ax = plt.subplots(1, 1, figsize=(6, 6)) ax.hist2d(cx, cy, bins=600, cmax=10, cmin=0) ax.set_aspect('equal') fig.tight_layout() plt.savefig('hist2d.jpg', dpi=300) fig, ax = plt.subplots(1, 2, figsize=(12, 6)) ax[0].hist(cx, bins=600) ax[1].hist(cy, bins=600) fig.tight_layout() plt.savefig('hist1d.jpg', dpi=200)
Example #21
Source File: draw_plot.py From TaobaoAnalysis with MIT License | 6 votes |
def draw_sold_reviews_plot(items): """ 画销量-评论图 """ items = list(items) review_counts = [len(item.reviews) for item in items] sold_counts = [item.sold_count for item in items] x_limit = y_limit = (0, 1000) ax_histx, ax_histy, ax_scatter = init_scatter_hist(x_limit, y_limit) plt.xlabel('评论数') plt.ylabel('销量') # 画图 ax_histx.hist(review_counts, bins=100, range=x_limit) ax_histy.hist(sold_counts, bins=100, range=y_limit, orientation='horizontal') ax_scatter.scatter(review_counts, sold_counts)
Example #22
Source File: pcd_corners_est.py From ILCC with BSD 2-Clause "Simplified" License | 5 votes |
def find_marker(file_path, csv_path, range_res=params['marker_range_limit']): file_list = os.listdir(file_path) res_ls = [] for file in file_list: # print file_path + file if is_marker(file_path + file, range_res): # print file res_ls.append(file_path + file) print len(res_ls) if len(res_ls) == 0: AssertionError("no marker is found") if len(res_ls) > 1: print "one than one candicate of the marker is found!" print res_ls print "The segment with most uniform intensity distribution is considered as the marker" num_ls = [] for file in res_ls: arr = exact_full_marker_data(csv_path, [file]) intensity_arr = arr[:, 3] hist, bin_edges = np.histogram(intensity_arr, 100) if debug: print hist, bin_edges num_ls.append(len(np.nonzero(hist)[0])) res_ls = [res_ls[np.argmax(num_ls)]] if debug: print res_ls assert len(res_ls) == 1 print "marker is found!" return res_ls # get the reflectance information of the chessboard's point cloud
Example #23
Source File: plot.py From neuron with GNU General Public License v3.0 | 5 votes |
def pca(pca, x, y): x_mean = np.mean(x, 0) x_std = np.std(x, 0) W = pca.components_ x_mu = W @ pca.mean_ # pca.mean_ is y_mean y_hat = x @ W + pca.mean_ y_err = y_hat - y y_rel_err = y_err / np.maximum(0.5*(np.abs(y)+np.abs(y_hat)), np.finfo('float').eps) plt.figure(figsize=(15, 7)) plt.subplot(2, 3, 1) plt.plot(pca.explained_variance_ratio_) plt.title('var %% explained') plt.subplot(2, 3, 2) plt.plot(np.cumsum(pca.explained_variance_ratio_)) plt.ylim([0, 1.01]) plt.grid() plt.title('cumvar explained') plt.subplot(2, 3, 3) plt.plot(np.cumsum(pca.explained_variance_ratio_)) plt.ylim([0.8, 1.01]) plt.grid() plt.title('cumvar explained') plt.subplot(2, 3, 4) plt.plot(x_mean) plt.plot(x_mean + x_std, 'k') plt.plot(x_mean - x_std, 'k') plt.title('x mean across dims (sorted)') plt.subplot(2, 3, 5) plt.hist(y_rel_err.flat, 100) plt.title('y rel err histogram') plt.subplot(2, 3, 6) plt.imshow(W @ np.transpose(W), cmap=plt.get_cmap('gray')) plt.colorbar() plt.title('W * W\'') plt.show()
Example #24
Source File: mujoco_dset.py From ICML2019-TREX with MIT License | 5 votes |
def plot(self): import matplotlib.pyplot as plt plt.hist(self.rets) plt.savefig("histogram_rets.png") plt.close()
Example #25
Source File: mujoco_dset.py From ICML2019-TREX with MIT License | 5 votes |
def plot(self): import matplotlib.pyplot as plt plt.hist(self.rets) plt.savefig("histogram_rets.png") plt.close()
Example #26
Source File: mujoco_dset.py From DRL_DeliveryDuel with MIT License | 5 votes |
def plot(self): import matplotlib.pyplot as plt plt.hist(self.rets) plt.savefig("histogram_rets.png") plt.close()
Example #27
Source File: utils.py From nussl with MIT License | 5 votes |
def visualize_gradient_flow(named_parameters, n_bins=50): """ Visualize the gradient flow through the named parameters of a PyTorch model. Plots the gradients flowing through different layers in the net during training. Can be used for checking for possible gradient vanishing / exploding problems. Usage: Plug this function in Trainer class after loss.backwards() as "visualize_gradient_flow(self.model.named_parameters())" to visualize the gradient flow Args: named_parameters (generator): Generator object yielding name and parameters for each layer in a PyTorch model. n_bins (int): Number of bins to use for each histogram. Defaults to 50. """ import matplotlib.pyplot as plt data = [] for n, p in named_parameters: if p.requires_grad and "bias" not in n: if p.grad is not None: _data = p.grad.cpu().data.numpy().flatten() lower = np.percentile(_data, 10) upper = np.percentile(_data, 90) _data = _data[_data >= lower] _data = _data[_data <= upper] n = n.split('layers.')[-1] data.append((n, _data, np.abs(_data).mean())) _data = [d[1] for d in sorted(data, key=lambda x: x[-1])] _names = [d[0] for d in sorted(data, key=lambda x: x[-1])] plt.hist(_data, len(_data) * n_bins, histtype='step', fill=False, stacked=True, label=_names) plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2)
Example #28
Source File: matchdist.py From vnpy_crypto with MIT License | 5 votes |
def plothist(x,distfn, args, loc, scale, right=1): plt.figure() # the histogram of the data n, bins, patches = plt.hist(x, 25, normed=1, facecolor='green', alpha=0.75) maxheight = max([p.get_height() for p in patches]) print(maxheight) axlim = list(plt.axis()) #print(axlim) axlim[-1] = maxheight*1.05 #plt.axis(tuple(axlim)) ## print(bins) ## print('args in plothist', args) # add a 'best fit' line #yt = stats.norm.pdf( bins, loc=loc, scale=scale) yt = distfn.pdf( bins, loc=loc, scale=scale, *args) yt[yt>maxheight]=maxheight lt = plt.plot(bins, yt, 'r--', linewidth=1) ys = stats.t.pdf( bins, 10,scale=10,)*right ls = plt.plot(bins, ys, 'b-', linewidth=1) plt.xlabel('Smarts') plt.ylabel('Probability') plt.title(r'$\mathrm{Testing: %s :}\ \mu=%f,\ \sigma=%f$'%(distfn.name,loc,scale)) #plt.axis([bins[0], bins[-1], 0, 0.134+0.05]) plt.grid(True) plt.draw() #plt.show() #plt.close() #targetdist = ['norm','t','truncnorm','johnsonsu','johnsonsb',
Example #29
Source File: matplotlib_helpers.py From deeplift with MIT License | 5 votes |
def plot_hist(data, bins=None, figsize=(7,7), title="", **kwargs): import matplotlib.pyplot as plt if (bins==None): bins=len(data) plt.figure(figsize=figsize); plt.hist(data, bins=bins, **kwargs) plt.title(title) plt.show()
Example #30
Source File: dataset_sparsity.py From ip_basic with MIT License | 5 votes |
def main(): input_depth_dir = os.path.expanduser( '~/Kitti/depth/val_selection_cropped/velodyne_raw') images_to_use = sorted(glob.glob(input_depth_dir + '/*')) # Process depth images num_images = len(images_to_use) all_sparsities = np.zeros(num_images) for i in range(num_images): # Print progress sys.stdout.write('\rProcessing index {} / {}'.format(i, num_images - 1)) sys.stdout.flush() depth_image_path = images_to_use[i] # Load depth from image depth_image = cv2.imread(depth_image_path, cv2.IMREAD_ANYDEPTH) # Divide by 256 depth_map = depth_image / 256.0 num_valid_pixels = len(np.where(depth_map > 0.0)[0]) num_pixels = depth_image.shape[0] * depth_image.shape[1] sparsity = num_valid_pixels / (num_pixels * 2/3) all_sparsities[i] = sparsity print('') print('Sparsity') print('Min: ', np.amin(all_sparsities)) print('Max: ', np.amax(all_sparsities)) print('Mean: ', np.mean(all_sparsities)) print('Median: ', np.median(all_sparsities)) plt.hist(all_sparsities, bins=20) plt.show()