本文整理汇总了Python中matplotlib.pyplot.axis方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.axis方法的具体用法?Python pyplot.axis怎么用?Python pyplot.axis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.axis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: demo_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def demo_plot():
audio = './data/esc10/audio/Dog/1-30226-A.ogg'
y, sr = librosa.load(audio, sr=44100)
y_ps = librosa.effects.pitch_shift(y, sr, n_steps=6) # n_steps控制音调变化尺度
y_ts = librosa.effects.time_stretch(y, rate=1.2) # rate控制时间维度的变换尺度
plt.subplot(311)
plt.plot(y)
plt.title('Original waveform')
plt.axis([0, 200000, -0.4, 0.4])
# plt.axis([88000, 94000, -0.4, 0.4])
plt.subplot(312)
plt.plot(y_ts)
plt.title('Time Stretch transformed waveform')
plt.axis([0, 200000, -0.4, 0.4])
plt.subplot(313)
plt.plot(y_ps)
plt.title('Pitch Shift transformed waveform')
plt.axis([0, 200000, -0.4, 0.4])
# plt.axis([88000, 94000, -0.4, 0.4])
plt.tight_layout()
plt.show()
示例2: plot_confusion_matrix
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def plot_confusion_matrix(y_true, y_pred, size=None, normalize=False):
"""plot_confusion_matrix."""
cm = confusion_matrix(y_true, y_pred)
fmt = "%d"
if normalize:
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
fmt = "%.2f"
xticklabels = list(sorted(set(y_pred)))
yticklabels = list(sorted(set(y_true)))
if size is not None:
plt.figure(figsize=(size, size))
heatmap(cm, xlabel='Predicted label', ylabel='True label',
xticklabels=xticklabels, yticklabels=yticklabels,
cmap=plt.cm.Blues, fmt=fmt)
if normalize:
plt.title("Confusion matrix (norm.)")
else:
plt.title("Confusion matrix")
plt.gca().invert_yaxis()
示例3: save_frames
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def save_frames(images, filename):
num_sequences, n_steps, w, h = images.shape
fig = plt.figure()
im = plt.imshow(combine_multiple_img(images[:, 0]), cmap=plt.cm.get_cmap('Greys'), interpolation='none')
plt.axis('image')
def updatefig(*args):
im.set_array(combine_multiple_img(images[:, args[0]]))
return im,
ani = animation.FuncAnimation(fig, updatefig, interval=500, frames=n_steps)
# Either avconv or ffmpeg need to be installed in the system to produce the videos!
try:
writer = animation.writers['avconv']
except KeyError:
writer = animation.writers['ffmpeg']
writer = writer(fps=3)
ani.save(filename, writer=writer)
plt.close(fig)
示例4: plot_roc_curve
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def plot_roc_curve(y_true, y_score, size=None):
"""plot_roc_curve."""
false_positive_rate, true_positive_rate, thresholds = roc_curve(
y_true, y_score)
if size is not None:
plt.figure(figsize=(size, size))
plt.axis('equal')
plt.plot(false_positive_rate, true_positive_rate, lw=2, color='navy')
plt.plot([0, 1], [0, 1], color='gray', lw=1, linestyle='--')
plt.xlabel('False positive rate')
plt.ylabel('True positive rate')
plt.ylim([-0.05, 1.05])
plt.xlim([-0.05, 1.05])
plt.grid()
plt.title('Receiver operating characteristic AUC={0:0.2f}'.format(
roc_auc_score(y_true, y_score)))
示例5: plot_num_recall
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def plot_num_recall(recalls, proposal_nums):
"""Plot Proposal_num-Recalls curve.
Args:
recalls(ndarray or list): shape (k,)
proposal_nums(ndarray or list): same shape as `recalls`
"""
if isinstance(proposal_nums, np.ndarray):
_proposal_nums = proposal_nums.tolist()
else:
_proposal_nums = proposal_nums
if isinstance(recalls, np.ndarray):
_recalls = recalls.tolist()
else:
_recalls = recalls
import matplotlib.pyplot as plt
f = plt.figure()
plt.plot([0] + _proposal_nums, [0] + _recalls)
plt.xlabel('Proposal num')
plt.ylabel('Recall')
plt.axis([0, proposal_nums.max(), 0, 1])
f.show()
示例6: plot_iou_recall
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def plot_iou_recall(recalls, iou_thrs):
"""Plot IoU-Recalls curve.
Args:
recalls(ndarray or list): shape (k,)
iou_thrs(ndarray or list): same shape as `recalls`
"""
if isinstance(iou_thrs, np.ndarray):
_iou_thrs = iou_thrs.tolist()
else:
_iou_thrs = iou_thrs
if isinstance(recalls, np.ndarray):
_recalls = recalls.tolist()
else:
_recalls = recalls
import matplotlib.pyplot as plt
f = plt.figure()
plt.plot(_iou_thrs + [1.0], _recalls + [0.])
plt.xlabel('IoU')
plt.ylabel('Recall')
plt.axis([iou_thrs.min(), 1, 0, 1])
f.show()
示例7: plot_time_series
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def plot_time_series(vals_bxtxn, bidx=None, n_to_plot=np.inf, scale=1.0,
color='r', title=None):
if bidx is None:
vals_txn = np.mean(vals_bxtxn, axis=0)
else:
vals_txn = vals_bxtxn[bidx,:,:]
T, N = vals_txn.shape
if n_to_plot > N:
n_to_plot = N
plt.plot(vals_txn[:,0:n_to_plot] + scale*np.array(range(n_to_plot)),
color=color, lw=1.0)
plt.axis('tight')
if title:
plt.title(title)
示例8: adjacencyToLaplacian
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def adjacencyToLaplacian(W):
"""
adjacencyToLaplacian: Computes the Laplacian from an Adjacency matrix
Input:
W (np.array): adjacency matrix
Output:
L (np.array): Laplacian matrix
"""
# Check that the matrix is square
assert W.shape[0] == W.shape[1]
# Compute the degree vector
d = np.sum(W, axis = 1)
# And build the degree matrix
D = np.diag(d)
# Return the Laplacian
return D - W
示例9: normalizeAdjacency
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def normalizeAdjacency(W):
"""
NormalizeAdjacency: Computes the degree-normalized adjacency matrix
Input:
W (np.array): adjacency matrix
Output:
A (np.array): degree-normalized adjacency matrix
"""
# Check that the matrix is square
assert W.shape[0] == W.shape[1]
# Compute the degree vector
d = np.sum(W, axis = 1)
# Invert the square root of the degree
d = 1/np.sqrt(d)
# And build the square root inverse degree matrix
D = np.diag(d)
# Return the Normalized Adjacency
return D @ W @ D
示例10: print_mutation
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def print_mutation(hyp, results, bucket=''):
# Print mutation results to evolve.txt (for use with train.py --evolve)
a = '%10s' * len(hyp) % tuple(hyp.keys()) # hyperparam keys
b = '%10.3g' * len(hyp) % tuple(hyp.values()) # hyperparam values
c = '%10.3g' * len(results) % results # results (P, R, mAP, F1, test_loss)
print('\n%s\n%s\nEvolved fitness: %s\n' % (a, b, c))
if bucket:
os.system('gsutil cp gs://%s/evolve.txt .' % bucket) # download evolve.txt
with open('evolve.txt', 'a') as f: # append result
f.write(c + b + '\n')
x = np.unique(np.loadtxt('evolve.txt', ndmin=2), axis=0) # load unique rows
np.savetxt('evolve.txt', x[np.argsort(-fitness(x))], '%10.3g') # save sort by fitness
if bucket:
os.system('gsutil cp evolve.txt gs://%s' % bucket) # upload evolve.txt
示例11: plot_images
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def plot_images(imgs, targets, paths=None, fname='images.jpg'):
# Plots training images overlaid with targets
imgs = imgs.cpu().numpy()
targets = targets.cpu().numpy()
# targets = targets[targets[:, 1] == 21] # plot only one class
fig = plt.figure(figsize=(10, 10))
bs, _, h, w = imgs.shape # batch size, _, height, width
bs = min(bs, 16) # limit plot to 16 images
ns = np.ceil(bs ** 0.5) # number of subplots
for i in range(bs):
boxes = xywh2xyxy(targets[targets[:, 0] == i, 2:6]).T
boxes[[0, 2]] *= w
boxes[[1, 3]] *= h
plt.subplot(ns, ns, i + 1).imshow(imgs[i].transpose(1, 2, 0))
plt.plot(boxes[[0, 2, 2, 0, 0]], boxes[[1, 1, 3, 3, 1]], '.-')
plt.axis('off')
if paths is not None:
s = Path(paths[i]).name
plt.title(s[:min(len(s), 40)], fontdict={'size': 8}) # limit to 40 characters
fig.tight_layout()
fig.savefig(fname, dpi=200)
plt.close()
示例12: get_mnist_data
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def get_mnist_data(binarize=False):
"""Puts the MNIST data in the right format."""
(X_train, y_train), (X_test, y_test) = mnist.load_data()
if binarize:
X_test = np.where(X_test >= 10, 1, -1)
X_train = np.where(X_train >= 10, 1, -1)
else:
X_train = (X_train.astype(np.float32) - 127.5) / 127.5
X_test = (X_test.astype(np.float32) - 127.5) / 127.5
X_train = np.expand_dims(X_train, axis=-1)
X_test = np.expand_dims(X_test, axis=-1)
y_train = np.expand_dims(y_train, axis=-1)
y_test = np.expand_dims(y_test, axis=-1)
return (X_train, y_train), (X_test, y_test)
示例13: test
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def test(self):
list_ = os.listdir("./maps/val/")
nums_file = list_.__len__()
saver = tf.train.Saver(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, "generator"))
saver.restore(self.sess, "./save_para/model.ckpt")
rand_select = np.random.randint(0, nums_file)
INPUTS_CONDITION = np.zeros([1, self.img_h, self.img_w, 3])
INPUTS = np.zeros([1, self.img_h, self.img_w, 3])
img = np.array(Image.open(self.path + list_[rand_select]))
img_h, img_w = img.shape[0], img.shape[1]
INPUTS_CONDITION[0] = misc.imresize(img[:, img_w//2:], [self.img_h, self.img_w]) / 127.5 - 1.0
INPUTS[0] = misc.imresize(img[:, :img_w//2], [self.img_h, self.img_w]) / 127.5 - 1.0
[fake_img] = self.sess.run([self.inputs_fake], feed_dict={self.inputs_condition: INPUTS_CONDITION})
out_img = np.concatenate((INPUTS_CONDITION[0], fake_img[0], INPUTS[0]), axis=1)
Image.fromarray(np.uint8((out_img + 1.0)*127.5)).save("./results/1.jpg")
plt.imshow(np.uint8((out_img + 1.0)*127.5))
plt.grid("off")
plt.axis("off")
plt.show()
示例14: generator
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def generator(self, inputs_condition):
inputs = inputs_condition
with tf.variable_scope("generator", reuse=tf.AUTO_REUSE):
inputs1 = leaky_relu(conv2d("conv1", inputs, 64, 5, 2))#128x128x128
inputs2 = leaky_relu(instanceNorm("in1", conv2d("conv2", inputs1, 128, 5, 2)))#64x64x256
inputs3 = leaky_relu(instanceNorm("in2", conv2d("conv3", inputs2, 256, 5, 2)))#32x32x512
inputs4 = leaky_relu(instanceNorm("in3", conv2d("conv4", inputs3, 512, 5, 2)))#16x16x512
inputs5 = leaky_relu(instanceNorm("in4", conv2d("conv5", inputs4, 512, 5, 2)))#8x8x512
inputs6 = leaky_relu(instanceNorm("in5", conv2d("conv6", inputs5, 512, 5, 2)))#4x4x512
inputs7 = leaky_relu(instanceNorm("in6", conv2d("conv7", inputs6, 512, 5, 2)))#2x2x512
inputs8 = leaky_relu(instanceNorm("in7", conv2d("conv8", inputs7, 512, 5, 2)))#1x1x512
outputs1 = tf.nn.relu(tf.concat([tf.nn.dropout(instanceNorm("in9", deconv2d("dconv1", inputs8, 512, 5, 2)), 0.5), inputs7], axis=3)) # 2x2x512
outputs2 = tf.nn.relu(tf.concat([tf.nn.dropout(instanceNorm("in10", deconv2d("dconv2", outputs1, 512, 5, 2)), 0.5), inputs6], axis=3)) # 4x4x512
outputs3 = tf.nn.relu(tf.concat([tf.nn.dropout(instanceNorm("in11", deconv2d("dconv3", outputs2, 512, 5, 2)), 0.5), inputs5], axis=3))#8x8x512
outputs4 = tf.nn.relu(tf.concat([instanceNorm("in12", deconv2d("dconv4", outputs3, 512, 5, 2)), inputs4], axis=3))#16x16x512
outputs5 = tf.nn.relu(tf.concat([instanceNorm("in13", deconv2d("dconv5", outputs4, 256, 5, 2)), inputs3], axis=3))#32x32x256
outputs6 = tf.nn.relu(tf.concat([instanceNorm("in14", deconv2d("dconv6", outputs5, 128, 5, 2)), inputs2], axis=3))#64x64x128
outputs7 = tf.nn.relu(tf.concat([instanceNorm("in15", deconv2d("dconv7", outputs6, 64, 5, 2)), inputs1], axis=3))#128x128x64
outputs8 = tf.nn.tanh((deconv2d("dconv8", outputs7, 3, 5, 2)))#256x256x3
return outputs8
示例15: _demo_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import axis [as 别名]
def _demo_plot(learning_curve_output, teststats, trainstats=None, take=None):
testcurve = [teststats['initialerrors']]
for rulescore in teststats['rulescores']:
testcurve.append(testcurve[-1] - rulescore)
testcurve = [1 - x/teststats['tokencount'] for x in testcurve[:take]]
traincurve = [trainstats['initialerrors']]
for rulescore in trainstats['rulescores']:
traincurve.append(traincurve[-1] - rulescore)
traincurve = [1 - x/trainstats['tokencount'] for x in traincurve[:take]]
import matplotlib.pyplot as plt
r = list(range(len(testcurve)))
plt.plot(r, testcurve, r, traincurve)
plt.axis([None, None, None, 1.0])
plt.savefig(learning_curve_output)