本文整理汇总了Python中matplotlib.collections.LineCollection.set_edgecolors方法的典型用法代码示例。如果您正苦于以下问题:Python LineCollection.set_edgecolors方法的具体用法?Python LineCollection.set_edgecolors怎么用?Python LineCollection.set_edgecolors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.LineCollection
的用法示例。
在下文中一共展示了LineCollection.set_edgecolors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_view
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
def plot_view(result):
# Determine bounding box if no clipping boundary was supplied
if not result['bbox']:
result['bbox'] = bbox_of_view(result)
ax = plt.subplot(111)
# plt.box(on=None)
m = Basemap(resolution='i',
projection='merc',
llcrnrlat=result['bbox']['ymin'],
urcrnrlat=result['bbox']['ymax'],
llcrnrlon=result['bbox']['xmin'],
urcrnrlon=result['bbox']['xmax'],
lat_ts=(result['bbox']['xmin'] +
result['bbox']['xmax']) / 2)
m.drawcoastlines()
try:
for el in result['results']:
vectors = get_vectors_from_postgis_map(m, loads(el['geom']))
lines = LineCollection(vectors, antialiaseds=(1, ))
lines.set_facecolors('black')
lines.set_edgecolors('white')
lines.set_linewidth(1)
ax.add_collection(lines)
m.fillcontinents(color='coral', lake_color='aqua')
# If AttributeError assume geom_type 'Point', simply collect all
# points and perform scatterplot
except AttributeError:
xy = m([loads(point['geom']).x for point in result['results']],
[loads(point['geom']).y for point in result['results']])
plt.scatter(xy[0], xy[1])
plt.show()
示例2: traceShape
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [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
示例3: draw_shp_polygons
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
def draw_shp_polygons(self, shp_filepath, linewidths=0.2, colors='k', antialiaseds=None, linestyles='solid'):
"""
Draw a shapefile containing polygons
"""
# Read the shapefile as shapes and records. For each polygon in shapes, draw its boundaries
r = shapefile.Reader(shp_filepath)
shapes = r.shapes()
records = r.records()
for record, shape in zip(records, shapes):
lons, lats = zip(*shape.points)
data = [(x, y) for x, y in zip(*self(lons, lats))]
# shape.parts is a list containing the starting index of each part of shape (e.g. a lake inside the shape) on xy_pts. If shape contains only 1 part, a list containing 0 is returned.
if len(shape.parts) == 1:
segs = [data, ]
else:
segs = []
for npart in range(1, len(shape.parts)):
ix1 = shape.parts[npart-1]
ix2 = shape.parts[npart]
segs.append(data[ix1:ix2])
segs.append(data[ix2: ])
lines = LineCollection(segs, antialiaseds = [1, ])
lines.set_edgecolors(colors)
lines.set_linestyle(linestyles)
lines.set_linewidth(linewidths)
self.ax.add_collection(lines)
示例4: load_colorado_shapes
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [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
示例5: add_data
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [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: addLine
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [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
示例7: plot_countries
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
def plot_countries(countries, world):
if type(countries) != list:
countries = [countries]
ax = plt.subplot(111)
m = get_region_map(countries, world)
for country in countries:
shpsegs = []
for ring in country['SHAPE']:
x, y = geo2map_coord(ring, m)
shpsegs.append(zip(x,y))
lines = LineCollection(shpsegs,antialiaseds=(1,))
lines.set_facecolors(cm.jet(np.random.rand(1)))
lines.set_edgecolors('k')
#lines.set_linewidth(0.3)
ax.add_collection(lines)
plt.show()
示例8: algo
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
def algo (region,output, word):
reg = [0 for i in range(0,23)]
total = 0
for line in region: #reg_num number
items = line.rstrip('\n').split('\t')
reg[int(items[0])]=int(items[1])
total = total+int(items[1])
reg=np.array(reg)
max_percent=np.max(reg)
plt.figure(figsize=(15,15))
ax = plt.subplot(111)
m = Basemap(projection='merc', lat_0=45, lon_0=0,
resolution = 'h', area_thresh = 10.0,
llcrnrlat=41.33, llcrnrlon=-5,
urcrnrlat=51.5, urcrnrlon=9.7)
m.drawcoastlines()
#m.drawcountries() # french border does not fit with region ones
m.fillcontinents(color='lightgrey',lake_color='white')
m.drawmapboundary(fill_color='white')
sf = shapefile.Reader("./geodata/FRA_adm1")
shapes = sf.shapes()
records = sf.records()
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.5)
lines.set_facecolors('brown')
lines.set_alpha(float(reg[record[3]])/max_percent) #record[3] est le numero de region
ax.add_collection(lines)
plt.savefig(word+'-'+str(total)+'.png',dpi=300)
return 0
示例9: plot
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
def plot(self, ax=None, cmapname=None, cmap=None, linewidth=1,
edgecolor='grey', facecolor=None, alpha=1):
"""Plot the geometries on the basemap using the defined colors
Parameters:
-----------
ax : matplotlib.axis object
An axis object for plots. Overwrites the self.ax attribute.
cmapname : string
Name of the color map from matplotlib (LINK!) (default: 'seismic')
cmap : matplotlib colormap
You can create you own colormap and pass it to the plot.
linewidth : float
Width of the lines.
edgecolor : string, float or iterable
Definition of the edge color. Can be an iterable with a color
definition for each geometry, a string with one color for
all geometries or a float to define one color for all geometries
from the cmap.
facecolor : string, float or iterable
Definition of the face color. See edgecolor.
alpha : float
Level of transparency.
"""
if ax is not None:
self.ax = ax
n = 0
if facecolor is None:
facecolor = self.color
if edgecolor is None:
edgecolor = self.color
if cmapname is not None:
self.cmapname = cmapname
if self.data is not None:
self.data = np.array(self.data)
if cmap is None:
cmap = plt.get_cmap(self.cmapname)
for geo in self.geometries:
vectors = self.get_vectors_from_postgis_map(geo)
lines = LineCollection(vectors, antialiaseds=(1, ))
lines.set_facecolors(self.select_color(facecolor, cmap, n))
lines.set_edgecolors(self.select_color(edgecolor, cmap, n))
lines.set_linewidth(linewidth)
lines.set_alpha(alpha)
self.ax.add_collection(lines)
n += 1
示例10: drawcountry
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
def drawcountry(self,
ax,
base_map,
iso2,
color,
alpha = 1):
if iso2 not in self.countries:
raise ValueError, "Where is that country ?"
vertices = self.countries[iso2]
shape = []
for vertex in vertices:
longs, lats = zip(*vertex)
# conversion to plot coordinates
x,y = base_map(longs, lats)
shape.append(zip(x,y))
lines = LineCollection(shape,antialiaseds=(1,))
lines.set_facecolors(cm.hot(np.array([color,])))
lines.set_edgecolors('white')
lines.set_linewidth(0.5)
lines.set_alpha(alpha)
ax.add_collection(lines)
示例11: plot_europe_map
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
def plot_europe_map(country_weights, b=None, ax=None):
"""
Plot a map from shapefiles with coutnries colored by gamma. Inspired by Magnus.
"""
if ax == None:
ax = plt.subplot(111)
m = Basemap(llcrnrlon=-10., llcrnrlat=30., urcrnrlon=50., urcrnrlat=72.,
projection='lcc', lat_1=40., lat_2=60., lon_0=20.,
resolution='l', area_thresh=1000.,
rsphere=(6378137.00, 6356752.3142))
m.drawcoastlines(linewidth=0)
r = shapefile.Reader(r'settings/ne_10m_admin_0_countries/ne_10m_admin_0_countries')
all_shapes = r.shapes()
all_records = r.records()
shapes = []
records = []
for country in all_countries:
shapes.append(all_shapes[shapefile_index[country]])
records.append(all_records[shapefile_index[country]])
country_count = 0
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_facecolor(cmap(country_weights[country_count]))
lines.set_edgecolors('k')
lines.set_linewidth(0.3)
ax.add_collection(lines)
country_count += 1
if b: plt.text(1.5e5, 4e6, r'$\beta = ' + str(b) + r'$', fontsize=12)
示例12: draw_map
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
def draw_map(x1=6., x2=11., y1=45., y2=48.):
### PARAMETERS FOR MATPLOTLIB :
import matplotlib as mpl
mpl.rcParams['font.size'] = 10.
mpl.rcParams['font.family'] = 'Bitstream Vera Sans'
mpl.rcParams['axes.labelsize'] = 8.
mpl.rcParams['xtick.labelsize'] = 6.
mpl.rcParams['ytick.labelsize'] = 6.
#fig = plt.figure(figsize=(11.7,8.3))
#Custom adjust of the subplots
plt.subplots_adjust(left=0.05,right=0.95,top=0.90,bottom=0.05,wspace=0.15,hspace=0.05)
ax = plt.subplot(111)
m = Basemap(resolution='i',projection='merc', llcrnrlat=y1,urcrnrlat=y2,llcrnrlon=x1,urcrnrlon=x2,lat_ts=(x1+x2)/2)
m.drawcountries(linewidth=0.5)
m.drawcoastlines(linewidth=0.5)
m.drawparallels(np.arange(y1,y2,2.),labels=[1,0,0,0],color='black',dashes=[1,1],labelstyle='+/-',linewidth=0.2) # draw parallels
m.drawmeridians(np.arange(x1,x2,2.),labels=[0,0,0,1],color='black',dashes=[1,1],labelstyle='+/-',linewidth=0.2) # draw meridians
m.bluemarble()
r = shapefile.Reader(r"borders/CHE_adm3")
shapes = r.shapes()
records = r.records()
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_facecolors(cm.jet(np.random.rand(1)))
lines.set_edgecolors('k')
lines.set_linewidth(0.05)
ax.add_collection(lines)
return (plt, m)
示例13: get_rivers
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
def get_rivers(mmap=None):
import shapefile
# from matplotlib.patches import Polygon
from matplotlib.collections import LineCollection
shf = '/home/raul/Github/basemap_shaded/sonoma_rivers/sonoma_rivers'
s = shapefile.Reader(shf)
shapes = s.shapes()
Nshp = len(shapes)
segs = []
for n in range(Nshp):
pts = shapes[n].points
lons, lats = zip(*pts)
x, y = mmap(lons, lats)
segs.append(zip(x, y))
lines = LineCollection(segs)
lines.set_edgecolors('b')
lines.set_linewidth(1)
return lines
示例14: range
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
dbf = dbflib.open('../states/statesp020')
for npoly in range(shp.info()[0]):
# draw colored polygons on the map
shpseqs = []
shp_object = shp.read_object(npoly)
verts = shp_object.vertices()
rings = len(verts)
for ring in range(rings):
lons, lats = zip(*verts[ring])
x, y = m(lons,lats)
shpsegs.append(zip(x,y))
if ring == 0:
shapedict = dbf.read_record(npoly)
name = shapedict['STATE']
lines = LineCollection(shpsegs,antialiased=(1,))
# state_to_code dict, e.g. 'ALASKA' -> 'AK', omitted
try:
per = obama[state_to_code[name.upper()]]
except KeyError:
continue
lines.set_facecolors('k')
lines.set_alpha(0.75 * per) # shrink the percentage a bit
lines.set_edgecolors('k')
lines.set_linewidth(0.3)
ax.add_collection(lines)
plt.show()
示例15: map_communities_and_commutes
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_edgecolors [as 别名]
def map_communities_and_commutes(G):
G_mod = nx.read_gml("/home/sscepano/D4D res/allstuff/User movements graphs/commuting patterns/1/total_commuting_G_scaled_weights_11COM_713_7115.gml")
col = [str]*256
for i in range(256):
col[i] = 'w'
for node in G_mod.nodes_iter(data=True):
#print node[1]['label']
col_gephi = node[1]['graphics']['fill']
while (len(col_gephi) < 7):
col_gephi += '0'
subpref_gephi = int(float(node[1]['label']))
print subpref_gephi, col_gephi
col[subpref_gephi] = col_gephi
#print col
plt.clf()
plt.subplots_adjust(left=0.05,right=0.95,top=0.90,bottom=0.05,wspace=0.15,hspace=0.05)
ax = plt.subplot(111)
m = Basemap(llcrnrlon=-9, \
llcrnrlat=3.8, \
urcrnrlon=-1.5, \
urcrnrlat = 11, \
resolution = 'h', \
projection = 'tmerc', \
lat_0 = 7.38, \
lon_0 = -5.30)
# read the shapefile archive
s = m.readshapefile('/home/sscepano/DATA SET7S/D4D/SubPrefecture/GEOM_SOUS_PREFECTURE', 'subpref')
from shapelib import ShapeFile
import dbflib
from matplotlib.collections import LineCollection
from matplotlib import cm
shp = ShapeFile(r'/home/sscepano/DATA SET7S/D4D/SubPrefecture/GEOM_SOUS_PREFECTURE')
dbf = dbflib.open(r'/home/sscepano/DATA SET7S/D4D/SubPrefecture/GEOM_SOUS_PREFECTURE')
for npoly in range(shp.info()[0]):
shpsegs = []
shpinfo = []
shp_object = shp.read_object(npoly)
verts = shp_object.vertices()
rings = len(verts)
for ring in range(rings):
lons, lats = zip(*verts[ring])
x, y = m(lons, lats)
shpsegs.append(zip(x,y))
if ring == 0:
shapedict = dbf.read_record(npoly)
#print shapedict
name = shapedict["ID_DEPART"]
subpref_id = shapedict["ID_SP"]
# add information about ring number to dictionary.
shapedict['RINGNUM'] = ring+1
shapedict['SHAPENUM'] = npoly+1
shpinfo.append(shapedict)
#print subpref_id
#print name
lines = LineCollection(shpsegs,antialiaseds=(1,))
lines.set_facecolors(col[subpref_id])
lines.set_edgecolors('gray')
lines.set_linewidth(0.3)
ax.add_collection(lines)
m.drawcoastlines()
plt.show()
# # data to plot on the map
# lons = [int]*256
# lats = [int]*256
#
# # read in coordinates fo subprefs
# file_name2 = "/home/sscepano/DATA SET7S/D4D/SUBPREF_POS_LONLAT.TSV"
# f2 = open(file_name2, 'r')
#
# # read subpref coordinates
# subpref_coord = {}
# for line in f2:
# subpref_id, lon, lat = line.split('\t')
# lon = float(lon)
# lat = float(lat)
# subpref_id = int(subpref_id)
# subpref_coord.keys().append(subpref_id)
# subpref_coord[subpref_id] = (lon, lat)
#
# f2.close()
#
# # if wanna plot number of users whose this is home subpref
# for subpref in range(1,256):
# lons[subpref] = subpref_coord[subpref][0]
# lats[subpref] = subpref_coord[subpref][1]
#
#
# if G.has_node(-1):
#.........这里部分代码省略.........