hexa
import numpy as np
def gen_one_hexa_coord(self,r=float(1),orient= stack ):
# 輸出指定半逕、方曏的以原點爲中心的六邊形坐標
r = 1
theta = np.arange(-30,390,60)
if orient == hexagonal :
#默認方曏爲stack
theta = theta 30
elif orient == stack :
pass
else:
exit( usage: orient is hexagonal or stack )
print(theta)
theta= theta/180*np.pi
x = r*np.cos(theta)
y = r*np.sin(theta)
coord = list()
for x1,y1 in zip(x,y):
coord.append([x1,y1])
return coord
def gen_multi_hexa_coord(self,center_coords):
#調用上一個函數,生成中心(center)在不同位置的六邊形坐標
for center in center_coords:
print(gen_one_hexa_coord())
return 0
print(ployone.gen_one_hexa_coord())
print(ployone.gen_multi_hexa_coord([1]))
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
import numpy as np
from matplotlib.patches import Circle, Wedge, Polygon
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
resolution = 50 # the number of vertices
N = 3
patches = []
for i in range(5):
#隨機生成的三角形,三個二維的數。
polygon = Polygon(np.random.rand(3,2))
print(polygon)
patches.append(polygon)
print( patchs number is str(len(patches)))
colors=np.arange(0,len(patches))
#colors = 100 * np.random.rand(len(patches))
# bwr 與 coolwarm均可
#p = PatchCollection(patches, alpha=0.4,cmap=matplotlib.cm.coolwarm)
clist0=[ blue , white , red ]
clist1=[ green , white , magenta ]
newcmp0 = LinearSegmentedColormap.from_list( chaos ,clist0)
newcmp1 = LinearSegmentedColormap.from_list( chaos ,clist1)
p = PatchCollection(patches, alpha=0.4,cmap=newcmp1)
p.set_array(colors)
ax.add_collection(p)
fig.colorbar(p, ax=ax)
fig.show()
fig.savefig(fname= name.png )
fig.clf()
0條評論