本文整理汇总了Python中matplotlib.pyplot.hexbin函数的典型用法代码示例。如果您正苦于以下问题:Python hexbin函数的具体用法?Python hexbin怎么用?Python hexbin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hexbin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cnt_map
def cnt_map(region, table = 'sample', draw = True):
"""Draw a region map of tweets"""
twt_lst = dataset.loadrows(GEOTWEET, ('lat', 'lng'),
('MBRContains({0}, geo)'.format(dataset.geo_rect(*region)),), table)
lat = list();
lng = list();
for twt in twt_lst:
lat.append(twt['lat'])
lng.append(twt['lng'])
if draw:
x = np.array(lng)
y = np.array(lat)
xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()
plt.hexbin(x,y, gridsize=200, cmap=cm.jet)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("Hexagon binning")
cb = plt.colorbar()
cb.set_label('counts')
plt.show()
return lat, lng
示例2: MakeFigures
def MakeFigures(pool, firsts, others):
"""Creates several figures for the book."""
# plot CDFs of birth ages for first babies and others
line_options = [
dict(linewidth=0.5),
dict(linewidth=0.5)
]
myplot.Cdfs([firsts.age_cdf, others.age_cdf],
root='nsfg_age_cdf',
line_options=line_options,
title="Mother's age CDF",
xlabel='age (years)',
ylabel='probability')
# make a scatterplot of ages and weights
ages, weights = GetAgeWeight(pool)
pyplot.clf()
#pyplot.scatter(ages, weights, alpha=0.2)
pyplot.hexbin(ages, weights, cmap=matplotlib.cm.gray_r)
myplot.Save(root='age_scatter',
xlabel='Age (years)',
ylabel='Birth weight (oz)',
legend=False)
示例3: psych_chart
def psych_chart(T, W=None, RH=None, heatplot=False, lims = (0, 90, 0, 0.02), **kwargs):
if (W==None) & (RH==None):
return None # TODO exception?
elif W==None:
W = humidity_ratio(RH, T)
fig = plt.figure()
if heatplot:
plt.hexbin(T, W, extent=lims, **kwargs)
else:
plt.scatter(T, W, **kwargs)
ts = np.linspace(lims[0],lims[1],21)
if heatplot:
linecolor = 'w'
else:
linecolor = 'k'
for rh in np.linspace(0.1,1,10):
plt.plot(ts, humidity_ratio(rh, ts), linecolor)
plt.xlabel('Temperature [degF]')
plt.ylabel('Humidity Ratio')
plt.ylim(lims[2], lims[3])
plt.xlim(lims[0], lims[1])
# RH labels on right hand side
ax1 = plt.axes()
ax2 = ax1.twinx()
ax2.get_yaxis().set_major_locator(ticker.FixedLocator(humidity_ratio(np.linspace(0,1,11), lims[1])/(lims[3]-lims[2])))
ax2.get_yaxis().set_major_formatter(ticker.FixedFormatter(np.linspace(0,100,11)))
plt.ylabel('Relative Humidity [%]')
return ax1
示例4: SummarizeWeight
def SummarizeWeight(rows, input_limit=None):
years = [1981, 1982, 1985, 1986, 1988, 1989, 1990, 1992,
1993, 1994, 1996, 1998, 2000, 2002, 2004, 2006, 2008]
all_diffs = []
for i, row in enumerate(rows):
if i == input_limit:
break
id, race, sex = row[:3]
weights = row[3:]
print id
diffs = Differences(years, weights, jitter=3)
all_diffs.extend(diffs)
weights, changes = zip(*all_diffs)
print 'Mean weight', thinkstats.Mean(weights)
print 'Mean change', thinkstats.Mean(changes)
print numpy.corrcoef(weights, changes)
pyplot.hexbin(weights, changes, cmap=matplotlib.cm.gray_r)
myplot.Save('nlsy_scatter',
title = 'Weight change vs. weight',
xlabel = 'Current weight (pounds)',
ylabel = 'Weight change (pounds)',
axis = [70, 270, -25, 25],
legend=False,
show=True,
)
示例5: _hex_bin
def _hex_bin(root, heights, weights, cmap=matplotlib.cm.Blues):
pyplot.hexbin(heights, weights, cmap=cmap)
_05_myplot._save(root=root,
xlabel='Height (cm)',
ylabel='Weight (kg)',
axis=[140, 210, 20, 200],
legend=False)
示例6: draw2
def draw2():
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
n = 100000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()
plt.subplots_adjust(hspace=0.5)
plt.subplot(121)
plt.hexbin(x, y, cmap=plt.cm.YlOrRd_r)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("Hexagon binning")
cb = plt.colorbar()
cb.set_label('counts')
plt.subplot(122)
plt.hexbin(x, y, bins='log', cmap=plt.cm.YlOrRd_r)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("With a log color scale")
cb = plt.colorbar()
cb.set_label('log10(N)')
plt.show()
示例7: make_figure
def make_figure(standard_id, scores, collection):
print_fig_info()
fig_file = os.path.join(args.output, '{0}_{1}_{2}.pdf'.format(args.db, collection, standard_id))
x = [100.0 - s[0] for s in scores]
y = [s[1] for s in scores]
xmin = min(x)
xmax = max(x)
ymin = min(y)
# ymax = max(y)
# plot params
plt.subplots_adjust(hspace=0.95)
plt.subplot(111)
plt.hexbin(x, y, bins='log', cmap=mpl.cm.jet, mincnt=2, gridsize=100)
plt.title(standard_id, fontsize=18)
# set and label axes
plt.axis([xmin-2, xmax+2, ymin-2, 102])
# plt.gca().invert_xaxis()
plt.xlabel('Germline divergence')
plt.ylabel('{0} identity'.format(standard_id))
# make and label the colorbar
cb = plt.colorbar()
cb.set_label('Sequence count (log10)', labelpad=10)
# save figure and close
plt.savefig(fig_file)
plt.close()
print_done()
示例8: rama_plot
def rama_plot(selection='all', from_state=1, to_state=1, step=1, scatter=True):
"""
Makes a scatter plot with the phi and psi angle pairs
"""
first, last = pose_from_pdb(selection)
if first or last:
bonds = get_glyco_bonds(first, last)
con_matrix = writer(bonds)
phi = []
psi = []
for state in range(from_state, to_state+1, step):
for element in con_matrix:
phi.append(get_phi(selection, element, state))
psi.append(get_psi(selection, element, state))
if scatter:
plt.scatter(phi, psi)
else:
gridsize=100
#gridsize = int(2*len(phi)**(1/3))
#if gridsize < 36:
# gridsize = 36
plt.hexbin(phi, psi, gridsize=gridsize, cmap=plt.cm.summer, mincnt=1)
plt.xlabel('$\phi$', fontsize=16)
plt.ylabel('$\psi$', fontsize=16, rotation=0)
plt.xlim(-180, 180)
plt.ylim(-180, 180)
plt.show()
示例9: chunks
def chunks():
kincr = []
pincr = []
for doc in collection.find(parms):
ktr = trajectory(doc['_id'],False,False,'karma')
tr = trajectory(doc['_id'],False,False)
for i in range(1,len(tr)):
kincr.append(ktr[i] - ktr[i-1])
pincr.append(tr[i] - tr[i-1])
#log scaler
nkincr = []
for k in kincr:
if k < 0: nkincr.append(-log(-k+1))
elif k == 0: nkincr.append(0)
elif k > 0 : nkincr.append(log(k+1))
npincr = []
for p in pincr:
if p < 0: npincr.append(-log(-p+1))
elif p == 0: npincr.append(0)
elif p > 0 : npincr.append(log(p+1))
plt.hexbin(npincr,nkincr,bins='log',mincnt=1)
plt.colorbar()
plt.title('Trajectory movement')
plt.xlabel('log scaled change of position')
plt.ylabel('log scaled change of karma')
plt.show()
示例10: main
def main():
print "Loading file ..."
with open("inverse_kinematics.txt", "rb") as handle:
iv = pickle.loads(handle.read())
print "Done."
coord_x = []
coord_y = []
for coord in iv.keys():
for _ in range(len(iv[coord])):
coord_x.append(coord[0])
coord_y.append(coord[1])
x = np.array(coord_x)
y = np.array(coord_y)
xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()
gridsize = 60
plt.hexbin(x, y, gridsize=gridsize, cmap=plt.cm.jet, bins=None)
plt.axis([xmin, xmax, ymin, ymax])
plt.subplot(111)
cb = plt.colorbar()
plt.show()
示例11: plot_column_pair
def plot_column_pair(i, num_columns, save_dir, titles, data, gmm_means, refcoords):
for j in range(i+1, num_columns):
plt.hexbin(data[:,i], data[:,j], bins = 'log', mincnt=1)
print(gmm_means)
print(gmm_means[i])
print(gmm_means[j])
for mean in gmm_means[i]:
plt.axvline(x=mean,color='k',ls='dashed')
for mean in gmm_means[j]:
plt.axhline(y=mean,color='k',ls='dashed')
if refcoords is not None:
plt.scatter([refcoords[0,i]], [refcoords[0,j]], marker = 's', c='w',s=15)
plt.scatter([refcoords[1,i]], [refcoords[1,j]], marker = 'v', c='k',s=15)
if titles is not None:
pp = PdfPages("%s/%s_%s.pdf" %(save_dir, titles[i], titles[j]))
plt.xlabel(titles[i])
plt.ylabel(titles[j])
pp.savefig()
pp.close()
plt.clf()
else:
pp = PdfPages("%s/tIC.%d_tIC.%d.pdf" %(save_dir, i+1, j+1))
plt.xlabel("tIC.%d" %(i+1))
plt.ylabel("tIC.%d" %(j+1))
pp.savefig()
pp.close()
plt.clf()
示例12: bivar_hexbin_latlon
def bivar_hexbin_latlon(lat, lon):
fig, ax = plt.subplots(figsize=(13, 7))
# set major ticks every 20
x_major_ticks = np.arange(0, 361, 20)
ax.set_xticks(x_major_ticks)
y_major_ticks = np.arange(-90, 91, 10)
ax.set_yticks(y_major_ticks)
ax.set_xlim([0, 360])
ax.set_ylim([-90, 90])
plt.hexbin(lon,
lat,
gridsize=140,
cmap=mpl.cm.plasma,
bins=None)
cb = plt.colorbar()
cb.set_label('Frequency')
ax.set_title("Crater Distribution on Mars Surface (System: Planetocentric)",fontsize=14)
ax.set_xlabel("LONGITUDE East (degrees)",fontsize=12)
ax.set_ylabel("LATITUDE (degrees)",fontsize=12)
# show plot figure
#plt.show()
# save plot figure
filename = 'graph_6.png'
plt.savefig(filename, dpi = 150)
plt.close()
示例13: my_plot_histogram_hexbin
def my_plot_histogram_hexbin(x, y,
bins='log',
gridsize=None,
ttitle="", txlabel='x', tylabel='y', ymin=None,
file_name=None):
"""Plot a 2d-histogram using hexbins
"""
fig = plt.figure(figsize = (9,8))
ax = fig.add_subplot(111)
xdata = x.ravel()
ydata = y.ravel()
if gridsize is not None:
plt.hexbin(xdata,ydata,cmap=plt.cm.gray_r,bins='log',gridsize=gridsize)
else:
plt.hexbin(xdata,ydata,cmap=plt.cm.gray_r,bins='log')
plt.colorbar()
plt.title(ttitle, color='k')
if ymin is not None:
ax.set_ylim(ymin,np.max(ydata))
plt.xlabel(txlabel)
plt.ylabel(tylabel)
if file_name is not None:
plt.savefig(file_name)
plt.show()
return 1
示例14: main
def main():
trajs = load_trajs()
pca = fit_pca(trajs)
cmap2 = matplotlib.cm.hot_r
#cmap1 = brewer2mpl.get_map('OrRd', 'Sequential', 9).mpl_colormap
for i, mfn in enumerate(model_fns):
msm = MarkovStateModel.load(mfn)
try:
X = np.vstack([trajs[str(t)] for t in msm.traj_filenames])
except KeyError as e:
logging.exception('Not found? round %d', i)
continue
X_reduced = pca.transform(X)
pp.hexbin(X_reduced[:,0], X_reduced[:,1], cmap=cmap2, bins='log',
vmin=0, vmax=VMAX)
pp.xlabel('PC 1')
pp.ylabel('PC 2')
pp.title('Round %d PCA: %d frames' % (i, X_reduced.shape[0]))
pp.xlim(*XLIM)
pp.ylim(*YLIM)
cb = pp.colorbar()
cb.set_label('log10(N)')
fn = 'plot_%04d.png' % i
print fn
pp.savefig(fn)
pp.clf()
subprocess.check_output('echo y | avconv -i plot_%04d.png -c:v libx264 -preset slow -crf 1 output.avi', shell=True)
示例15: plot_tica_and_clusters
def plot_tica_and_clusters(component_j, transformed_data, clusterer, lag_time, component_i, label = "dot", active_cluster_ids = [], intermediate_cluster_ids = [], inactive_cluster_ids = [], tica_dir = ""):
trajs = np.concatenate(transformed_data)
plt.hexbin(trajs[:,component_i], trajs[:,component_j], bins='log', mincnt=1)
plt.xlabel("tIC %d" %(component_i + 1))
plt.ylabel('tIC %d' %(component_j+1))
centers = clusterer.cluster_centers_
indices = [j for j in range(0,len(active_cluster_ids),1)]
for i in [active_cluster_ids[j] for j in indices]:
center = centers[i,:]
if label == "dot":
plt.scatter([center[component_i]],[center[component_j]], marker='v', c='k', s=10)
else:
plt.annotate('%d' %i, xy=(center[component_i],center[component_j]), xytext=(center[component_i], center[component_j]),size=6)
indices = [j for j in range(0,len(intermediate_cluster_ids),5)]
for i in [intermediate_cluster_ids[j] for j in indices]:
center = centers[i,:]
if label == "dot":
plt.scatter([center[component_i]],[center[component_j]], marker='8', c='m', s=10)
else:
plt.annotate('%d' %i, xy=(center[component_i],center[component_j]), xytext=(center[component_i], center[component_j]),size=6)
indices = [j for j in range(0,len(inactive_cluster_ids),5)]
for i in [inactive_cluster_ids[j] for j in indices]:
center = centers[i,:]
if label == "dot":
plt.scatter([center[component_i]],[center[component_j]], marker='s', c='w', s=10)
else:
plt.annotate('%d' %i, xy=(center[component_i],center[component_j]), xytext=(center[component_i], center[component_j]),size=6)
pp = PdfPages("%s/c%d_c%d_clusters%d.pdf" %(tica_dir, component_i, component_j, np.shape(centers)[0]))
pp.savefig()
pp.close()
plt.clf()