10 examples of 'matplotlib draw line between two points' in Python

Every line of 'matplotlib draw line between two points' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
17def line(x, y, angle, plt):
18 line = mpl.patches.Ellipse(xy=(x,y), width=0.8, height=0.3,
19 angle=angle, facecolor="none",
20 edgecolor="#000000", linewidth=3)
21 plt.gca().add_artist(line)
22 return plt
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

271def lines(x, y, ax=None, **kwargs):
272 """Add lines to the most recent plot.
273
274 """
275 if ax is None:
276 global _last_axis_
277 ax = _last_axis_
278 ax.plot(x, y, **kwargs)
183def DrawLine(X=[0,1],Y=[0,1],LineColor='k',LineWidth=1,LineStyle="-",LineAlpha=0.3):
184 plt.plot(X,Y,color=LineColor, linewidth=LineWidth, linestyle=LineStyle,alpha= LineAlpha)
35def Line(self, a, b, color = (1,0,0), linewidth=1):
36 if isinstance(a[0], (list, tuple)):
37 la = a
38 lb = b
39 else:
40 la = [a]
41 lb = [b]
42 for pa, pb in zip(la, lb):
43 line = plt.Line2D(pa, pb, lw = linewidth, color = color)
44 plt.gca().add_line(line)
393def _plot_line(path_):
394 if not use_path:
395 sxy_, exy_ = path_
396 objs.extend(ax.plot([sxy_[0], exy_[0]], [
397 sxy_[1], exy_[1]], lw=lw, color=color,
398 zorder=zorder, ls=ls, solid_capstyle=solid_capstyle))
399 else:
400 obj = patches.PathPatch(path_, lw=lw, facecolor='none', edgecolor=color,
401 zorder=zorder, ls=ls)
402 objs.append(obj)
403 ax.add_patch(obj)
327def GraphicsStraightenLine(point1, point2):
328 dx = point2[0] - point1[0]
329 dy = point2[1] - point1[1]
330
331 if dx == 0:
332 return
333 elif abs(float(dy) / dx) > 1:
334 point2[0] = point1[0]
335 else:
336 point2[1] = point1[1]
87def addCanvasDashedWedge(self,p1,p2,p3,dash=(2,2),color=(0,0,0),
88 color2=None,**kwargs):
89 canvas = self._axes
90 dash= (3,3)
91 pts1 = self._getLinePoints(p1,p2,dash)
92 pts2 = self._getLinePoints(p1,p3,dash)
93 pts1 = [self.rescalePt(p) for p in pts1]
94 pts2 = [self.rescalePt(p) for p in pts2]
95 if len(pts2)<len(pts1):
96 pts2,pts1=pts1,pts2
97 for i in range(len(pts1)):
98 if color2 and color2!=color:
99 mp = (pts1[i][0]+pts2[i][0])/2.,(pts1[i][1]+pts2[i][1])/2.
100 canvas.add_line(Line2D((pts1[i][0],mp[0]),(pts1[i][1],mp[1]),color=color,**kwargs))
101 canvas.add_line(Line2D((mp[0],pts2[i][0]),(mp[1],pts2[i][1]),color=color2,**kwargs))
102 else:
103 canvas.add_line(Line2D((pts1[i][0],pts2[i][0]),(pts1[i][1],pts2[i][1]),color=color,**kwargs))
113def draw_lines():
114 """
115 Draws a line between a set of random values
116 """
117 r = numpy.random.randn(200)
118 fig = pyplot.figure()
119 ax = fig.add_subplot(111)
120 ax.plot(r)
121
122 ax.grid(True)
123
124 pyplot.savefig(lines_filename)
46def plot_lines(axis, object, color='#00b700'):
47 for line in object:
48 x, y = line.xy
49 ax.plot(x, y, color=color, alpha=0.4, linewidth=1, solid_capstyle='round', zorder=2)
185def draw_line(self,pt1,pt2,color=(1,1,1,1)):
186 if len(color) == 3:
187 color = (*color,1)
188 glBegin(GL_LINES)
189 glColor4f(*color)
190 glVertex2f(*pt1)
191 glVertex2f(*pt2)
192 glEnd()

Related snippets