def plot(self):
pl.figure(figsize = (8, 8))
pl.plot(self.t,self.theta)
pl.plot(self.t,self.theta, 'c')
pl.ylim(-4, 4)
pl.xlim(0, 10)
pl.ylabel('$\\theta$ (radians)')
pl.xlabel('time (yr)')
pl.title('Hyperion $\\theta$ versus time')
pl.text(4.1, 3.5, 'Elliptical orbit')
python类text()的实例源码
11 py3.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
11 py2.py 文件源码
项目:computational_physics_N2014301020117
作者: yukangnineteen
项目源码
文件源码
阅读 30
收藏 0
点赞 0
评论 0
def plot(self):
pl.figure(figsize = (8, 8))
pl.plot(self.t,self.omega, 'c')
pl.ylim(0, 15)
pl.xlim(0, 8)
pl.ylabel('$\\omega$ (radians/yr)')
pl.xlabel('time (yr)')
pl.title('Hyperion $\\omega$ versus time')
pl.text(3.3, 13.5, 'Circular orbit')
def DrawStr(s):
pl.figure
pl.text(0,0,s)
pl.show()
pl.close()
def text(x, y, s, fontdict=None, withdash=False, **kwargs):
pl.text(x, y, s, fontdict, withdash, **kwargs)
def drawHessDiagram(self,catalog=None):
ax = plt.gca()
if not catalog: catalog = self.get_stars()
r_peak = self.kernel.extension
angsep = ugali.utils.projector.angsep(self.ra, self.dec, catalog.ra, catalog.dec)
cut_inner = (angsep < r_peak)
cut_annulus = (angsep > 0.5) & (angsep < 1.) # deg
mmin, mmax = 16., 24.
cmin, cmax = -0.5, 1.0
mbins = np.linspace(mmin, mmax, 150)
cbins = np.linspace(cmin, cmax, 150)
color = catalog.color[cut_annulus]
mag = catalog.mag[cut_annulus]
h, xbins, ybins = numpy.histogram2d(color, mag, bins=[cbins,mbins])
blur = nd.filters.gaussian_filter(h.T, 2)
kwargs = dict(extent=[xbins.min(),xbins.max(),ybins.min(),ybins.max()],
cmap='gray_r', aspect='auto', origin='lower',
rasterized=True, interpolation='none')
ax.imshow(blur, **kwargs)
pylab.scatter(catalog.color[cut_inner], catalog.mag[cut_inner],
c='red', s=7, edgecolor='none')# label=r'$r < %.2f$ deg'%(r_peak))
ugali.utils.plotting.drawIsochrone(self.isochrone, c='b', zorder=10)
ax.set_xlim(-0.5, 1.)
ax.set_ylim(24., 16.)
plt.xlabel(r'$g - r$')
plt.ylabel(r'$g$')
plt.xticks([-0.5, 0., 0.5, 1.])
plt.yticks(numpy.arange(mmax - 1., mmin - 1., -1.))
radius_string = (r'${\rm r}<%.1f$ arcmin'%( 60 * r_peak))
pylab.text(0.05, 0.95, radius_string,
fontsize=10, ha='left', va='top', color='red',
transform=pylab.gca().transAxes,
bbox=dict(facecolor='white', alpha=1., edgecolor='none'))
c10_20_6_figures.py 文件源码
项目:Python-for-Finance-Second-Edition
作者: PacktPublishing
项目源码
文件源码
阅读 31
收藏 0
点赞 0
评论 0
def graph(text,text2=''):
pl.xticks(())
pl.yticks(())
pl.xlim(0,30)
pl.ylim(0,20)
pl.plot([x,x],[0,3])
pl.text(x,-2,"X");
pl.text(0,x,"X")
pl.text(x,x*1.7, text, ha='center', va='center',size=10, alpha=.5)
pl.text(-5,10,text2,size=25)
def plot(self, output=None):
"""
Plot the statistics.
INPUT: None
OUTPUT: None
SIDE EFFECTS: Generates a plot, depending on the output mode of pylab
this may open a ne window.
"""
fig = pylab.figure()
ax1 = fig.add_subplot(111)
ax1.set_xlabel(self.mode[1])
ax1.set_ylabel('MB/s')
ax1.set_xlim([0,self.loop+0.5])
ax1.bar(where(self.y>=0)[0]+0.1,self.y)
ax1.xaxis.axes.set_autoscalex_on(False)
ax1.plot([0,self.loop+0.5],[median(self.y[where(self.y > 0)]),
median(self.y[where(self.y > 0)])])
ax1.plot([0,self.loop+0.5],[mean(self.y[where(self.y > 0)]),
mean(self.y[where(self.y > 0)])])
pylab.text(0.02,0.95,'Median: %5.2f MB/s'
% median(self.y[where(self.y > 0)]),
transform = ax1.transAxes,ha='left', va='bottom', color='b',
fontsize=10)
pylab.text(0.02,0.95,'Mean: %5.2f MB/s'
% mean(self.y[where(self.y > 0)]),
transform = ax1.transAxes,ha='left', va='top', color='g',
fontsize=10)
ax2 = ax1.twinx()
ax2.xaxis.axes.set_autoscalex_on(False)
ax2.plot(where(self.n>=0)[0]+0.5,self.n,'r-', marker='o')
for tl in ax2.get_yticklabels():
tl.set_color('r')
ax2.set_ylabel('Number of files',{'color':'r'})
if self.mode[1] == 'Day':
fig.canvas.set_window_title('%s: %s' % (self.db,self.date))
ax2.set_title('%s %s ingest rate: %s' % (self.db, self.mode[0], self.date))
else:
fig.canvas.set_window_title('%s: %s' % (self.db,self.date))
ax2.set_title('%s %s ingest rate: %s' % (self.db, self.mode[0], self.date))
pylab.text(0.99,0.95,'Total: %5.2f TB' % self.tvol,transform = ax1.transAxes,ha='right', va='bottom')
pylab.text(0.99,0.95,'Total # files: %8d' % self.tfils,transform = ax1.transAxes,ha='right', va='top')
if (output is not None):
fig.savefig(output)
else:
fig.show()
#pl.close(fig)
def fast_load(self, file_name):
file_name = file_name + "_extra"
with open(file_name, 'rb') as f:
(self.current_run, self.current_patient, self.patients[self.current_patient].current_voxel) = pickle.load(f)
# Patient.find_patients()
# b = Batch_balanced(Patient.patients_list[0:10], 17)
# b.start_iteration()
#
# k = 10000
# (X, y) = b.get_batch(k, two_class=True)
# b.stop_iteration()
#
#
# print("done ")
# print(X.shape)
# print(y.shape)
#
# for i in range(0, k):
# plt.imshow(X[i][0], cmap = "Greys_r")
# plt.text(0, 0, "class : "+str(y[i]), color = "r")
# plt.show()
#
# b.set_current_location(1, 140, 0, 0)
#
# b.start_iteration()
#
#
# print(b.get_current_location())
# print(b.has_next_batch())
# x, y = b.get_batch(10000000)
# print(x.shape)
# print(b.patients[b.current_patient].get_current_input())
# print(b.patients[b.current_patient].get_current_location())
# print(b.get_current_location())
# print(b.has_next_batch())
#
# b.stop_iteration()
plot_recallPrecision.py 文件源码
项目:breaking_cycles_in_noisy_hierarchies
作者: zhenv5
项目源码
文件源码
阅读 33
收藏 0
点赞 0
评论 0
def plotPrecisionRecallDiagram(title="title", points=None, labels=None, loc="best",xy_ranges = [0.6, 1.0, 0.6, 1.0], save_file = None):
"""Plot (precision,recall) values with 10 f-Measure equipotential lines.
Plots into the current canvas.
Points is a list of (precision,recall) pairs.
Optionally you can also provide labels (list of strings), which will be
used to create a legend, which is located at loc.
"""
if labels:
ax = pl.axes([0.1, 0.1, 0.7, 0.8]) # llc_x, llc_y, width, height
else:
ax = pl.gca()
pl.title(title)
pl.xlabel("Precision")
pl.ylabel("Recall")
_plotFMeasures(start = min(xy_ranges[0],xy_ranges[2]), end = max(xy_ranges[1],xy_ranges[3]))
if points:
getColor = it.cycle(colors).next
getMarker = it.cycle(markers).next
scps = [] # scatter points
for i, (x, y) in enumerate(points):
label = None
if labels:
label = labels[i]
print i, x, y, label
scp = ax.scatter(x, y, label=label, s=50, linewidths=0.75,
facecolor=getColor(), alpha=0.75, marker=getMarker())
scps.append(scp)
# pl.plot(x,y, label=label, marker=getMarker(), markeredgewidth=0.75, markerfacecolor=getColor())
# if labels: pl.text(x, y, label, fontsize="x-small")
if labels:
# pl.legend(scps, labels, loc=loc, scatterpoints=1, numpoints=1, fancybox=True) # passing scps & labels explicitly to work around a bug with legend seeming to miss out the 2nd scatterplot
#pl.legend(scps, labels, loc=(1.01, 0), scatterpoints=1, numpoints=1, fancybox=True) # passing scps & labels explicitly to work around a bug with legend seeming to miss out the 2nd scatterplot
pl.legend(scps, labels, loc= loc, scatterpoints=1, numpoints=1, fancybox=True,fontsize = 10) # passing scps & labels explicitly to work around a bug with legend seeming to miss out the 2nd scatterplot
pl.axis(xy_ranges) # xmin, xmax, ymin, ymax
if save_file:
pl.savefig(save_file)
pl.show()
pl.close()
def drawMembersCMD(self,data):
ax = plt.gca()
if isinstance(data,basestring):
filename = data
data = pyfits.open(filename)[1].data
xmin, xmax = -0.25,0.25
ymin, ymax = -0.25,0.25
mmin, mmax = 16., 24.
cmin, cmax = -0.5, 1.0
mbins = np.linspace(mmin, mmax, 150)
cbins = np.linspace(cmin, cmax, 150)
mag_1 = data[self.config['catalog']['mag_1_field']]
mag_2 = data[self.config['catalog']['mag_2_field']]
x_prob, y_prob = sphere2image(self.ra, self.dec, data['RA'], data['DEC'])
sel = (x_prob > xmin)&(x_prob < xmax) & (y_prob > ymin)&(y_prob < ymax)
sel_prob = data['PROB'][sel] > 5.e-2
index_sort = numpy.argsort(data['PROB'][sel][sel_prob])
plt.scatter(data['COLOR'][sel][~sel_prob], mag_1[sel][~sel_prob],
marker='o',s=2,c='0.75',edgecolor='none')
sc = pylab.scatter(data['COLOR'][sel][sel_prob][index_sort], mag_1[sel][sel_prob][index_sort],
c=data['PROB'][sel][sel_prob][index_sort],
marker='o', s=10, edgecolor='none', cmap='jet', vmin=0., vmax=1)
pylab.xlim(cmin, cmax)
pylab.ylim(mmax, mmin)
pylab.xlabel(r'$g - r$')
pylab.ylabel(r'$g$')
#axes[1].yaxis.set_major_locator(MaxNLocator(prune='lower'))
pylab.xticks([-0.5, 0., 0.5, 1.])
pylab.yticks(numpy.arange(mmax - 1., mmin - 1., -1.))
ugali.utils.plotting.drawIsochrone(self.isochrone, c='k', zorder=10)
pylab.text(0.05, 0.95, r'$\Sigma p_{i} = %i$'%(data['PROB'].sum()),
fontsize=10, horizontalalignment='left', verticalalignment='top', color='k', transform=pylab.gca().transAxes,
bbox=dict(facecolor='white', alpha=1., edgecolor='none'))
divider = make_axes_locatable(pylab.gca())
ax_cb = divider.new_horizontal(size="7%", pad=0.1)
plt.gcf().add_axes(ax_cb)
pylab.colorbar(sc, cax=ax_cb, orientation='vertical', ticks=[0, 0.2, 0.4, 0.6, 0.8, 1.0], label='Membership Probability')
ax_cb.yaxis.tick_right()
def plotTriangle(srcfile,samples,burn=0,**kwargs):
#import triangle
import corner
import ugali.analysis.source
import ugali.analysis.mcmc
#matplotlib.rcParams.update({'text.usetex': True})
source = ugali.analysis.source.Source()
source.load(srcfile,section='source')
params = source.get_params()
results = yaml.load(open(srcfile))['results']
samples = ugali.analysis.mcmc.Samples(samples)
names = samples.names
labels = names
truths = [params[n] for n in names]
chain = samples.get(burn=burn,clip=5)
### Triangle plot
#extents = [[0,15e3],[323.6,323.8],[-59.8,-59.7],[0,0.1],[19.5,20.5]]
kwargs.setdefault('extents',None)
kwargs.setdefault('plot_contours',True)
kwargs.setdefault('plot_datapoints',True)
kwargs.setdefault('verbose',False)
kwargs.setdefault('quantiles',[0.16,0.84])
if len(names) > 1:
fig = corner.corner(chain,labels=labels,truths=truths,**kwargs)
else:
fig = plt.figure()
plt.hist(chain,bins=100)
plt.xlabel(names[0])
try:
text = 'RA,DEC = (%.2f,%.2f)\n'%(results['ra'][0],results['dec'][0])
text += '(m-M,D) = (%.1f, %.0f kpc)\n'%(results['distance_modulus'][0],results['distance'][0])
text += r'$r_h$ = %.1f arcmin'%(results['extension_arcmin'][0])+'\n'
text += 'TS = %.1f\n'%results['ts'][0]
text += 'NSamples = %i\n'%(len(chain))
#plt.figtext(0.65,0.90,text,ha='left',va='top')
except KeyError as e:
logger.warning(str(e))
pass
label = map(str.capitalize,source.name.split('_'))
label[-1] = label[-1].upper()
title = '%s'%' '.join(label)
plt.suptitle(title)
############################################################