本文整理汇总了Python中matplotlib.use函数的典型用法代码示例。如果您正苦于以下问题:Python use函数的具体用法?Python use怎么用?Python use使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了use函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUpClass
def setUpClass(cls):
try:
import matplotlib as mpl
mpl.use("Agg", warn=False)
except ImportError:
raise nose.SkipTest
开发者ID:nfoti,项目名称:pandas,代码行数:7,代码来源:test_graphics.py
示例2: showKernel
def showKernel(dataOrMatrix, fileName = None, useLabels = True, **args) :
labels = None
if hasattr(dataOrMatrix, 'type') and dataOrMatrix.type == 'dataset' :
data = dataOrMatrix
k = data.getKernelMatrix()
labels = data.labels
else :
k = dataOrMatrix
if 'labels' in args :
labels = args['labels']
import matplotlib
if fileName is not None and fileName.find('.eps') > 0 :
matplotlib.use('PS')
from matplotlib import pylab
pylab.matshow(k)
#pylab.show()
if useLabels and labels.L is not None :
numPatterns = 0
for i in range(labels.numClasses) :
numPatterns += labels.classSize[i]
#pylab.figtext(0.05, float(numPatterns) / len(labels), labels.classLabels[i])
#pylab.figtext(float(numPatterns) / len(labels), 0.05, labels.classLabels[i])
pylab.axhline(numPatterns, color = 'black', linewidth = 1)
pylab.axvline(numPatterns, color = 'black', linewidth = 1)
pylab.axis([0, len(labels), 0, len(labels)])
if fileName is not None :
pylab.savefig(fileName)
pylab.close()
开发者ID:Grater,项目名称:Sentiment-Analysis,代码行数:33,代码来源:ker.py
示例3: plot_gen
def plot_gen(ping, now, t, nans, host, interactive=False, size="1280x640"):
''' Generates ping vs time plot '''
if not interactive:
import matplotlib
matplotlib.use("Agg") # no need to load gui toolkit, can run headless
import matplotlib.pyplot as plt
size = [int(dim) for dim in size.split('x')]
datestr = now[0].ctime().split()
datestr = datestr[0] + " " + datestr[1] + " " + datestr[2] + " " + datestr[-1]
plt.figure(figsize=(size[0]/80.,size[1]/80.)) # dpi is 80
plt.plot(now[~nans], ping[~nans], drawstyle='steps', marker='+')
plt.title("Ping Results for {0}".format(host))
plt.ylabel("Latency [ms]")
plt.xlabel("Time, {0} [GMT -{1} hrs]".format(datestr, time.timezone/3600))
plt.xticks(size=10)
plt.yticks(size=10)
plt.ylim(ping[~nans].min()-5, ping[~nans].max()+5)
# plot packet losses
start = []
finish = []
for i in range(len(nans)):
if nans[i] == True:
if i == 0:
start.append(i)
elif nans[i] != nans[i-1]:
start.append(i)
#if i != len(nans) and nans[i+1] != nans[i]:
# finish.append(i)
# add the red bars for bad pings
for i in range(len(start)):
plt.axvspan(now[start[i]], now[finish[i]+1], color='red')
return plt
开发者ID:tmacbg,项目名称:python,代码行数:35,代码来源:pingplot.py
示例4: testTelescope
def testTelescope(self):
import matplotlib
matplotlib.use('AGG')
import matplotlib.mlab as ml
import pylab as pl
import time
w0 = 8.0
k = 2*np.pi/3.0
gb = GaussianBeam(w0, k)
lens = ThinLens(150, 150)
gb2 = lens*gb
self.assertAlmostEqual(gb2._z0, gb._z0 + 2*150.0)
lens2 = ThinLens(300, 600)
gb3 = lens2*gb2
self.assertAlmostEqual(gb3._z0, gb2._z0 + 2*300.0)
self.assertAlmostEqual(gb._w0, gb3._w0/2.0)
z = np.arange(0, 150)
z2 = np.arange(150, 600)
z3 = np.arange(600, 900)
pl.plot(z, gb.w(z, k), z2, gb2.w(z2, k), z3, gb3.w(z3, k))
pl.grid()
pl.xlabel('z')
pl.ylabel('w')
pl.savefig('testTelescope1.png')
time.sleep(0.1)
pl.close('all')
开发者ID:clemrom,项目名称:pyoptic,代码行数:26,代码来源:TestSuite.py
示例5: screeplot
def screeplot(self, type="barplot", **kwargs):
"""
Produce the scree plot
:param type: type of plot. "barplot" and "lines" currently supported
:param show: if False, the plot is not shown. matplotlib show method is blocking.
:return: None
"""
# check for matplotlib. exit if absent.
try:
imp.find_module('matplotlib')
import matplotlib
if 'server' in kwargs.keys() and kwargs['server']: matplotlib.use('Agg', warn=False)
import matplotlib.pyplot as plt
except ImportError:
print "matplotlib is required for this function!"
return
variances = [s**2 for s in self._model_json['output']['importance'].cell_values[0][1:]]
plt.xlabel('Components')
plt.ylabel('Variances')
plt.title('Scree Plot')
plt.xticks(range(1,len(variances)+1))
if type == "barplot": plt.bar(range(1,len(variances)+1), variances)
elif type == "lines": plt.plot(range(1,len(variances)+1), variances, 'b--')
if not ('server' in kwargs.keys() and kwargs['server']): plt.show()
开发者ID:madmax983,项目名称:h2o-3,代码行数:25,代码来源:dim_reduction.py
示例6: plot_lines_iamondb_example
def plot_lines_iamondb_example(X, title=None, index=None, ax=None, equal=True,
save=True):
if save:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
if ax is None:
f, ax = plt.subplots()
points = list(np.where(X[:, 0] > 0)[0])
start_points = [0] + points
stop_points = points + [len(X)]
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
for start, stop in zip(start_points, stop_points):
# Hack to actually separate lines...
ax.plot(X[start + 2:stop, 1], X[start + 2:stop, 2], color="black")
if equal:
ax.set_aspect('equal')
if title is not None:
plt.title(title)
if ax is None:
if not save:
plt.show()
else:
if index is None:
t = time.time()
else:
t = index
plt.savefig("lines_%i.png" % t)
开发者ID:kastnerkyle,项目名称:dagbldr,代码行数:29,代码来源:sample_from_saved_handwriting_model.py
示例7: __init__
def __init__(self, controllers, recipelist, server=myserver.myserver(host="0.0.0.0", port=8080)):
self.count = 0
self.wapp = Bottle()
self.controllers = controllers
self.recipelist = recipelist
self.server = server
self.stages = {}
self.runningRecipeName = ""
self.selectedRecipeName = ""
self.recipeObject = None
self.switchdict = {"lights": True, "camera": False, "sound": True}
matplotlib.use("Agg")
# Routing statements
self.wapp.route("/status", "GET", self.statusPage)
self.wapp.route("/", "GET", self.indexPage)
self.wapp.route("/start", "GET", self.commandPage)
self.wapp.route("/start", "POST", self.doCommand)
self.wapp.route("/recipelist", "GET", self.recipeliststatusPage)
self.wapp.route("/recipelist", "POST", self.dorecipeliststatus)
self.wapp.route("/debugStages", "GET", self.debugStages)
self.wapp.route("/readrecipes", "GET", self.getTestRecipeList)
self.wapp.route("/switchlist", "GET", self.switchliststatusPage)
self.wapp.route("/switchlist", "POST", self.doswitchliststatus)
self.wapp.route("/temp", "GET", self.tempPage)
self.wapp.route("/ingredients", "GET", self.ingredientsPage)
self.wapp.route("/static/<filename>", "GET", self.server_static)
self.s2b = stages2beer.s2b(controllers, self.stages)
self.dl = ctrl.datalogger(controllers)
开发者ID:cloudymike,项目名称:hopitty,代码行数:34,代码来源:webctrl.py
示例8: plot
def plot(self, path, only=None, title=None):
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
_only = set(only) if only is not None else set(self.ssmap.values())
rmap = dict([(v,k) for (k,v) in self.ssmap.iteritems()])
only = set([rmap.get(name) for name in _only])
stats = self.stats()
xaxis = np.array(sorted(stats.keys()))
totals = np.zeros(len(xaxis))
ss_perc = collections.defaultdict(lambda: np.zeros(len(xaxis)))
for i, x in enumerate(xaxis):
total = sum(stats[x].values())
totals[i] = total
for ss, count in stats[x].iteritems():
if ss in only: name = ss
else: name = 'other'
ss_perc[name][i] += 100 * count / float(total)
self.colormap['other'] = 'black'
self.ssmap['other'] = 'other'
xaxis /= 10.**3 # convert to ns
gs = gridspec.GridSpec(2, 1, hspace=0, height_ratios=[1,10])
# frame counts
plt.subplot(gs[0])
plt.title(title)
ax = plt.gca()
plt.bar(xaxis, totals, 1, color='grey', alpha=.5)
ax.yaxis.tick_right()
ax.yaxis.set_label_position('right')
plt.ylabel('#')
ax.yaxis.set_major_locator(plt.MaxNLocator(2))
ax.xaxis.set_visible(False)
# ax.spines['bottom'].set_visible(False)
# ax.xaxis.set_ticks_position('none')
# aggregate SS data
plt.subplot(gs[1])
for ss in ss_perc.keys():
color = self.colormap[ss]
color = color if not color == '#FFFFFF' else 'black'
style = ':' if color is 'black' else '-'
plt.plot(xaxis, ss_perc[ss], linestyle=style,
color=color, label=self.ssmap[ss], lw=3, alpha=.6)
plt.ylabel('%')
plt.xlabel('Time (ns)')
ax = plt.gca()
# ax.tick_params('x', labeltop='off')
# ax.spines['top'].set_visible(False)
# ax.xaxis.set_ticks_position('none')
plt.legend(loc='best', fontsize=9, frameon=False, ncol=len(self.ssmap)/2)
plt.savefig(path, bbox_inches='tight')
开发者ID:badi,项目名称:mdprep,代码行数:60,代码来源:xpm.py
示例9: create_figures
def create_figures(data):
import numpy as np
print "# Creating figure ..."
# prepare matplotlib
import matplotlib
matplotlib.rc("font",**{"family":"sans-serif"})
matplotlib.rcParams.update({'font.size': 14})
matplotlib.rc("text", usetex=True)
matplotlib.use("PDF")
import matplotlib.pyplot as plt
# KSP
plt.figure(1)
n, bins, patches = plt.hist(data[:, 1], bins = 50, fc = "k", ec = "w")
plt.xticks(range(300, 1001, 100), range(300, 1001, 100))
plt.yticks(range(0, 17, 2), range(0, 17, 2))
plt.xlabel("Model years")
plt.ylabel("Occurrence")
plt.savefig("parameterrange-ksp", bbox_inches = "tight")
# SNES
plt.figure(2)
n, bins, patches = plt.hist(data[:, 0], bins = 50, fc = "k", ec = "w")
plt.xticks(range(5, 46, 5), range(5, 46, 5))
plt.yticks(range(0, 15, 2), range(0, 15, 2))
plt.xlabel("Newton steps")
plt.ylabel("Occurrence")
plt.savefig("parameterrange-snes", bbox_inches = "tight")
开发者ID:metos3d,项目名称:2016-GMD-Metos3D,代码行数:28,代码来源:create-figure.py
示例10: setup
def setup():
# The baseline images are created in this locale, so we should use
# it during all of the tests.
import locale
import warnings
from matplotlib.backends import backend_agg, backend_pdf, backend_svg
try:
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
except locale.Error:
try:
locale.setlocale(locale.LC_ALL, str('English_United States.1252'))
except locale.Error:
warnings.warn(
"Could not set locale to English/United States. "
"Some date-related tests may fail")
use('Agg', warn=False) # use Agg backend for these tests
# These settings *must* be hardcoded for running the comparison
# tests and are not necessarily the default values as specified in
# rcsetup.py
rcdefaults() # Start with all defaults
set_font_settings_for_testing()
开发者ID:aragilar,项目名称:matplotlib,代码行数:25,代码来源:__init__.py
示例11: __init__
def __init__(self,master,title):
Toplevel.__init__(self,master)
self.master = master
from __init__ import MATPLOTLIB_BACKEND
if MATPLOTLIB_BACKEND != None:
print "manipulator: Setting matplotlib backend to \"TkAgg\"."
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from matplotlib import pyplot
self.title(title)
self.resizable(True,True)
self.fig = pyplot.figure()
pyplot.ion()
self.canvas = FigureCanvasTkAgg(self.fig, master=self)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
self.canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1)
self.update()
self.experiments = []
开发者ID:elihuihms,项目名称:itcsimlib,代码行数:27,代码来源:manipulator.py
示例12: run_tests
def run_tests(self):
import matplotlib
matplotlib.use('agg')
import nose
from matplotlib.testing.noseclasses import KnownFailure
from matplotlib import default_test_modules as testmodules
from matplotlib import font_manager
import time
# Make sure the font caches are created before starting any possibly
# parallel tests
if font_manager._fmcache is not None:
while not os.path.exists(font_manager._fmcache):
time.sleep(0.5)
plugins = [KnownFailure]
# Nose doesn't automatically instantiate all of the plugins in the
# child processes, so we have to provide the multiprocess plugin
# with a list.
from nose.plugins import multiprocess
multiprocess._instantiate_plugins = plugins
if self.omit_pep8:
testmodules.remove('matplotlib.tests.test_coding_standards')
elif self.pep8_only:
testmodules = ['matplotlib.tests.test_coding_standards']
nose.main(addplugins=[x() for x in plugins],
defaultTest=testmodules,
argv=['nosetests'] + self.test_args,
exit=True)
开发者ID:Acanthostega,项目名称:matplotlib,代码行数:30,代码来源:setup.py
示例13: matplotAnimationLibMovie
def matplotAnimationLibMovie():
# Use matplotlib's animation library to directly output an mp4.
import numpy as np
import matplotlib
matplotlib.use('TKAgg')
from matplotlib import pyplot as plt
from matplotlib import animation
def update_line(num, data, line):
line.set_data(data[...,:num])
return line,
fig1 = plt.figure()
data = np.random.rand(2, 25)
l, = plt.plot([], [], 'r-')
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('x')
plt.title('test')
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),
interval=50, blit=True)
line_ani.save('outLines.mp4')
fig2 = plt.figure()
x = np.arange(-9, 10)
y = np.arange(-9, 10).reshape(-1, 1)
base = np.hypot(x, y)
ims = []
for add in np.arange(15):
ims.append((plt.pcolor(x, y, base + add, norm=plt.Normalize(0, 30)),))
im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000,
blit=True)
im_ani.save('outSurface.mp4', metadata={'artist':'Guido'})
开发者ID:cdkkim,项目名称:omf,代码行数:30,代码来源:makeMovie.py
示例14: begin
def begin(self):
#
# We monkey-patch javabridge.start_vm here in order to
# set up the ImageJ event bus (actually
# org.bushe.swing.event.ThreadSafeEventService) to not start
# its cleanup thread which semi-buggy hangs around forever
# and prevents Java from exiting.
#
def patch_start_vm(*args, **kwargs):
jvm_args = list(args[0]) + [
"-Dloci.bioformats.loaded=true",
"-Djava.util.prefs.PreferencesFactory="+
"org.cellprofiler.headlesspreferences"+
".HeadlessPreferencesFactory"]
#
# Find the ij1patcher
#
if hasattr(sys, 'frozen') and sys.platform == 'win32':
root = os.path.dirname(sys.argv[0])
else:
root = os.path.dirname(__file__)
jardir = os.path.join(root, "imagej", "jars")
patchers = sorted([
x for x in os.listdir(jardir)
if x.startswith("ij1-patcher") and x.endswith(".jar")])
if len(patchers) > 0:
jvm_args.append(
"-javaagent:%s=init" % os.path.join(jardir, patchers[-1]))
result = start_vm(jvm_args, *args[1:], **kwargs)
if javabridge.get_env() is not None:
try:
event_service_cls = javabridge.JClassWrapper(
"org.bushe.swing.event.ThreadSafeEventService")
event_service_cls.CLEANUP_PERIOD_MS_DEFAULT = None
except:
pass
return result
patch_start_vm.func_globals["start_vm"] = javabridge.start_vm
javabridge.start_vm = patch_start_vm
if "CP_EXAMPLEIMAGES" in os.environ:
self.temp_exampleimages = None
else:
self.temp_exampleimages = tempfile.mkdtemp(prefix="cpexampleimages")
if "CP_TEMPIMAGES" in os.environ:
self.temp_images = None
else:
self.temp_images = tempfile.mkdtemp(prefix="cptempimages")
#
# Set up matplotlib for WXAgg if in frozen mode
# otherwise it looks for TK which isn't there
#
if hasattr(sys, 'frozen'):
import matplotlib
matplotlib.use("WXAgg")
try:
from ilastik.core.jobMachine import GLOBAL_WM
GLOBAL_WM.set_thread_count(1)
except:
pass
开发者ID:LeeKamentsky,项目名称:CellProfiler,代码行数:60,代码来源:cpnose.py
示例15: activate_matplotlib
def activate_matplotlib(backend):
"""Activate the given backend and set interactive to True."""
import matplotlib
if backend.startswith('module://'):
# Work around bug in matplotlib: matplotlib.use converts the
# backend_id to lowercase even if a module name is specified!
matplotlib.rcParams['backend'] = backend
else:
matplotlib.use(backend)
matplotlib.interactive(True)
# This must be imported last in the matplotlib series, after
# backend/interactivity choices have been made
import matplotlib.pylab as pylab
# XXX For now leave this commented out, but depending on discussions with
# mpl-dev, we may be able to allow interactive switching...
#import matplotlib.pyplot
#matplotlib.pyplot.switch_backend(backend)
pylab.show._needmain = False
# We need to detect at runtime whether show() is called by the user.
# For this, we wrap it into a decorator which adds a 'called' flag.
pylab.draw_if_interactive = flag_calls(pylab.draw_if_interactive)
开发者ID:BlackEarth,项目名称:portable-python-win32,代码行数:25,代码来源:pylabtools.py
示例16: plot_dist_matrix
def plot_dist_matrix(matrix, fasta_names, heatmap_out, dendrogram_out):
"""Cluster the distance matrix hierarchically and plot using seaborn.
Average linkage method is used."""
# Load required modules for plotting
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from scipy.cluster.hierarchy import dendrogram, linkage
# Create
pdm = pd.DataFrame(matrix, index=fasta_names, columns=fasta_names)
# Plot heatmap
figsizex = max(10, len(fasta_names) / 4)
clustergrid = sns.clustermap(pdm, metric='euclidean', method='average',
figsize=(figsizex, figsizex))
clustergrid.savefig(heatmap_out)
# Plot dendrogram
sns.set_style('white')
figsizey = max(10, len(fasta_names) / 8)
f, ax = plt.subplots(figsize=(figsizex, figsizey))
link = linkage(pdm, metric='euclidean', method='average')
dendrogram(link, labels=pdm.index, ax=ax)
no_spine = {'left': True, 'bottom': True, 'right': True, 'top': True}
sns.despine(**no_spine)
plt.xticks(rotation=90)
f.tight_layout()
plt.savefig(dendrogram_out)
开发者ID:BinPro,项目名称:CONCOCT,代码行数:31,代码来源:dnadiff_dist_matrix.py
示例17: _savePlot
def _savePlot(self, data, filename):
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.plot(data)
plt.savefig(filename)
开发者ID:lbusoni,项目名称:pi_gcs,代码行数:7,代码来源:tip_tilt_2_axes_test.py
示例18: footprint_area
def footprint_area(cat,ngal=1,mask=None,nside=4096,nest=True,label=''):
import healpy as hp
import matplotlib
matplotlib.use ('agg')
import matplotlib.pyplot as plt
# plt.style.use('/home/troxel/SVA1/SVA1StyleSheet.mplstyle')
from matplotlib.colors import LogNorm
import pylab
mask=CatalogMethods.check_mask(cat.coadd,mask)
if not hasattr(cat, 'pix'):
cat.pix=CatalogMethods.radec_to_hpix(cat.ra,cat.dec,nside=nside,nest=True)
area=hp.nside2pixarea(nside)*(180./np.pi)**2
print 'pixel area (arcmin)', area*60**2
mask1=np.bincount(cat.pix[mask])>ngal
print 'footprint area (degree)', np.sum(mask1)*area
pix=np.arange(len(mask1))[mask1]
print pix
tmp=np.zeros((12*nside**2), dtype=[('hpix','int')])
tmp['hpix'][pix.astype(int)]=1
print tmp['hpix'][pix.astype(int)]
fio.write('footprint_hpix'+label+'.fits.gz',tmp,clobber=True)
tmp2=np.zeros(12*nside**2)
tmp2[tmp.astype(int)]=1
hp.cartview(tmp2,nest=True)
plt.savefig('footprint_hpix'+label+'.png')
plt.close()
return
开发者ID:cpadavis,项目名称:destest,代码行数:32,代码来源:catalog.py
示例19: plot_scatter_iamondb_example
def plot_scatter_iamondb_example(X, title=None, index=None, ax=None, equal=True,
save=True):
if save:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
if ax is None:
f, ax = plt.subplots()
down = np.where(X[:, 0] == 0)[0]
up = np.where(X[:, 0] == 1)[0]
ax.scatter(X[down, 1], X[down, 2], color="steelblue")
ax.scatter(X[up, 1], X[up, 2], color="darkred")
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
if equal:
ax.set_aspect('equal')
if title is not None:
plt.title(title)
if ax is None:
if not save:
plt.show()
else:
if index is None:
t = time.time()
else:
t = index
plt.savefig("scatter_%i.png" % t)
开发者ID:kastnerkyle,项目名称:dagbldr,代码行数:27,代码来源:sample_from_saved_handwriting_model.py
示例20: create_cdf_fig
def create_cdf_fig(in_file, out_file, title):
min_y = []
avg_y = []
max_y = []
with open(in_file ,'r') as dat:
for line in dat:
if len(line) > 0:
sp = line.split(' ')
if len(sp) < 4:
continue
min_y.append(float(sp[1]))
avg_y.append(float(sp[2]))
max_y.append(float(sp[3]))
min_x, min__y = get_cdf(min_y)
avg_x, avg__y = get_cdf(avg_y)
max_x, max__y = get_cdf(max_y)
ax = plt.subplot(1, 1, 1)
plt.plot(min_x, min__y, label="Min")
plt.plot(avg_x, avg__y, label="Avg")
plt.plot(max_x, max__y, label="Max")
matplotlib.use('Agg')
plt.legend(loc='upper left')
plt.xlabel("Fraction")
plt.ylabel("RTT (ms)")
plt.title(title)
plt.savefig(out_file)
plt.clf()
开发者ID:rlyspn,项目名称:pingstat,代码行数:30,代码来源:generate_figures.py
注:本文中的matplotlib.use函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论