本文整理汇总了Python中pylab.scatter函数的典型用法代码示例。如果您正苦于以下问题:Python scatter函数的具体用法?Python scatter怎么用?Python scatter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了scatter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_pr_scatter_plots
def generate_pr_scatter_plots(
query_prf, subject_prf, query_color="b", subject_color="r", x_label="Precision", y_label="Recall"
):
""" Generate scatter plot of precision versus recall for query and subject results
query_prf: precision, recall, and f-measure values as returned
from compute_prfs for query data
subject_prf: precision, recall, and f-measure values as returned
from compute_prfs for subject data
query_color: the color of the query points (defualt: blue)
subject_color: the color of the subject points (defualt: red)
x_label: x axis label for the plot (default: "Precision")
y_label: y axis label for the plot (default: "Recall")
"""
# Extract the query precisions and recalls and
# generate a scatter plot
query_precisions = [e[4] for e in query_prf]
query_recalls = [e[5] for e in query_prf]
scatter(query_precisions, query_recalls, c=query_color)
# Extract the subject precisions and recalls and
# generate a scatter plot
subject_precisions = [e[4] for e in subject_prf]
subject_recalls = [e[5] for e in subject_prf]
scatter(subject_precisions, subject_recalls, c=subject_color)
xlim(0, 1)
ylim(0, 1)
xlabel(x_label)
ylabel(y_label)
示例2: plotslice
def plotslice(pos,filename='',boxsize=100.):
ng = pos.shape[0]
M.clf()
M.scatter(pos[ng/4,:,:,1].flatten(),pos[ng/4,:,:,2].flatten(),s=1.,lw=0.)
M.axis('tight')
if filename != '':
M.savefig(filename)
示例3: geweke_plot
def geweke_plot(data, name, format='png', suffix='-diagnostic', path='./', fontmap = None,
verbose=1):
# Generate Geweke (1992) diagnostic plots
if fontmap is None: fontmap = {1:10, 2:8, 3:6, 4:5, 5:4}
# Generate new scatter plot
figure()
x, y = transpose(data)
scatter(x.tolist(), y.tolist())
# Plot options
xlabel('First iteration', fontsize='x-small')
ylabel('Z-score for %s' % name, fontsize='x-small')
# Plot lines at +/- 2 sd from zero
pyplot((nmin(x), nmax(x)), (2, 2), '--')
pyplot((nmin(x), nmax(x)), (-2, -2), '--')
# Set plot bound
ylim(min(-2.5, nmin(y)), max(2.5, nmax(y)))
xlim(0, nmax(x))
# Save to file
if not os.path.exists(path):
os.mkdir(path)
if not path.endswith('/'):
path += '/'
savefig("%s%s%s.%s" % (path, name, suffix, format))
示例4: plot_polynomial_regression
def plot_polynomial_regression():
rng = np.random.RandomState(0)
x = 2*rng.rand(100) - 1
f = lambda t: 1.2 * t**2 + .1 * t**3 - .4 * t **5 - .5 * t ** 9
y = f(x) + .4 * rng.normal(size=100)
x_test = np.linspace(-1, 1, 100)
pl.figure()
pl.scatter(x, y, s=4)
X = np.array([x**i for i in range(5)]).T
X_test = np.array([x_test**i for i in range(5)]).T
regr = linear_model.LinearRegression()
regr.fit(X, y)
pl.plot(x_test, regr.predict(X_test), label='4th order')
X = np.array([x**i for i in range(10)]).T
X_test = np.array([x_test**i for i in range(10)]).T
regr = linear_model.LinearRegression()
regr.fit(X, y)
pl.plot(x_test, regr.predict(X_test), label='9th order')
pl.legend(loc='best')
pl.axis('tight')
pl.title('Fitting a 4th and a 9th order polynomial')
pl.figure()
pl.scatter(x, y, s=4)
pl.plot(x_test, f(x_test), label="truth")
pl.axis('tight')
pl.title('Ground truth (9th order polynomial)')
示例5: pseudoSystem
def pseudoSystem():
#The corrolations discovered when answering this question shows the emergent effects of component evolution on CSE.
#We can further study these correlations by creating an example component system consisting of many components where a a different component has a new version released every day.
#By looking at users who Upgrade the system at different frequencies over 100 days, we present two graphs, Upgrade frequency to uttd and change.
l = 100
uttdxy = []
chxy = []
for uf in range(1,20):
uttd = range(uf)*(l*2/uf)
uttd = uttd[1:l+1]
uttdxy.append((uf,numpy.mean(uttd)))
sh = [0]*(uf-1) + [uf]
sh = sh*l
sh = sh[:l]
chxy.append((uf,sum(sh)))
pylab.figure(20)
x,y = zip(*sorted(uttdxy))
pylab.plot(x,y)
pylab.scatter(x,y)
saveFigure("q1bpseudouttd")
pylab.figure(21)
x,y = zip(*sorted(chxy))
pylab.plot(x,numpy.array(y))
pylab.scatter(x,numpy.array(y))
pylab.ylim([0,l+10])
saveFigure("q1bpseudochange")
示例6: test
def test():
from pandas import DataFrame
X = np.linspace(0.01, 1.0, 10)
Y = np.log(X)
Y -= Y.min()
Y /= Y.max()
Y *= 0.95
#Y = X
df = DataFrame({'X': X, 'Y': Y})
P = Pareto(df, 'X', 'Y')
data = []
for val in np.linspace(0,1,15):
data.append(dict(val=val, x=P.lookup_x(val), y=P.lookup_y(val)))
pl.axvline(val, alpha=.5)
pl.axhline(val, alpha=.5)
dd = DataFrame(data)
pl.scatter(dd.y, dd.val, lw=0, c='r')
pl.scatter(dd.val, dd.x, lw=0, c='g')
print dd
#P.scatter(c='r', lw=0)
P.show_frontier(c='r', lw=4)
pl.show()
示例7: plot_values
def plot_values(X, Y, xlabel, ylabel, suffix, ptype='plot'):
output_filename = constants.ATTRACTIVENESS_FOLDER_NAME + constants.DATASET + '_' + suffix
X1 = [X[i] for i in range(len(X)) if X[i]>0 and Y[i]>0]
Y1 = [Y[i] for i in range(len(X)) if X[i]>0 and Y[i]>0]
X = X1
Y = Y1
pylab.close("all")
pylab.figure(figsize=(8, 7))
#pylab.rcParams.update({'font.size': 20})
pylab.scatter(X, Y)
#pylab.axis(vis.get_bounds(X, Y, False, False))
#pylab.xscale('log')
pylab.yscale('log')
pylab.xlabel(xlabel)
pylab.ylabel(ylabel)
#pylab.xlim(0.1,1)
#pylab.ylim(ymin=0.01)
#pylab.tight_layout()
pylab.savefig(output_filename + '.pdf')
示例8: plot_contour
def plot_contour(X, X1, X2, clf, title):
pl.figure()
pl.title(title)
# Plot instances of class 1.
pl.plot(X1[:, 0], X1[:, 1], "ro")
# Plot instances of class 2.
pl.plot(X2[:, 0], X2[:, 1], "bo")
# Select "support vectors".
if hasattr(clf, "support_vectors_"):
sv = clf.support_vectors_
else:
sv = X[clf.coef_.ravel() != 0]
# Plot support vectors.
pl.scatter(sv[:, 0], sv[:, 1], s=100, c="g")
# Plot decision surface.
A, B = np.meshgrid(np.linspace(-6, 6, 50), np.linspace(-6, 6, 50))
C = np.array([[x1, x2] for x1, x2 in zip(np.ravel(A), np.ravel(B))])
Z = clf.decision_function(C).reshape(A.shape)
pl.contour(A, B, Z, [0.0], colors="k", linewidths=1, origin="lower")
pl.axis("tight")
示例9: scatter_from_csv
def scatter_from_csv(self, filename, sand = 'sand', silt = 'silt', clay = 'clay', diameter = '', hue = '', tags = '', **kwargs):
"""Loads data from filename (expects csv format). Needs one header row with at least the columns {sand, silt, clay}. Can also plot two more variables for each point; specify the header value for columns to be plotted as diameter, hue. Can also add a text tag offset from each point; specify the header value for those tags.
Note! text values (header entries, tag values ) need to be quoted to be recognized as text. """
fh = file(filename, 'rU')
soilrec = csv2rec(fh)
count = 0
if (sand in soilrec.dtype.names):
count = count + 1
if (silt in soilrec.dtype.names):
count = count + 1
if (clay in soilrec.dtype.names):
count = count + 1
if (count < 3):
print "ERROR: need columns for sand, silt and clay identified in ', filename"
locargs = {'s': None, 'c': None}
for (col, key) in ((diameter, 's'), (hue, 'c')):
col = col.lower()
if (col != '') and (col in soilrec.dtype.names):
locargs[key] = soilrec.field(col)
else:
print 'ERROR: did not find ', col, 'in ', filename
for k in kwargs:
locargs[k] = kwargs[k]
values = zip(*[soilrec.field(sand), soilrec.field(clay), soilrec.field(silt)])
print values
(xs, ys) = self._toCart(values)
p.scatter(xs, ys, label='_', **locargs)
if (tags != ''):
tags = tags.lower()
for (x, y, tag) in zip(*[xs, ys, soilrec.field(tags)]):
print x,
print y,
print tag
p.text(x + 1, y + 1, tag, fontsize=12)
fh.close()
示例10: plot
def plot(self):
f = pylab.figure(figsize=(8,4))
co = [] #colors container
for zScore, r in itertools.izip(self.zScores, self.log2Ratio):
if zScore < self.pCut:
if r > 0:
co.append(Colors().greenColor)
elif r < 0:
co.append(Colors().redColor)
else:
raise Exception
else:
co.append(Colors().blueColor)
#print "Probability this is from a normal distribution: %.3e" %stats.normaltest(self.log2Ratio)[1]
ax = f.add_subplot(121)
pylab.axvline(self.meanLog2Ratio, color=Colors().redColor)
pylab.axvspan(self.meanLog2Ratio-(2*self.stdLog2Ratio),
self.meanLog2Ratio+(2*self.stdLog2Ratio), color=Colors().blueColor, alpha=0.2)
his = pylab.hist(self.log2Ratio, bins=50, color=Colors().blueColor)
pylab.xlabel("log2 Ratio %s/%s" %(self.sampleNames[1], self.sampleNames[0]))
pylab.ylabel("Frequency")
ax = f.add_subplot(122, aspect='equal')
pylab.scatter(self.genes1, self.genes2, c=co, alpha=0.5)
pylab.ylabel("%s RPKM" %self.sampleNames[1])
pylab.xlabel("%s RPKM" %self.sampleNames[0])
pylab.yscale('log')
pylab.xscale('log')
pylab.tight_layout()
示例11: genderBoxplots
def genderBoxplots(self, women, men, labels, path):
data = [women.edition_count.values, men.edition_count.values]
plt.figure()
plt.boxplot(data)
# mark the mean
means = [np.mean(x) for x in data]
print(means)
plt.scatter(range(1, len(data) + 1), means, color="red", marker=">", s=20)
plt.ylabel("num editions")
plt.xticks(range(1, len(data) + 1), labels)
plt.savefig(
path + "/numeditions_gender_box_withOutlier" + self.pre + "-" + self.post + ".png", bbox_inches="tight"
)
plt.figure()
plt.boxplot(data, sym="")
# mark the mean
means = [np.mean(x) for x in data]
print(means)
plt.scatter(range(1, len(data) + 1), means, color="red", marker=">", s=20)
plt.ylabel("num editions")
plt.xticks(range(1, len(data) + 1), labels)
plt.savefig(path + "/numeditions_gender_box" + self.pre + "-" + self.post + ".png", bbox_inches="tight")
示例12: linearReg
def linearReg():
from sklearn import datasets
diabetes = datasets.load_diabetes()
diabetes_X_train = diabetes.data[:-20]
diabetes_X_test = diabetes.data[-20:]
diabetes_y_train = diabetes.target[:-20]
diabetes_y_test = diabetes.target[-20:]
from sklearn import linear_model
regr = linear_model.LinearRegression()
regr.fit(diabetes_X_train, diabetes_y_train)
print(regr.coef_)
import numpy as np
np.mean((regr.predict(diabetes_X_test) - diabetes_y_test) ** 2)
regr.score(diabetes_X_test, diabetes_y_test)
X = np.c_[.5, 1].T
y = [.5, 1]
test = np.c_[0, 2].T
regr = linear_model.LinearRegression()
import pylab as pl
pl.figure()
np.random.seed(0)
for _ in range(6):
this_X = .1 * np.random.normal(size=(2, 1)) + X
regr.fit(this_X, y)
pl.plot(test, regr.predict(test))
pl.scatter(this_X, y, s=3)
示例13: plot_all
def plot_all(x, y):
pca = PCA(n_components=2)
new_x = pca.fit(x).transform(x)
for i in range(0, len(new_x)):
l_color = color_list[y[i]]
pl.scatter(new_x[i, 0], new_x[i, 1], color=l_color)
pl.show()
示例14: draw_cluster
def draw_cluster(self):
for station in self.cluster.stations:
for detector in station.detectors:
x, y = detector.get_xy_coordinates()
plt.scatter(x, y, c='r', s=5, edgecolor='none')
x, y, alpha = station.get_xyalpha_coordinates()
plt.scatter(x, y, c='orange', s=10, edgecolor='none')
示例15: plot
def plot(n):
h = heighway(n)
x, y = [], []
for z in h:
x.append(z.real), y.append(z.imag)
scatter(x, y)
show()