本文整理汇总了Python中matplotlib.pyplot.ylim方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.ylim方法的具体用法?Python pyplot.ylim怎么用?Python pyplot.ylim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.ylim方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_roc_curve
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [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)))
示例2: data_stat
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def data_stat():
"""data statistic"""
audio_path = './data/esc10/audio/'
class_list = [os.path.basename(i) for i in glob(audio_path + '*')]
nums_each_class = [len(glob(audio_path + cl + '/*.ogg')) for cl in class_list]
rects = plt.bar(range(len(nums_each_class)), nums_each_class)
index = list(range(len(nums_each_class)))
plt.title('Numbers of each class for ESC-10 dataset')
plt.ylim(ymax=60, ymin=0)
plt.xticks(index, class_list, rotation=45)
plt.ylabel("numbers")
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width() / 2, height, str(height), ha='center', va='bottom')
plt.tight_layout()
plt.show()
示例3: visualize_2D_trip
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def visualize_2D_trip(self,trip,tw_open,tw_close):
plt.figure(figsize=(30,30))
rcParams.update({'font.size': 22})
# Plot cities
colors = ['red'] # Depot is first city
for i in range(len(tw_open)-1):
colors.append('blue')
plt.scatter(trip[:,0], trip[:,1], color=colors, s=200)
# Plot tour
tour=np.array(list(range(len(trip))) + [0])
X = trip[tour, 0]
Y = trip[tour, 1]
plt.plot(X, Y,"--", markersize=100)
# Annotate cities with TW
tw_open = np.rint(tw_open)
tw_close = np.rint(tw_close)
time_window = np.concatenate((tw_open,tw_close),axis=1)
for tw, (x, y) in zip(time_window,(zip(X,Y))):
plt.annotate(tw,xy=(x, y))
plt.xlim(0,60)
plt.ylim(0,60)
plt.show()
# Heatmap of permutations (x=cities; y=steps)
示例4: visualize_2D_trip
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def visualize_2D_trip(self, trip):
plt.figure(figsize=(30,30))
rcParams.update({'font.size': 22})
# Plot cities
plt.scatter(trip[:,0], trip[:,1], s=200)
# Plot tour
tour=np.array(list(range(len(trip))) + [0])
X = trip[tour, 0]
Y = trip[tour, 1]
plt.plot(X, Y,"--", markersize=100)
# Annotate cities with order
labels = range(len(trip))
for i, (x, y) in zip(labels,(zip(X,Y))):
plt.annotate(i,xy=(x, y))
plt.xlim(0,100)
plt.ylim(0,100)
plt.show()
# Heatmap of permutations (x=cities; y=steps)
示例5: plot_wh_methods
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def plot_wh_methods(): # from utils.utils import *; plot_wh_methods()
# Compares the two methods for width-height anchor multiplication
# https://github.com/ultralytics/yolov3/issues/168
x = np.arange(-4.0, 4.0, .1)
ya = np.exp(x)
yb = torch.sigmoid(torch.from_numpy(x)).numpy() * 2
fig = plt.figure(figsize=(6, 3), dpi=150)
plt.plot(x, ya, '.-', label='yolo method')
plt.plot(x, yb ** 2, '.-', label='^2 power method')
plt.plot(x, yb ** 2.5, '.-', label='^2.5 power method')
plt.xlim(left=-4, right=4)
plt.ylim(bottom=0, top=6)
plt.xlabel('input')
plt.ylabel('output')
plt.legend()
fig.tight_layout()
fig.savefig('comparison.png', dpi=200)
示例6: make_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def make_plot(files, labels):
plt.figure()
for file_idx in range(len(files)):
rot_err, trans_err = read_csv(files[file_idx])
success_dict = count_success(trans_err)
x_range = success_dict.keys()
x_range.sort()
success = []
for i in x_range:
success.append(success_dict[i])
success = np.array(success)/total_cases
plt.plot(x_range, success, linewidth=3, label=labels[file_idx])
# plt.scatter(x_range, success, s=50)
plt.ylabel('Success Ratio', fontsize=40)
plt.xlabel('Threshold for Translation Error', fontsize=40)
plt.tick_params(labelsize=40, width=3, length=10)
plt.grid(True)
plt.ylim(0,1.005)
plt.yticks(np.arange(0,1.2,0.2))
plt.xticks(np.arange(0,2.1,0.2))
plt.xlim(0,2)
plt.legend(fontsize=30, loc=4)
示例7: plot_contour
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def plot_contour(self, w=0.0):
"""
Plot contour with poles of Green's function in the self-energy
SelfEnergy(w) = G(w+w')W(w')
with respect to w' = Re(w')+Im(w')
Poles of G(w+w') are located: w+w'-(E_n-Fermi)+i*eps sign(E_n-Fermi)==0 ==>
w'= (E_n-Fermi) - w -i eps sign(E_n-Fermi)
"""
try :
import matplotlib.pyplot as plt
from matplotlib.patches import Arc, Arrow
except:
print('no matplotlib?')
return
fig,ax = plt.subplots()
fe = self.fermi_energy
ee = self.mo_energy
iee = 0.5-np.array(ee>fe)
eew = ee-fe-w
ax.plot(eew, iee, 'r.', ms=10.0)
pp = list()
pp.append(Arc((0,0),4,4,angle=0, linewidth=2, theta1=0, theta2=90, zorder=2, color='b'))
pp.append(Arc((0,0),4,4,angle=0, linewidth=2, theta1=180, theta2=270, zorder=2, color='b'))
pp.append(Arrow(0,2,0,-4,width=0.2, color='b', hatch='o'))
pp.append(Arrow(-2,0,4,0,width=0.2, color='b', hatch='o'))
for p in pp: ax.add_patch(p)
ax.set_aspect('equal')
ax.grid(True, which='both')
ax.axhline(y=0, color='k')
ax.axvline(x=0, color='k')
plt.ylim(-3.0,3.0)
plt.show()
示例8: _show_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def _show_plot(x_values, y_values, x_labels=None, y_labels=None):
try:
import matplotlib.pyplot as plt
except ImportError:
raise ImportError('The plot function requires matplotlib to be installed.'
'See http://matplotlib.org/')
plt.locator_params(axis='y', nbins=3)
axes = plt.axes()
axes.yaxis.grid()
plt.plot(x_values, y_values, 'ro', color='red')
plt.ylim(ymin=-1.2, ymax=1.2)
plt.tight_layout(pad=5)
if x_labels:
plt.xticks(x_values, x_labels, rotation='vertical')
if y_labels:
plt.yticks([-1, 0, 1], y_labels, rotation='horizontal')
# Pad margins so that markers are not clipped by the axes
plt.margins(0.2)
plt.show()
#////////////////////////////////////////////////////////////
#{ Parsing and conversion functions
#////////////////////////////////////////////////////////////
示例9: plot_pixels
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def plot_pixels(file_name, candidate_data_single_band,
reference_data_single_band, limits=None, fit_line=None):
logging.info('Display: Creating pixel plot - {}'.format(file_name))
fig = plt.figure()
plt.hexbin(
candidate_data_single_band, reference_data_single_band, mincnt=1)
if not limits:
min_value = 0
_, ymax = plt.gca().get_ylim()
_, xmax = plt.gca().get_xlim()
max_value = max([ymax, xmax])
limits = [min_value, max_value]
plt.plot(limits, limits, 'k-')
if fit_line:
start = limits[0] * fit_line.gain + fit_line.offset
end = limits[1] * fit_line.gain + fit_line.offset
plt.plot(limits, [start, end], 'g-')
plt.xlim(limits)
plt.ylim(limits)
plt.xlabel('Candidate DNs')
plt.ylabel('Reference DNs')
fig.savefig(file_name, bbox_inches='tight')
plt.close(fig)
示例10: plot_histograms
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def plot_histograms(file_name, candidate_data_multiple_bands,
reference_data_multiple_bands=None,
# Default is for Blue-Green-Red-NIR:
colour_order=['b', 'g', 'r', 'y'],
x_limits=None, y_limits=None):
logging.info('Display: Creating histogram plot - {}'.format(file_name))
fig = plt.figure()
plt.hold(True)
for colour, c_band in zip(colour_order, candidate_data_multiple_bands):
c_bh, c_bins = numpy.histogram(c_band, bins=256)
plt.plot(c_bins[:-1], c_bh, color=colour, linestyle='-', linewidth=2)
if reference_data_multiple_bands:
for colour, r_band in zip(colour_order, reference_data_multiple_bands):
r_bh, r_bins = numpy.histogram(r_band, bins=256)
plt.plot(
r_bins[:-1], r_bh, color=colour, linestyle='--', linewidth=2)
plt.xlabel('DN')
plt.ylabel('Number of pixels')
if x_limits:
plt.xlim(x_limits)
if y_limits:
plt.ylim(y_limits)
fig.savefig(file_name, bbox_inches='tight')
plt.close(fig)
示例11: print_roc
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def print_roc(self, y_true, y_scores, filename):
'''
Prints the ROC for this model.
'''
fpr, tpr, thresholds = metrics.roc_curve(y_true, y_scores)
plt.figure()
plt.plot(fpr, tpr, color='darkorange', label='ROC curve (area = %0.2f)' % self.roc_auc)
plt.plot([0, 1], [0, 1], color='navy', linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic')
plt.legend(loc="lower right")
plt.savefig(filename)
plt.close()
示例12: plot_loss_change
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def plot_loss_change(self, sma=1, n_skip_beginning=10, n_skip_end=5, y_lim=(-0.01, 0.01)):
"""
Plots rate of change of the loss function.
Parameters:
sma - number of batches for simple moving average to smooth out the curve.
n_skip_beginning - number of batches to skip on the left.
n_skip_end - number of batches to skip on the right.
y_lim - limits for the y axis.
"""
derivatives = self.get_derivatives(sma)[n_skip_beginning:-n_skip_end]
lrs = self.lrs[n_skip_beginning:-n_skip_end]
plt.ylabel("rate of loss change")
plt.xlabel("learning rate (log scale)")
plt.plot(lrs, derivatives)
plt.xscale('log')
plt.ylim(y_lim)
plt.show()
示例13: plot_path_hist
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def plot_path_hist(results, labels, tols, figsize, ylim=None):
configure_plt()
sns.set_palette('colorblind')
n_competitors = len(results)
fig, ax = plt.subplots(figsize=figsize)
width = 1. / (n_competitors + 1)
ind = np.arange(len(tols))
b = (1 - n_competitors) / 2.
for i in range(n_competitors):
plt.bar(ind + (i + b) * width, results[i], width,
label=labels[i])
ax.set_ylabel('path computation time (s)')
ax.set_xticks(ind + width / 2)
plt.xticks(range(len(tols)), ["%.0e" % tol for tol in tols])
if ylim is not None:
plt.ylim(ylim)
ax.set_xlabel(r"$\epsilon$")
plt.legend(loc='upper left')
plt.tight_layout()
plt.show(block=False)
return fig
示例14: show_classification_areas
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def show_classification_areas(X, Y, lr):
x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.02), np.arange(y_min, y_max, 0.02))
Z = lr.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.figure(1, figsize=(30, 25))
plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Pastel1)
# Plot also the training points
plt.scatter(X[:, 0], X[:, 1], c=np.abs(Y - 1), edgecolors='k', cmap=plt.cm.coolwarm)
plt.xlabel('X')
plt.ylabel('Y')
plt.xlim(xx.min(), xx.max())
plt.ylim(yy.min(), yy.max())
plt.xticks(())
plt.yticks(())
plt.show()
开发者ID:PacktPublishing,项目名称:Fundamentals-of-Machine-Learning-with-scikit-learn,代码行数:23,代码来源:1logistic_regression.py
示例15: _plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ylim [as 别名]
def _plot(self, results, x, y, x_label, y_label, curve, filename):
r"""
Contains the actual plot functionality.
"""
plt.plot(x, y)
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.ylim([0.0, 1.0])
plt.xlim([0.0, 1.0])
if results == 'test':
plt.title('{} test set {} curve'.format(self.method, curve))
else:
plt.title('{} train set {} curve'.format(self.method, curve))
if filename is not None:
plt.savefig(filename + '_' + curve + '.pdf')
plt.close()
else:
plt.show()