本文整理汇总了Python中matplotlib.pylab.gca方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.gca方法的具体用法?Python pylab.gca怎么用?Python pylab.gca使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pylab
的用法示例。
在下文中一共展示了pylab.gca方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_feat_importance
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def plot_feat_importance(feature_names, clf, name):
pylab.clf()
coef_ = clf.coef_
important = np.argsort(np.absolute(coef_.ravel()))
f_imp = feature_names[important]
coef = coef_.ravel()[important]
inds = np.argsort(coef)
f_imp = f_imp[inds]
coef = coef[inds]
xpos = np.array(range(len(coef)))
pylab.bar(xpos, coef, width=1)
pylab.title('Feature importance for %s' % (name))
ax = pylab.gca()
ax.set_xticks(np.arange(len(coef)))
labels = ax.set_xticklabels(f_imp)
for label in labels:
label.set_rotation(90)
filename = name.replace(" ", "_")
pylab.savefig(os.path.join(
CHART_DIR, "feat_imp_%s.png" % filename), bbox_inches="tight")
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:23,代码来源:utils.py
示例2: plot_feat_importance
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def plot_feat_importance(feature_names, clf, name):
pylab.figure(num=None, figsize=(6, 5))
coef_ = clf.coef_
important = np.argsort(np.absolute(coef_.ravel()))
f_imp = feature_names[important]
coef = coef_.ravel()[important]
inds = np.argsort(coef)
f_imp = f_imp[inds]
coef = coef[inds]
xpos = np.array(list(range(len(coef))))
pylab.bar(xpos, coef, width=1)
pylab.title('Feature importance for %s' % (name))
ax = pylab.gca()
ax.set_xticks(np.arange(len(coef)))
labels = ax.set_xticklabels(f_imp)
for label in labels:
label.set_rotation(90)
filename = name.replace(" ", "_")
pylab.savefig(os.path.join(
CHART_DIR, "feat_imp_%s.png" % filename), bbox_inches="tight")
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:23,代码来源:utils.py
示例3: format_plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def format_plot(X, epoch=None, title=None, figsize=(15, 10)):
plt.figure(figsize=figsize)
if X.shape[-1] == 1:
plt.imshow(X[:, :, 0], cmap="gray")
else:
plt.imshow(X)
plt.axis("off")
plt.gca().xaxis.set_major_locator(mp.ticker.NullLocator())
plt.gca().yaxis.set_major_locator(mp.ticker.NullLocator())
if epoch is not None and title is None:
save_path = os.path.join(FLAGS.fig_dir, "current_batch_%s.png" % epoch)
elif epoch is not None and title is not None:
save_path = os.path.join(FLAGS.fig_dir, "%s_%s.png" % (title, epoch))
elif title is not None:
save_path = os.path.join(FLAGS.fig_dir, "%s.png" % title)
plt.savefig(save_path, bbox_inches='tight', pad_inches=0)
plt.clf()
plt.close()
示例4: plot_correlations
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def plot_correlations(corrs, errors=None, ax=None, **plot_kwargs):
"""
Correlation vs CCA dimension
:param corrs: correlation values for the CCA dimensions
:type corrs: 1-D vector
:param errors: error values
:type shuffled: 1-D array of size len(corrs)
:param ax: axis to plot on (default None)
:type ax: matplotlib axis object
:return: axis if specified, or plot if axis = None
"""
# evaluate if np.arrays are passed
assert type(corrs) is np.ndarray, "'corrs' is not a numpy array."
if errors is not None:
assert type(errors) is np.ndarray, "'errors' is not a numpy array."
# create axis if no axis is passed
if ax is None:
ax = plt.gca()
# get the data for the x and y axis
y_data = corrs
x_data = range(1, (len(corrs) + 1))
# create the plot object
ax.plot(x_data, y_data, **plot_kwargs)
if errors is not None:
ax.fill_between(x_data, y_data - errors, y_data + errors, **plot_kwargs, alpha=0.2)
# change y and x labels and ticks
ax.set_xticks(x_data)
ax.set_ylabel("Correlation")
ax.set_xlabel("CCA dimension")
return ax
示例5: plot_dt
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def plot_dt(tri, colors=None):
import matplotlib as mpl
from matplotlib import pylab as pl
if colors is None:
colors = [(0, 0, 0, 0.2)]
lc = mpl.collections.LineCollection(
np.array([((tri.x[i], tri.y[i]), (tri.x[j], tri.y[j]))
for i, j in tri.edge_db]),
colors=colors)
ax = pl.gca()
ax.add_collection(lc)
pl.draw_if_interactive()
示例6: plot_vo
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def plot_vo(tri, colors=None):
import matplotlib as mpl
from matplotlib import pylab as pl
if colors is None:
colors = [(0, 1, 0, 0.2)]
lc = mpl.collections.LineCollection(np.array(
[(tri.circumcenters[i], tri.circumcenters[j])
for i in xrange(len(tri.circumcenters))
for j in tri.triangle_neighbors[i] if j != -1]),
colors=colors)
ax = pl.gca()
ax.add_collection(lc)
pl.draw_if_interactive()
示例7: plot_cc
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def plot_cc(tri, edgecolor=None):
import matplotlib as mpl
from matplotlib import pylab as pl
if edgecolor is None:
edgecolor = (0, 0, 1, 0.2)
dxy = (np.array([(tri.x[i], tri.y[i]) for i, j, k in tri.triangle_nodes])
- tri.circumcenters)
r = np.hypot(dxy[:, 0], dxy[:, 1])
ax = pl.gca()
for i in xrange(len(r)):
p = mpl.patches.Circle(tri.circumcenters[i], r[i],
resolution=100, edgecolor=edgecolor,
facecolor=(1, 1, 1, 0), linewidth=0.2)
ax.add_patch(p)
pl.draw_if_interactive()
示例8: plot1D_mat
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def plot1D_mat(a, b, M, title=''):
""" Plot matrix M with the source and target 1D distribution
Creates a subplot with the source distribution a on the left and
target distribution b on the tot. The matrix M is shown in between.
Parameters
----------
a : ndarray, shape (na,)
Source distribution
b : ndarray, shape (nb,)
Target distribution
M : ndarray, shape (na, nb)
Matrix to plot
"""
na, nb = M.shape
gs = gridspec.GridSpec(3, 3)
xa = np.arange(na)
xb = np.arange(nb)
ax1 = pl.subplot(gs[0, 1:])
pl.plot(xb, b, 'r', label='Target distribution')
pl.yticks(())
pl.title(title)
ax2 = pl.subplot(gs[1:, 0])
pl.plot(a, xa, 'b', label='Source distribution')
pl.gca().invert_xaxis()
pl.gca().invert_yaxis()
pl.xticks(())
pl.subplot(gs[1:, 1:], sharex=ax1, sharey=ax2)
pl.imshow(M, interpolation='nearest')
pl.axis('off')
pl.xlim((0, nb))
pl.tight_layout()
pl.subplots_adjust(wspace=0., hspace=0.2)
示例9: plot_learning_curves
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def plot_learning_curves(self, hyperparameter):
if hyperparameter == "TV":
C = self.C_tv_history
elif hyperparameter == "Group L1":
C = self.C_group_l1_history
else:
raise ValueError("hyperparameter value should be either `TV` or"
" `Group L1`")
x = np.log10(C)
order = np.argsort(x)
m = np.array(self.kfold_mean_train_scores)[order]
sd = np.array(self.kfold_sd_train_scores)[order]
fig = plt.figure()
ax = plt.gca()
p1 = ax.plot(x[order], m)
p2 = ax.fill_between(x[order], m - sd, m + sd, alpha=.3)
min_point_train = np.min(m - sd)
m = np.array(self.kfold_mean_test_scores)[order]
sd = np.array(self.kfold_sd_test_scores)[order]
p3 = ax.plot(x[order], m)
p4 = ax.fill_between(x[order], m - sd, m + sd, alpha=.3)
min_point_test = np.min(m - sd)
min_point = min(min_point_train, min_point_test)
p5 = plt.scatter(np.log10(C), min_point * np.ones_like(C))
ax.legend([(p1[0], p2), (p3[0], p4), p5],
['train score', 'test score', 'tested hyperparameters'],
loc='lower right')
ax.set_title('Learning curves')
ax.set_xlabel('C %s (log scale)' % hyperparameter)
ax.set_ylabel('Loss')
return fig, ax
示例10: remove_values_along_axes
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def remove_values_along_axes():
from matplotlib import pylab
frame = pylab.gca()
frame.axes.get_xaxis().set_ticks([])
frame.axes.get_yaxis().set_ticks([])
示例11: newline
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def newline(p1, p2, color):
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
ax = plt.gca()
x_min = p1[0]
x_max = p1[1]
y_min = p2[0]
y_max = p2[1]
logging.info('{} {}'.format([x_min, x_max], [y_min, y_max]))
l = mlines.Line2D([x_min, x_max], [y_min, y_max], color=color, linestyle='dashdot', linewidth=3)
ax.add_line(l)
return l
# plt.ion()
示例12: plot_na
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def plot_na(x,y,mode='stem'):
pylab.figure(figsize=(5,2))
frame1 = pylab.gca()
if mode.lower() == 'stem':
pylab.stem(x,y)
else:
pylab.plot(x,y)
frame1.axes.get_xaxis().set_visible(False)
frame1.axes.get_yaxis().set_visible(False)
pylab.show()
示例13: remove_top_right_on_plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def remove_top_right_on_plot(ax=None):
if ax==None:
ax = plt.gca()
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
示例14: drawpoints
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def drawpoints(points, xmin=None, ymin=None, xmax=None, ymax=None):
skips = np.hstack((np.array([0]),points[:,2]))
xys = np.vstack((np.zeros((1,2)),np.cumsum(points[:,:2],axis=0)))
xys[:,:2] -= xys[:,:2].mean(axis=0)
# xys = points[:,:2]
xs=[]
ys=[]
x=[]
y=[]
for xy,s in zip(xys, skips):
if s:
if len(x) > 1:
xs.append(x)
ys.append(y)
x=[]
y=[]
else:
x.append(xy[0])
y.append(xy[1])
for x,y in zip(xs, ys):
pl.plot(x, y, 'k-')
if xmin is None:
xmin,ymin = xys.min(axis=0)
xmax,ymax = xys.max(axis=0)
ax = pl.gca()
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
ax.invert_yaxis()
ax.set_xticks([])
ax.set_yticks([])
示例15: clean_ticks
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import gca [as 别名]
def clean_ticks():
ax = plt.gca()
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')