Issue
I want to change the alpha of the edge lines of those polygons independent of the matplotlib patches Polygon. I want the edge lines to have alpha greater than the patches of polygons. And the patch is going beyond the edge line how to fit the patch perfectly on the edge line so it doesn't go outside the polygon.
Here is the code:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Polygon
from scipy.spatial import ConvexHull
hull = ConvexHull(points)
# plt.plot(points[:,0], points[:,1], 'o')
cent = np.mean(points, 0)
pts = []
for pt in points[hull.simplices]:
pts.append(pt[0].tolist())
pts.append(pt[1].tolist())
pts.sort(key=lambda p: np.arctan2(p[1] - cent[1],
p[0] - cent[0]))
pts = pts[0::2] # Deleting duplicates
pts.insert(len(pts), pts[0])
k = 0.4
poly = Polygon(k*(np.array(pts)- cent) + cent,fill=True,closed=True,
facecolor=color, alpha=0.2,edgecolor=color,linewidth=7)
plt.gca().add_patch(poly)
plt.show()
Output is here:
Solution
I think you might need to draw them separately - basically:
poly = Polygon(k*(np.array(pts)- cent) + cent,fill=True,closed=True,
facecolor=color, alpha=0.2)
polyEdge = Polygon(k*(np.array(pts)- cent) + cent,fill=False,closed=True,
alpha=0.8,edgecolor=color,linewidth=7)
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Polygon
from scipy.spatial import ConvexHull
points = np.array([(.30,.60), (.50,.40), (0,.30),(.15,.25),(.20,0),(.50,.10),(.55,.20),(.70,.30)])
hull = ConvexHull(points)
# plt.plot(points[:,0], points[:,1], 'o')
cent = np.mean(points, 0)
pts = []
for pt in points[hull.simplices]:
pts.append(pt[0].tolist())
pts.append(pt[1].tolist())
color='red'
pts.sort(key=lambda p: np.arctan2(p[1] - cent[1],
p[0] - cent[0]))
pts = pts[0::2] # Deleting duplicates
pts.insert(len(pts), pts[0])
k = 0.4
poly = Polygon(k*(np.array(pts)- cent) + cent,fill=True,closed=True,
facecolor=color, alpha=0.2)
polyEdge = Polygon(k*(np.array(pts)- cent) + cent,fill=False,closed=True,
alpha=0.8,edgecolor=color,linewidth=7)
plt.gca().add_patch(poly)
plt.gca().add_patch(polyEdge)
plt.show()
Answered By - James_SO
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.