本文整理汇总了Python中matplotlib.collections.LineCollection.set_linewidth方法的典型用法代码示例。如果您正苦于以下问题:Python LineCollection.set_linewidth方法的具体用法?Python LineCollection.set_linewidth怎么用?Python LineCollection.set_linewidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.LineCollection
的用法示例。
在下文中一共展示了LineCollection.set_linewidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_Kiel_diagram
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def plot_Kiel_diagram(starl):
"""
Plot Kiel diagram.
"""
x = starl['temperature']
y = starl['g']
age = starl['age']/1e6
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
cmap = pl.cm.spectral
norm = pl.Normalize(age.min(), age.max())
lc = LineCollection(segments, cmap=cmap,norm=norm)
lc.set_array(age)
lc.set_linewidth(3)
pl.gca().add_collection(lc)
pl.xlim(x.max(), x.min())
pl.ylim(y.max(), y.min())
pl.xlabel('Effective temperature [K]')
pl.ylabel('log(surface gravity [cm s$^{-2}$]) [dex]')
ax0 = pl.gca()
ax1 = pl.mpl.colorbar.make_axes(ax0)[0]
norm = pl.mpl.colors.Normalize(age.min(), age.max())
cb1 = pl.mpl.colorbar.ColorbarBase(ax1, cmap=cmap,
norm=norm,orientation='vertical')
cb1.set_label('Age [Myr]')
pl.axes(ax0)
示例2: hello
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def hello():
rtimes, rt, rp = np.loadtxt("data/data.txt").T
rtimes = map(datetime.datetime.fromtimestamp, rtimes)
rtimes = matplotlib.dates.date2num(rtimes)
fig = Figure()
axis = fig.add_subplot(1, 1, 1)
axis.xaxis_date()
fig.autofmt_xdate()
forecast_list = []
for fname in glob.glob("data/forecast.*.txt"):
stamp = fname.split(".")[1]
times, tempa = np.loadtxt(fname).T
times = map(datetime.datetime.fromtimestamp, times)
times = matplotlib.dates.date2num(times)
points = np.array([times, tempa]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lc = LineCollection(segments, cmap=plt.get_cmap("jet"),
norm=plt.Normalize(0, 1))
lc.set_array(np.linspace(0,1,len(times)))
lc.set_linewidth(1)
axis.add_collection(lc)
axis.plot_date(times, tempa, "-", linewidth=0)
axis.plot_date(rtimes, rt, "-",linewidth=1, color="black")
canvas = FigureCanvas(fig)
output = StringIO.StringIO()
canvas.print_png(output)
response = make_response(output.getvalue())
response.mimetype = 'image/png'
return response
示例3: show_mf_wave
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def show_mf_wave(**kwargs):
ion()
mjfile='data/mf_W1%s_W2%s_U%s_N%s_dmu%s.npy'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),kwargs.get('dmu'))
pls=load(mjfile)
ampl=(pls[:2]*pls[:2].conj()).real
print 'Magnituede %s'%sum(ampl,axis=1)
if ONSV:
return
#mjfile2='data/mf_W1%s_W2%s_U%s_N%s_dmu%s.npy'%(kwargs.get('K1'),kwargs.get('K2'),kwargs.get('U'),kwargs.get('nsite'),-kwargs.get('dmu'))
#pls2=load(mjfile2)
#overlap=(pls2[:2].dot(pls[:2].T.conj()))
#print overlap
#subplot(211)
#plot(abs(ket_even.state))
#ylim(0,0.5)
#subplot(212)
#plot(abs(ket_odd.state))
#ylim(0,0.5)
#pdb.set_trace()
lw=2
lc='r'
nsite=pls.shape[1]
for n in xrange(2):
pln=ampl[n]
ax=subplot(121+n)
lc=LineCollection([[(i,0),(i,pln[i].item())] for i in xrange(nsite)])
lc.set_linewidth(lw)
ax.add_collection(lc)
ax.autoscale()
ax.margins(0.1)
pdb.set_trace()
示例4: d3
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def d3():
rtimes, rt, rp = np.loadtxt("data/data.txt").T
mask = np.logical_and(rtimes>1391000000, rtimes<1393000000)
rtimes = rtimes[mask]
rt = rt[mask]
rtimes = map(datetime.datetime.fromtimestamp, rtimes)
rtimes = matplotlib.dates.date2num(rtimes)
fig, axis = plt.subplots()
axis.xaxis_date()
fig.autofmt_xdate()
axis.plot_date(rtimes, rt, "-",linewidth=3, color="black")
forecast_list = []
for fname in glob.glob("data/forecast.1391*.txt"):
stamp = fname.split(".")[1]
times, tempa = np.loadtxt(fname).T
times = map(datetime.datetime.fromtimestamp, times)
times = matplotlib.dates.date2num(times)
points = np.array([times, tempa]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lc = LineCollection(segments, cmap=plt.get_cmap("jet"),
norm=plt.Normalize(0, 1))
lc.set_array(np.linspace(0,1,len(times)))
lc.set_linewidth(1)
axis.add_collection(lc)
axis.plot_date(times, tempa, "-", linewidth=2)
return fig_to_html(fig)
示例5: add_data
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def add_data(globe, axes, color_dict):
"""Add shapefile polygons to the matplotlib axes"""
file_object = shapefile.Reader(filename)
shapes = file_object.shapes()
records = file_object.records()
#iterate over all but the first 20 polygons (they're junk)
for record, shape in zip(records[20:],shapes[20:]):
#this entry is the colour code
description = record[6]
lons,lats = zip(*shape.points)
#transform the lat/long coords to the right projection
data = np.array(globe(lons, lats)).T
#shapefile shapes can have disconnected parts, we have
#to check
if len(shape.parts) == 1:
segs = [data,]
else:
segs = []
for i in range(1,len(shape.parts)):
#add all the parts
index = shape.parts[i-1]
index2 = shape.parts[i]
segs.append(data[index:index2])
segs.append(data[index2:])
#Add all the parts we've found as a set of lines
lines = LineCollection(segs,antialiaseds=(1,))
lines.set_facecolors(color_dict[description])
lines.set_edgecolors('k')
lines.set_linewidth(0.1)
#add the collection to the active axes
axes.add_collection(lines)
示例6: __plot_all
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def __plot_all(self, spectrum):
total = len(spectrum)
count = 0.0
for timeStamp in spectrum:
if self.settings.fadeScans:
alpha = (total - count) / total
else:
alpha = 1
data = spectrum[timeStamp].items()
peakF, peakL = self.extent.get_peak_fl()
segments, levels = self.__create_segments(data)
if segments is not None:
lc = LineCollection(segments)
lc.set_array(numpy.array(levels))
lc.set_norm(self.__get_norm(self.settings.autoL, self.extent))
lc.set_cmap(self.colourMap)
lc.set_linewidth(self.lineWidth)
lc.set_gid('plot')
lc.set_alpha(alpha)
self.axes.add_collection(lc)
count += 1
return peakF, peakL
示例7: doTracelines
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def doTracelines(xstart,ystart,zstart,step,tmax,Nmax):
global ActiveAxis, ActiveCanvas, ActiveTimmlModel, ActiveSettings
setActiveWindow()
win = getActiveWindow()
ActiveAxis.set_autoscale_on(False)
width = 0.5
color = []
for j in range(getActiveNumberLayers()):
color.append( ActiveSettings.get_color('Trace',j) )
color[j] = colorConverter.to_rgba( color[j] )
for i in range( len(xstart) ):
xyz, time, reason, pylayers = ActiveTimmlModel.\
traceline(xstart[i],ystart[i],zstart[i],step,tmax,Nmax,tstart=0.0,window=win,labfrac = 2.0, Hfrac = 2.0)
trace_color = []
for j in range(len(xyz)-1): # Number of segments one less than number of points
trace_color.append( color[ pylayers[j] ] )
points = zip( xyz[:,0], xyz[:,1] )
segments = zip( points[:-1], points[1:] )
LC = LineCollection(segments, colors = trace_color)
LC.set_linewidth(width)
ActiveAxis.add_collection(LC)
#ActiveAxis.plot( xyz[:,0], xyz[:,1], 'b' )
ActiveAxis.set_xlim(win[0],win[2])
ActiveAxis.set_ylim(win[1],win[3])
ActiveCanvas.draw()
示例8: addLine
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def addLine(shapefilename):
r = shapefile.Reader(shapefilename)
shapes = r.shapes()
records = r.records()
cnt = 0
for record, shape in zip(records, shapes):
print(cnt)
lons,lats = zip(*shape.points)
data = np.array(m(lons, lats)).T
if len(shape.parts) == 1:
segs = [data,]
else:
segs = []
for i in range(1,len(shape.parts)):
index = shape.parts[i-1]
index2 = shape.parts[i]
segs.append(data[index:index2])
segs.append(data[index2:])
lines = LineCollection(segs,antialiaseds=(1,), zorder=3)
# lines.set_facecolors(np.random.rand(3, 1) * 0.5 + 0.5)
lines.set_edgecolors('k')
lines.set_linewidth(0.3)
ax.add_collection(lines)
cnt += 1
示例9: colorline
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def colorline(ax, x,y,z,linewidth=1, colormap='jet', norm=None, zorder=1, alpha=1, linestyle='solid'):
cmap = plt.get_cmap(colormap)
if type(linewidth) is list or type(linewidth) is np.array or type(linewidth) is np.ndarray:
linewidths = linewidth
else:
linewidths = np.ones_like(z)*linewidth
if norm is None:
norm = plt.Normalize(np.min(z), np.max(z))
else:
norm = plt.Normalize(norm[0], norm[1])
'''
if self.hide_colorbar is False:
if self.cb is None:
self.cb = matplotlib.colorbar.ColorbarBase(self.ax1, cmap=cmap, norm=norm, orientation='vertical', boundaries=None)
'''
# Create a set of line segments so that we can color them individually
# This creates the points as a N x 1 x 2 array so that we can stack points
# together easily to get the segments. The segments array for line collection
# needs to be numlines x points per line x 2 (x and y)
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
# Create the line collection object, setting the colormapping parameters.
# Have to set the actual values used for colormapping separately.
lc = LineCollection(segments, linewidths=linewidths, cmap=cmap, norm=norm, zorder=zorder, alpha=alpha, linestyles=linestyle )
lc.set_array(z)
lc.set_linewidth(linewidth)
ax.add_collection(lc)
示例10: __plot_all
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def __plot_all(self):
total = len(self.data)
count = 0.0
for timeStamp in self.data:
if len(self.data[timeStamp]) < 2:
self.parent.threadPlot = None
return None, None
if self.fade:
alpha = (total - count) / total
else:
alpha = 1
data = self.data[timeStamp].items()
peakF, peakL = self.extent.get_peak_fl()
segments, levels = self.__create_segments(data)
lc = LineCollection(segments)
lc.set_array(numpy.array(levels))
lc.set_norm(self.__get_norm(self.autoL, self.extent))
lc.set_cmap(self.colourMap)
lc.set_linewidth(self.lineWidth)
lc.set_gid('plot')
lc.set_alpha(alpha)
self.axes.add_collection(lc)
count += 1
return peakF, peakL
示例11: load_colorado_shapes
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def load_colorado_shapes(m):
# read all US counties
rdr = shapefile.Reader("../USA_adm/USA_adm2")
shapes = rdr.shapes()
records = rdr.records()
# only keep Colorado counties
ndx = filter(lambda i: records[i][4] == 'Colorado', np.arange(len(shapes)))
shapes = [shapes[i] for i in ndx]
records = [records[i] for i in ndx]
# modified from web tutorial
# http://www.geophysique.be/2013/02/12/matplotlib-basemap-tutorial-10-shapefiles-unleached-continued/
line_col = []
for record, shape in zip(records, shapes):
lons,lats = zip(*shape.points)
data = np.array(m(lons, lats)).T
if len(shape.parts) == 1:
segs = [data,]
else:
segs = []
for i in range(1,len(shape.parts)):
index = shape.parts[i-1]
index2 = shape.parts[i]
segs.append(data[index:index2])
segs.append(data[index2:])
lines = LineCollection(segs, antialiaseds=(1,))
lines.set_edgecolors('k')
lines.set_linewidth(0.8)
line_col.append(lines)
return line_col
示例12: plot_spectrum
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def plot_spectrum(el,x=arange(2),offset=[0.,0.],ax=None,lw=3,**kwargs):
'''
Plot spectrum.
el:
the data.
x:
the lower and upper limit of x.
offset:
the displace of data.
ax:
the ax.
'''
N=len(el)
if ax==None:
ax=gca()
#x=repeat([array(x)+offset[0]],N,axis=0).T
x=array(x)+offset[0]
el=el+offset[1]
lc=LineCollection([[(x[0],el[i]),(x[1],el[i])] for i in xrange(N)],**kwargs)
lc.set_linewidth(lw)
#pl=ax.plot(x,concatenate([el[newaxis,...],el[newaxis,...]],axis=0))
ax.add_collection(lc)
ax.autoscale()
ax.margins(0.1)
#for i in xrange(N):
#axhline(y=el[i],xmin=x[0],xmax=x[1])
return ax
示例13: traceShape
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def traceShape(file_shapefile):
r = shapefile.Reader(file_shapefile)
shapes = r.shapes()
records = r.records()
#sc_fac = 100000
for record, shape in zip(records,shapes):
#print shape.points
lonsh,latsh = zip(*shape.points)
# lonsh = [x/sc_fac for x in lonsh]
# latsh = [x/sc_fac for x in latsh]
data = np.array(m(lonsh, latsh)).T
if len(shape.parts) == 1:
segs = [data,]
else:
segs = []
for i in range(1,len(shape.parts)):
index = shape.parts[i-1]
index2 = shape.parts[i]
segs.append(data[index:index2])
segs.append(data[index2:])
lines = LineCollection(segs,antialiaseds=(1,))
# lines.set_facecolors(cm.jet(np.random.rand(1)))
lines.set_edgecolors('k')
lines.set_linewidth(0.1)
ax.add_collection(lines)
return None
示例14: plotflow
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def plotflow(nm,j,ylabel='Congestion Window Size',state=False):
i=0
if state and not isinstance(nm,list):
r = (1,0,0)
g = (0,1,0)
b = (0,0,1)
clrs = np.zeros((flows[nm][3].shape[0],3))
clrs[flows[nm][-1]=='SS']=g
clrs[flows[nm][-1]=='CA']=b
clrs[flows[nm][-1]=='FR']=r
points = np.array([flows[nm][i], flows[nm][j]]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lc = LineCollection(segments, colors=clrs)
lc.set_linewidth(1.7)
fig, ax = plt.subplots()
ax.add_collection(lc)
ax.autoscale_view()
line_ss = mlines.Line2D([], [], color='green', label='Slow Start')
line_ca = mlines.Line2D([], [], color='blue', label='Congestion Avoidance')
line_fr = mlines.Line2D([], [], color='red', label='Fast Recovery')
plt.legend(handles=[line_ss,line_ca,line_fr])
else:
if isinstance(nm,list):
for n in nm:
if n in flows:
plt.plot(flows[n][i],flows[n][j],label=n)
else:
plt.plot(flows[nm][i],flows[nm][j])
plt.legend()
plt.xlabel('time (s)')
plt.ylabel(ylabel)
plt.show()
示例15: plot
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_linewidth [as 别名]
def plot(ax, x, y, time, sim_type):
assert(len(x) == len(y) == len(time))
l = len(time)
if use_hf_coloration:
time_to_grayscale = 0.8 / 23.6 # for HF coloring
else:
time_to_grayscale = 0.8 / time[l-1]
colors = []
for i in range(l-1):
if use_hf_coloration:
color = get_hf_color(time[i]) # time[] is really HF
else:
g = 0.8 - (time[i] * time_to_grayscale)**2.0
if sim_type == 'driven':
color = (g, 1.0, g, 0.8)
else:
color = (g, g, 1.0, 1.0)
colors.append(color)
points = zip(x,y)
segments = zip(points[:-1], points[1:])
lc = LineCollection(segments, colors=colors)
lc.set_alpha(1.0)
lc.set_linewidth(1.0)
lc.set_antialiased(True)
ax.add_collection(lc)
if use_hf_coloration:
end_points.append((x[l-1], y[l-1], get_hf_color(time[l-1])))
else:
end_points.append((x[l-1], y[l-1], COLOR[sim_type]))