本文整理汇总了Python中matplotlib.pyplot.close函数的典型用法代码示例。如果您正苦于以下问题:Python close函数的具体用法?Python close怎么用?Python close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了close函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_radardisplay_init
def test_radardisplay_init():
# test that a display object can be created with and without
radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_PPI_FILE)
radar.antenna_transition = {'data': np.zeros((40, ))}
display = pyart.graph.RadarDisplay(radar)
assert display.antenna_transition is not None
plt.close()
开发者ID:gavi,项目名称:pyart,代码行数:7,代码来源:test_radardisplay.py
示例2: scree_plot
def scree_plot(pca_obj, fname=None):
'''
Scree plot for variance & cumulative variance by component from PCA.
Arguments:
- pca_obj: a fitted sklearn PCA instance
- fname: path to write plot to file
Output:
- scree plot
'''
components = pca_obj.n_components_
variance = pca.explained_variance_ratio_
plt.figure()
plt.plot(np.arange(1, components + 1), np.cumsum(variance), label='Cumulative Variance')
plt.plot(np.arange(1, components + 1), variance, label='Variance')
plt.xlim([0.8, components]); plt.ylim([0.0, 1.01])
plt.xlabel('No. Components', labelpad=11); plt.ylabel('Variance Explained', labelpad=11)
plt.legend(loc='best')
plt.tight_layout()
if fname is not None:
plt.savefig(fname)
plt.close()
else:
plt.show()
return
开发者ID:thomasbrawner,项目名称:python_tools,代码行数:26,代码来源:scree_plot.py
示例3: display_d3
def display_d3(fig=None, closefig=True, d3_url=None):
"""Display figure in IPython notebook via the HTML display hook
Parameters
----------
fig : matplotlib figure
The figure to display (grabs current figure if missing)
closefig : boolean (default: True)
If true, close the figure so that the IPython matplotlib mode will not
display the png version of the figure.
d3_url : string (optional)
The URL of the d3 library. If not specified, a standard web path
will be used.
Returns
-------
fig_d3 : IPython.display.HTML object
the IPython HTML rich display of the figure.
See Also
--------
show_d3 : show a figure in a new browser window, notebook not required.
enable_notebook : automatically embed figures in the IPython notebook
"""
# import here, in case users don't have requirements installed
from IPython.display import HTML
import matplotlib.pyplot as plt
if fig is None:
fig = plt.gcf()
if closefig:
plt.close(fig)
return HTML(fig_to_d3(fig, d3_url=d3_url))
开发者ID:catarinacavaco,项目名称:mpld3,代码行数:32,代码来源:display.py
示例4: graph_view
def graph_view(request):
try:
fig = plot.figure()
ax = fig.add_subplot(111)
plot_data(request, ax, 0)
plot_data(request, ax, 1)
ax.set_xlabel("Time")
ax.set_ylabel(u"Temperature (°C)")
fig.autofmt_xdate()
imgdata = StringIO.StringIO()
fig.savefig(imgdata, format='svg')
return Response(imgdata.getvalue(), content_type='image/svg+xml')
except DBAPIError:
conn_err_msg = """\
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="10cm" height="10cm" viewBox="0 0 100 300"
xmlns="http://www.w3.org/2000/svg" version="1.1">
<desc>Database connection error message</desc>
<text x="0" y="0" fill="red">Database error.</text>
</svg>"""
return Response(conn_err_msg, content_type='image/svg+xml', status_int=500)
finally:
plot.close('all')
开发者ID:bwduncan,项目名称:autoboiler,代码行数:25,代码来源:views.py
示例5: make_iso_visual_panel
def make_iso_visual_panel(fn, img_compo, img_map, contours1, contours3, z, pixsize, legend_suffix, name, title_compo, title_map, label_cbar):
fig, (ax0, ax1, ax_cb) = get_figure_grids(n_panel=2)
# plot composit
ax_imshow(fig, ax0, img_compo, origin='upper', tocolorbar=False, tosetlim=True)
nx, ny = img_compo.shape[:2]
overplot_ruler(ax0, z, pixsize=pixsize, rlength_arcsec=10., nx=nx, ny=ny)
ax0.text(5, 12, name, color='white', fontsize=12)
ax0.text(nx-35, 12, '$z={}$'.format('%.2f'%z), color='white', fontsize=10)
ax0.set_title(title_compo)
ax0.title.set_position([.5, 1.03])
# plot line map
im = ax_imshow(fig, ax1, img_map, vmin=-1, vmax=8, origin='lower', tocolorbar=False, tosetlim=True)
overplot_contours(ax1, contours3, lw=1.)
overplot_contours(ax1, contours1, lw=0.2)
make_legend_isophotes(ax1, lw=2, suffix=legend_suffix)
ax1.set_title(title_map)
ax1.title.set_position([.5, 1.03])
# plot color bar
cbar = fig.colorbar(im, cax=ax_cb, label=label_cbar, format='%i')
ax_cb.set_aspect(20)
# set ticks off
for ax in [ax0, ax1]:
ax.axis('off')
# saving
fig.savefig(fn, format='pdf')
plt.close()
开发者ID:aileisun,项目名称:bubblepy,代码行数:35,代码来源:plottools.py
示例6: plot_cc
def plot_cc(self):
with PdfPages("CCplot.pdf") as pdf:
for each_frame in self.frame_list:
fig, axs = plt.subplots(5,5, sharex=True, sharey=True, squeeze=True, facecolor='w', edgecolor='k')
fig.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1, hspace = 0.5, wspace=0.1)
fig.text(0.5, 0.04, 'CCweak', ha='center')
fig.text(0.04, 0.5, 'CCall', va='center', rotation='vertical')
fig.set_size_inches(8,11)
axs = axs.flatten()
for i in range(len(each_frame)):
ccall, ccweak = get_CCs(each_frame[i])
if len(ccweak) > len(ccall):
diff = len(ccweak) - len(ccall)
axs[i].plot(ccweak[0:(len(ccweak)-diff)], ccall, 'o', linewidth=1, rasterized=True)
elif len(ccweak) < len(ccall):
diff = len(ccall) - len(ccweak)
axs[i].plot(ccweak, ccall[0:(len(ccall)-diff)], 'o', linewidth=1, rasterized=True)
else:
axs[i].plot(ccweak, ccall, 'o', linewidth=1, rasterized=True)
titles = each_frame[i].strip('-shelxd.log')
axs[i].set_title(titles, fontsize=8)
pdf.savefig(fig)
plt.close()
开发者ID:shibom,项目名称:scripts_sls,代码行数:27,代码来源:plot_cluster.py
示例7: export
def export(data, F, k):
'''Write data to a png image
Arguments
---------
data : numpy.ndarray
array containing the data to be written as png image
F : float
feed rate of the current configuration
k : float
rate constant of the current configuration
'''
figsize = tuple(s / 72.0 for s in data.shape)
fig = plt.figure(figsize=figsize, dpi=72.0, facecolor='white')
fig.add_axes([0, 0, 1, 1], frameon=False)
plt.xticks([])
plt.yticks([])
plt.imshow(data, cmap=plt.cm.RdBu_r, interpolation='bicubic')
plt.gci().set_clim(0, 1)
filename = './study/F{:03d}-k{:03d}.png'.format(int(1000*F), int(1000*k))
plt.savefig(filename, dpi=72.0)
plt.close()
开发者ID:michaelschaefer,项目名称:grayscott,代码行数:25,代码来源:parameterstudy.py
示例8: test_singleton_ax_dim
def test_singleton_ax_dim():
for axis, direction in enumerate("xyz"):
shape = [5, 6, 7]
shape[axis] = 1
img = nibabel.Nifti1Image(np.ones(shape), np.eye(4))
plot_stat_map(img, None, display_mode=direction)
plt.close()
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:7,代码来源:test_img_plotting.py
示例9: test_plot_anat
def test_plot_anat():
img = _generate_img()
# Test saving with empty plot
z_slicer = plot_anat(anat_img=False, display_mode='z')
filename = tempfile.mktemp(suffix='.png')
try:
z_slicer.savefig(filename)
finally:
os.remove(filename)
z_slicer = plot_anat(display_mode='z')
filename = tempfile.mktemp(suffix='.png')
try:
z_slicer.savefig(filename)
finally:
os.remove(filename)
ortho_slicer = plot_anat(img, dim='auto')
filename = tempfile.mktemp(suffix='.png')
try:
ortho_slicer.savefig(filename)
finally:
os.remove(filename)
# Save execution time and memory
plt.close()
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:27,代码来源:test_img_plotting.py
示例10: test_radardisplay_get_colorbar_label
def test_radardisplay_get_colorbar_label():
radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_PPI_FILE)
display = pyart.graph.RadarDisplay(radar)
# default is to base the label on the standard_name key
assert (display._get_colorbar_label('reflectivity_horizontal') ==
'equivalent reflectivity factor (dBZ)')
# next is to look at the long_name
del display.fields['reflectivity_horizontal']['standard_name']
assert (display._get_colorbar_label('reflectivity_horizontal') ==
'Reflectivity (dBZ)')
# use the field if standard_name and long_name missing
del display.fields['reflectivity_horizontal']['long_name']
print(display._get_colorbar_label('reflectivity_horizontal'))
assert (display._get_colorbar_label('reflectivity_horizontal') ==
'reflectivity horizontal (dBZ)')
# no units if key is missing
del display.fields['reflectivity_horizontal']['units']
print(display._get_colorbar_label('reflectivity_horizontal'))
assert (display._get_colorbar_label('reflectivity_horizontal') ==
'reflectivity horizontal (?)')
plt.close()
开发者ID:gavi,项目名称:pyart,代码行数:25,代码来源:test_radardisplay.py
示例11: test_plot_stat_map
def test_plot_stat_map():
img = _generate_img()
plot_stat_map(img, cut_coords=(80, -120, -60))
# Smoke test coordinate finder, with and without mask
masked_img = nibabel.Nifti1Image(
np.ma.masked_equal(img.get_data(), 0),
mni_affine)
plot_stat_map(masked_img, display_mode='x')
plot_stat_map(img, display_mode='y', cut_coords=2)
# 'yx' display_mode
plot_stat_map(img, display_mode='yx')
# regression test #510
data = np.zeros((91, 109, 91))
aff = np.eye(4)
new_img = nibabel.Nifti1Image(data, aff)
plot_stat_map(new_img, threshold=1000, colorbar=True)
rng = np.random.RandomState(42)
data = rng.randn(91, 109, 91)
new_img = nibabel.Nifti1Image(data, aff)
plot_stat_map(new_img, threshold=1000, colorbar=True)
# Save execution time and memory
plt.close()
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:28,代码来源:test_img_plotting.py
示例12: test_radardisplay_misc
def test_radardisplay_misc():
# misc methods which are not tested above
radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_PPI_FILE)
display = pyart.graph.RadarDisplay(radar)
fig = plt.figure()
ax = fig.add_subplot(111)
# _set_vpt_title with a title
display._set_vpt_title('foo_field', 'title_string', ax)
assert ax.get_title() == 'title_string'
# _generate_field_name method
fn = pyart.graph.common.generate_field_name(
radar, 'reflectivity_horizontal')
assert fn == 'Equivalent reflectivity factor'
display.fields['reflectivity_horizontal'].pop('standard_name')
fn = pyart.graph.common.generate_field_name(
radar, 'reflectivity_horizontal')
assert fn == 'Reflectivity'
display.fields['reflectivity_horizontal'].pop('long_name')
fn = pyart.graph.common.generate_field_name(
radar, 'reflectivity_horizontal')
assert fn == 'Reflectivity horizontal'
plt.close()
开发者ID:gavi,项目名称:pyart,代码行数:27,代码来源:test_radardisplay.py
示例13: test_radardisplay_user_specified_labels
def test_radardisplay_user_specified_labels():
# test that labels are set when a user specifies them.
radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_PPI_FILE)
display = pyart.graph.RadarDisplay(radar)
fig = plt.figure()
ax = fig.add_subplot(111)
display._set_ray_title('field', 0, 'foo', ax)
assert ax.get_title() == 'foo'
display._label_axes_ppi(('foo', 'bar'), ax)
assert ax.get_xlabel() == 'foo'
assert ax.get_ylabel() == 'bar'
display._label_axes_rhi(('spam', 'eggs'), ax)
assert ax.get_xlabel() == 'spam'
assert ax.get_ylabel() == 'eggs'
display._label_axes_ray(('baz', 'qux'), 'field', ax)
assert ax.get_xlabel() == 'baz'
assert ax.get_ylabel() == 'qux'
display._label_axes_vpt(('nick', 'nock'), False, ax)
assert ax.get_xlabel() == 'nick'
assert ax.get_ylabel() == 'nock'
plt.close()
开发者ID:gavi,项目名称:pyart,代码行数:26,代码来源:test_radardisplay.py
示例14: test_radardisplay_plot_rhi_reverse
def test_radardisplay_plot_rhi_reverse():
radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_RHI_FILE)
display = pyart.graph.RadarDisplay(radar)
fig = plt.figure()
ax = fig.add_subplot(111)
display.plot('reflectivity_horizontal', 0, ax=ax, reverse_xaxis=True)
plt.close()
开发者ID:gavi,项目名称:pyart,代码行数:7,代码来源:test_radardisplay.py
示例15: test_heatmap_ticklabel_rotation
def test_heatmap_ticklabel_rotation(self):
f, ax = plt.subplots(figsize=(2, 2))
mat.heatmap(self.df_norm, ax=ax)
for t in ax.get_xticklabels():
nt.assert_equal(t.get_rotation(), 0)
for t in ax.get_yticklabels():
nt.assert_equal(t.get_rotation(), 90)
plt.close(f)
df = self.df_norm.copy()
df.columns = [str(c) * 10 for c in df.columns]
df.index = [i * 10 for i in df.index]
f, ax = plt.subplots(figsize=(2, 2))
mat.heatmap(df, ax=ax)
for t in ax.get_xticklabels():
nt.assert_equal(t.get_rotation(), 90)
for t in ax.get_yticklabels():
nt.assert_equal(t.get_rotation(), 0)
plt.close(f)
开发者ID:petebachant,项目名称:seaborn,代码行数:27,代码来源:test_matrix.py
示例16: make_fish
def make_fish(zoom=False):
plt.close(1)
plt.figure(1, figsize=(6, 4))
plt.plot(plot_limits['pitch'], plot_limits['rolldev'], '-g', lw=3)
plt.plot(plot_limits['pitch'], -plot_limits['rolldev'], '-g', lw=3)
plt.plot(pitch.midvals, roll.midvals, '.b', ms=1, alpha=0.7)
p, r = make_ellipse() # pitch, off nominal roll
plt.plot(p, r, '-c', lw=2)
gf = -0.08 # Fudge on pitch value for illustrative purposes
plt.plot(greta['pitch'] + gf, -greta['roll'], '.r', ms=1, alpha=0.7)
plt.plot(greta['pitch'][-1] + gf, -greta['roll'][-1], 'xr', ms=10, mew=2)
if zoom:
plt.xlim(46.3, 56.1)
plt.ylim(4.1, 7.3)
else:
plt.ylim(-22, 22)
plt.xlim(40, 180)
plt.xlabel('Sun pitch angle (deg)')
plt.ylabel('Sun off-nominal roll angle (deg)')
plt.title('Mission off-nominal roll vs. pitch (5 minute samples)')
plt.grid()
plt.tight_layout()
plt.savefig('fish{}.png'.format('_zoom' if zoom else ''))
开发者ID:sot,项目名称:safemode_2015264,代码行数:26,代码来源:plot_fish.py
示例17: test_savefig
def test_savefig(self):
# Not sure if this is the right way to test....
cm = mat.ClusterGrid(self.df_norm, **self.default_kws)
cm.plot(**self.default_plot_kws)
cm.savefig(tempfile.NamedTemporaryFile(), format='png')
plt.close('all')
开发者ID:petebachant,项目名称:seaborn,代码行数:7,代码来源:test_matrix.py
示例18: plot_dpi_dpr_distribution
def plot_dpi_dpr_distribution(args, dpis, dprs, diagnoses):
print log.INFO, 'Plotting estimate distributions...'
diagnoses = np.array(diagnoses)
diagnoses[(0.25 <= diagnoses) & (diagnoses <= 0.75)] = 0.5
# Setup plot
fig, ax = plt.subplots()
pt.setup_axes(plt, ax)
biomarkers_str = args.method if args.biomarkers is None else ', '.join(args.biomarkers)
ax.set_title('DP estimation using {0} at {1}'.format(biomarkers_str, ', '.join(args.visits)))
ax.set_xlabel('DP')
ax.set_ylabel('DPR')
plt.scatter(dpis, dprs, c=diagnoses, edgecolor='none', s=25.0,
vmin=0.0, vmax=1.0, cmap=pt.progression_cmap,
alpha=0.5)
# Plot legend
# noinspection PyUnresolvedReferences
rects = [mpl.patches.Rectangle((0, 0), 1, 1, fc=pt.color_cn + (0.5,), linewidth=0),
mpl.patches.Rectangle((0, 0), 1, 1, fc=pt.color_mci + (0.5,), linewidth=0),
mpl.patches.Rectangle((0, 0), 1, 1, fc=pt.color_ad + (0.5,), linewidth=0)]
labels = ['CN', 'MCI', 'AD']
legend = ax.legend(rects, labels, fontsize=10, ncol=len(rects), loc='upper center', framealpha=0.9)
legend.get_frame().set_edgecolor((0.6, 0.6, 0.6))
# Draw or save the plot
plt.tight_layout()
if args.plot_file is not None:
plt.savefig(args.plot_file, transparent=True)
else:
plt.show()
plt.close(fig)
开发者ID:aschmiri,项目名称:DiseaseProgressionModel,代码行数:34,代码来源:estimate_progressions.py
示例19: key_press
def key_press(event):
ax = event.inaxes
if ax == None: return
ax_title = ax.get_title()
if event.key == 'q': plt.close('all')
if event.key == 'm':
click_x, click_y = event.xdata, event.ydata
rr = np.arange((x2-2*dpix),(x2+2*dpix+1), dtype=np.int)
#p = ip.gauss_fit(rr, row[rr], p0=[1, x2, 1])
#a2.plot(rr, ip.gauss(rr, *p), 'r--')
#mx = p[1]
mx, mval = ip.find_features(rr, row[rr], gpix=dpix)
mx, mval = mx[0], mval[0]
a2.plot(mx, mval, 'ro')
fig.canvas.draw()
fwv = cwv[np.argmin(np.abs(cwv-wav[mx]))]
strtmp = raw_input('input wavelength at (%d, %d) = %.7f:' % (mx, my, fwv))
if strtmp == '': strtmp = fwv
try:
mwv = np.float(strtmp)
lxx.append(mx)
lyy.append(my)
lwv.append(mwv)
a1.plot(mx, my, 'ro')
fig.canvas.draw()
print '%.7f at (%d, %d)' % (mwv, mx, my)
except:
print 'No input, again...'
开发者ID:gmace,项目名称:plp,代码行数:31,代码来源:extract.py
示例20: plot_jacobian
def plot_jacobian(A, name, cmap= plt.cm.coolwarm, normalize=True, precision=1e-6):
"""
Customized visualization of jacobian matrices for observing
sparsity patterns
"""
plt.figure()
fig, ax = plt.subplots()
if normalize is True:
plt.imshow(A, interpolation='none', cmap=cmap,
norm = mpl.colors.Normalize(vmin=-1.,vmax=1.))
else:
plt.imshow(A, interpolation='none', cmap=cmap)
plt.colorbar(format=ticker.FuncFormatter(fmt))
ax.spy(A, marker='.', markersize=0, precision=precision)
ax.spines['right'].set_visible(True)
ax.spines['bottom'].set_visible(True)
ax.xaxis.set_ticks_position('top')
ax.yaxis.set_ticks_position('left')
xlabels = np.linspace(0, A.shape[0], 5, True, dtype=int)
ylabels = np.linspace(0, A.shape[1], 5, True, dtype=int)
plt.xticks(xlabels)
plt.yticks(ylabels)
plt.savefig(name, bbox_inches='tight', pad_inches=0.05)
plt.close()
return
开发者ID:komahanb,项目名称:pchaos,代码行数:35,代码来源:plotter.py
注:本文中的matplotlib.pyplot.close函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论