本文整理汇总了Python中pylab.hist方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.hist方法的具体用法?Python pylab.hist怎么用?Python pylab.hist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylab
的用法示例。
在下文中一共展示了pylab.hist方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: summary
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def summary(self, Nbest=5, lw=2, plot=True, method="sumsquare_error"):
"""Plots the distribution of the data and Nbest distribution
"""
if plot:
pylab.clf()
self.hist()
self.plot_pdf(Nbest=Nbest, lw=lw, method=method)
pylab.grid(True)
Nbest = min(Nbest, len(self.distributions))
try:
names = self.df_errors.sort_values(
by=method).index[0:Nbest]
except:
names = self.df_errors.sort(method).index[0:Nbest]
return self.df_errors.loc[names]
示例2: plotVerticalHistSummary
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def plotVerticalHistSummary(all_result_outputs, label='', data_label='', y_label='', plot_label='', hist_width=1000, hist_bins=100, oligo_id_str='Oligo ID', val_str = 'Cut Rate', total_reads_str= 'Total Reads'):
datas = [x[0][data_label][0] for x in all_result_outputs]
sample_names = [shortDirLabel(x[1]) for x in all_result_outputs]
merged_data = pd.merge(datas[0],datas[1],how='inner',on=oligo_id_str, suffixes=['', ' 2'])
for i, data in enumerate(datas[2:]):
merged_data = pd.merge(merged_data, data,how='inner',on=oligo_id_str, suffixes=['', ' %d' % (i+3)])
suffix = lambda i: ' %d' % (i+1) if i > 0 else ''
xpos = [x*hist_width for x in range(len(sample_names))]
PL.figure(figsize=(12,8))
for i,label1 in enumerate(sample_names):
dvs = merged_data[val_str + suffix(i)]
PL.hist(dvs, bins=hist_bins, bottom=i*hist_width, orientation='horizontal')
PL.xticks(xpos, sample_names, rotation='vertical')
PL.ylabel(y_label)
PL.title(label)
PL.show(block=False)
PL.savefig(getPlotDir() + '/%s_%s.png' % (plot_label, label.replace(' ','_')), bbox_inches='tight')
示例3: hist_overflow
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def hist_overflow(val, val_max, **kwds):
""" Make a histogram with an overflow bar above val_max """
import pylab, numpy
overflow = len(val[val>=val_max])
pylab.hist(val[val<val_max], **kwds)
if 'color' in kwds:
color = kwds['color']
else:
color = None
if overflow > 0:
rect = pylab.bar(val_max+0.05, overflow, .5, color=color)[0]
pylab.text(rect.get_x(),
1.10*rect.get_height(), '%s+' % val_max)
示例4: show_statistics
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def show_statistics(self):
"""
Shows several statistics of the data. The first plot shows the distribution of the number of cells per node
in the topological representation. The second plot shows the distribution of the number of common cells
between nodes that share an edge in the topological representation. The third plot contains the distribution
of the number of nodes that contain the same cell. Finally, the fourth plot shows the distribution of
transcripts in log_2(1+TPM) scale, after filtering.
"""
x = map(len, self.dic.values())
pylab.figure()
pylab.hist(x, max(x)-1, alpha=0.6, color='b')
pylab.xlabel('Cells per node')
x = []
for q in self.g.edges():
x.append(len(set(self.dic[q[0]]).intersection(self.dic[q[1]])))
pylab.figure()
pylab.hist(x, max(x)-1, alpha=0.6, color='g')
pylab.xlabel('Shared cells between connected nodes')
pel = []
for m in self.dic.values():
pel += list(m)
q = []
for m in range(max(pel)+1):
o = pel.count(m)
if o > 0:
q.append(o)
pylab.figure()
pylab.hist(q, max(q)-1, alpha=0.6, color='r')
pylab.xlabel('Number of nodes containing the same cell')
pylab.figure()
r = []
for m in self.dicgenes.keys():
r += list(self.dicgenes[m])
r = [k for k in r if 30 > k > 0.0]
pylab.hist(r, 100, alpha=0.6)
pylab.xlabel('Expression')
pylab.show()
示例5: pvalhist
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def pvalhist(pv,numbins=50,linewidth=3.0,linespec='--r', figsize=[5,5]):
'''
Plots normalized histogram, plus theoretical null-only line.
'''
h2=pl.figure(figsize=figsize)
[nn,bins,patches]=pl.hist(pv,numbins,normed=True)
pl.plot([0, 1],[1,1],linespec,linewidth=linewidth)
示例6: __init__
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def __init__(self, data=None, X=None, Y=None, bins=None):
""".. rubric:: **Constructor**
One should provide either the parameter **data** alone, or the X and Y
parameters, which are the histogram of some data sample.
:param data: random data
:param X: evenly spaced X data
:param Y: probability density of the data
:param bins: if data is providede, we will compute the probability using
hist function and bins may be provided.
"""
self.data = data
if data:
Y, X, _ = pylab.hist(self.data, bins=bins, density=True)
self.N = len(X) - 1
self.X = [(X[i]+X[i+1])/2 for i in range(self.N)]
self.Y = Y
self.A = 1
self.guess_std = pylab.std(self.data)
self.guess_mean = pylab.mean(self.data)
self.guess_amp = 1
else:
self.X = X
self.Y = Y
self.Y = self.Y / sum(self.Y)
if len(self.X) == len(self.Y) + 1 :
self.X = [(X[i]+X[i+1])/2 for i in range(len(X)-1)]
self.N = len(self.X)
self.guess_mean = self.X[int(self.N/2)]
self.guess_std = sqrt(sum((self.X - mean(self.X))**2)/self.N)/(sqrt(2*3.14))
self.guess_amp = 1.
self.func = self._func_normal
示例7: hist
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def hist(self):
"""Draw normed histogram of the data using :attr:`bins`
.. plot::
>>> from scipy import stats
>>> data = stats.gamma.rvs(2, loc=1.5, scale=2, size=20000)
>>> # We then create the Fitter object
>>> import fitter
>>> fitter.Fitter(data).hist()
"""
_ = pylab.hist(self._data, bins=self.bins, density=self._density)
pylab.grid(True)
示例8: test2
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def test2():
from fitter import HistFit
from pylab import hist
import scipy.stats
data = [scipy.stats.norm.rvs(2,3.4) for x in range(10000)]
Y, X, _ = hist(data, bins=30)
hf = HistFit(X=X, Y=Y)
hf.fit(error_rate=0.03, Nfit=20)
print(hf.mu, hf.sigma, hf.amplitude)
示例9: hist
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def hist(arg):
try:
import pylab
except ImportError:
logger.warning("pylab is not installed and required")
return
plot(pylab.hist(arg)[1])
示例10: run
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def run(opts):
arg_permutations = str(opts.input[0])
perm_tfce_max = np.genfromtxt(arg_permutations, delimiter=',')
p_array=np.zeros(perm_tfce_max.shape)
sorted_perm_tfce_max=sorted(perm_tfce_max, reverse=True)
num_perm=perm_tfce_max.shape[0]
perm_tfce_mean = perm_tfce_max.mean()
perm_tfce_std = perm_tfce_max.std()
perm_tfce_max_val = int(sorted_perm_tfce_max[0])
perm_tfce_min_val = int(sorted_perm_tfce_max[(num_perm-1)])
for j in range(num_perm):
p_array[j] = 1 - np.true_divide(j,num_perm)
sig=int(num_perm*0.05)
firstquater=sorted_perm_tfce_max[int(num_perm*0.75)]
median=sorted_perm_tfce_max[int(num_perm*0.50)]
thirdquater=sorted_perm_tfce_max[int(num_perm*0.25)]
sig_tfce=sorted_perm_tfce_max[sig]
pl.hist(perm_tfce_max, 100, range=[0,perm_tfce_max_val], label='Max TFCE scores')
ylim = pl.ylim()
pl.plot([sig_tfce,sig_tfce], ylim, '--g', linewidth=3,label='P[FWE]=0.05')
pl.text((sig_tfce*1.4),(ylim[1]*.5), r"$\mu=%0.2f,\ \sigma=%0.2f$" "\n" r"$Critical\ TFCE\ value=%0.0f$" "\n" r"$[%d,\ %d,\ %d,\ %d,\ %d]$" % (perm_tfce_mean,perm_tfce_std,sig_tfce,perm_tfce_min_val,firstquater, median, thirdquater, perm_tfce_max_val), size='medium')
pl.ylim(ylim)
pl.legend()
pl.xlabel('Permutation scores')
save("%s.hist" % arg_permutations, ext="png", close=False, verbose=True)
pl.show()
示例11: draw_var
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import hist [as 别名]
def draw_var(self, data, name):
plt.figure(figsize=(12, 9))
ax = plt.subplot(111)
bar_width = 0.5
bar_l = [i + 1 for i in range(len(data))]
tick_pos = [ i + (bar_width/2) for i in bar_l ]
acc = map(lambda a: (a.acc_in*a.tot_in + a.acc_out*a.tot_out)/(a.tot_in + a.tot_out), data)
fp = map(lambda a: float(a.fp_in + a.fp_out)/(a.tot_in + a.tot_out), data)
fn = map(lambda a: float(a.fn_in + a.fn_out)/(a.tot_in + a.tot_out), data)
print("average/standard deviation:")
print("| accuracy: {:.3g}/{:.3g}".format(numpy.mean(acc), numpy.std(acc)))
print("| false positive: {:.3g}/{:.3g}".format(numpy.mean(fp), numpy.std(fp)))
print("| false negative: {:.3g}/{:.3g}".format(numpy.mean(fn), numpy.std(fn)))
ax.bar(bar_l, acc, width=bar_width, label="accuracy",
alpha=1, color=Chart.colors["acc"])
ax.bar(bar_l, fn, width=bar_width, label="false negatives",
alpha=1, bottom=acc, color=Chart.colors["fn"])
ax.bar(bar_l, fp, width=bar_width, label="false positives",
alpha=1, bottom=map(lambda a: a[0] + a[1], zip(acc, fn)), color=Chart.colors["fp"])
# Limit the range of the plot to only where the data is.
# Avoid unnecessary whitespace.
plt.ylim(0.9, 1.01)
plt.xlim(0, len(data) * 1.05)
ax.spines["top"].set_visible(False)
ax.spines["bottom"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["left"].set_visible(False)
# Ensure that the axis ticks only show up on the bottom and left of the plot.
# Ticks on the right and top of the plot are generally unnecessary chartjunk.
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()
plt.xticks(tick_pos, map(lambda a: a.tot_in + a.tot_out, data), rotation="vertical")
plt.tick_params(axis="both", which="both", bottom="off", top="off",
labelbottom="on", left="off", right="off", labelleft="on")
plt.legend()
plt.savefig("test/chart/{}_{}.png".format(self._analysis, name), bbox_inches="tight")
return
P.figure(figsize=(12,9))
P.hist([[10, 20], [1, 5]], 5, stacked=True, histtype='bar')
# plt.plot(range(1, len(data) + 1), acc_in, 'o', lw=1, color=Chart.colors[1], label="accuracy")
# plt.plot(range(1, len(data) + 1), tot_in, 'o', lw=1, color=Chart.colors[3], label="number of functions")
# plt.plot(range(1, len(data) + 1), fp_in, 'o', lw=1, color=Chart.colors[7], label="false positives")
# plt.plot(range(1, len(data) + 1), fn_in, 'o', lw=1, color=Chart.colors[6], label="false negatives")
# plt.legend()
P.savefig("test/chart/{}_{}.png".format(self._analysis, name), bbox_inches="tight")
return