2013-10-09 3 views
6

मैं matplotlib में एक बहुभुज ड्राइंग कर रहा हूँ। मैं अंक के सभी निर्देशांक में डाल दिया। कुछ बिंदुओं के बीच में मैं सीधे रेखाओं के बजाय 'राउंड' या 'रेडियल' किनारों को बनाना चाहता हूं (ड्राइंग पर अंक 1 और 2 कहें। क्या यह संभव है? यदि नहीं, तो इसे आकर्षित करने का सबसे प्रभावी तरीका क्या है?matplotlib - पॉलीगॉन किनारों में त्रिज्या - क्या यह संभव है?

example drawing

संपादित करें: रूगेर के समाधान काम करता है अच्छा

enter image description here

+0

तुम्हारा मतलब है तुम एक समतल वक्र फिट करने के लिए करना चाहते हैं:

matplotlib पथ ट्यूटोरियल कैसे पथ बनाया जा सकता है का विस्तृत विवरण प्रदान करता है? – doctorlove

+0

मेरा मतलब दो निर्दिष्ट बिंदुओं और त्रिज्या के साथ एक आर्क है। –

उत्तर

3

आप पथ से बहुभुज बनाकर आर्क्स का उपयोग कर सकते

एक सामान्य वर्ग:।।

import matplotlib.path as mpath 
import matplotlib.patches as patches 

verts = [(0,0), 
     (1,0), 
     (1,1), 
     (0,1), 
     (0,0)] 

codes = [mpath.Path.MOVETO] + (len(x)-1)*[mpath.Path.LINETO] 
square_verts = mpath.Path(verts, codes) 

fig, ax = plt.subplots(subplot_kw={'aspect': 1.0, 'xlim': [-0.2,1.2], 'ylim': [-0.2,1.2]}) 

square = patches.PathPatch(square_verts, facecolor='orange', lw=2) 
ax.add_patch(square) 

enter image description here

एक गोल वर्ग के साथ किया जा सकता है:

verts = [(0.2, 0.0), 
     (0.8, 0.0), # start of the lower right corner 
     (1.0, 0.0), # intermediate point (as if it wasn't rounded) 
     (1.0, 0.2), # end point of the lower right corner 
     (1.0, 0.8), # move to the next point etc. 
     (1.0, 1.0), 
     (0.8, 1.0), 
     (0.2, 1.0), 
     (0.0, 1.0), 
     (0.0, 0.8), 
     (0.0, 0.2), 
     (0.0, 0.0), 
     (0.2, 0.0)] 

codes = [mpath.Path.MOVETO, 
     mpath.Path.LINETO, 
     mpath.Path.CURVE3, 
     mpath.Path.CURVE3, 
     mpath.Path.LINETO, 
     mpath.Path.CURVE3, 
     mpath.Path.CURVE3, 
     mpath.Path.LINETO, 
     mpath.Path.CURVE3, 
     mpath.Path.CURVE3, 
     mpath.Path.LINETO, 
     mpath.Path.CURVE3, 
     mpath.Path.CURVE3] 


rounded_verts = mpath.Path(verts, codes) 

fig, ax = plt.subplots(subplot_kw={'aspect': 1.0, 'xlim': [-0.2,1.2], 'ylim': [-0.2,1.2]}) 

rounded_verts = patches.PathPatch(rounded_verts, facecolor='orange', lw=2) 
ax.add_patch(rounded_verts) 

enter image description here

अपने उदाहरण के लिए, आप एक मध्यवर्ती बिंदु जो Point1 से x-coordinate का उपयोग करता है निर्दिष्ट करने के लिए की आवश्यकता होगी और प्वाइंट 2 से y-coordinatehttp://matplotlib.org/users/path_tutorial.html

संबंधित मुद्दे