plt.figure(figsize=(12,6))x_positions=np.linspace(0,1,10)colors=plt.cm.rainbow(np.linspace(0,1,10))forx,colorinzip(x_positions,colors):plt.axvline(x=x,color=color,linestyle='-',linewidth=1)plt.title('Multiple Vertical Lines using Loop - how2matplotlib.com')plt.xlabel('X-axis')p...
import matplotlib.pyplot as plt # draw vertical lines on a given plot plt.axvline(x=0.34211321321) plt.axvline(x=0.7012231312) plt.axvline(x=0.4353452542) The output Method-2: Vlines Another function that helps draw vertical lines on a given plot is vlines function, the arguments are sam...
→ ax.legend(frameon=False) … show error as shaded region? → ax.fill_between(X, Y+error, Y‐error) … draw a rectangle? → ax.add_patch(plt.Rectangle((0, 0),1,1) … draw a vertical line? → ax.axvline(x=0.5) … draw outside frame? → ax.plot(…, clip_on=False) … ...
x=np.linspace(0,10,100)y=np.sin(x)*np.cos(x)plt.figure(figsize=(10,6))plt.plot(x,y,label='sin(x) * cos(x)')# 添加带箭头标签的垂直线plt.axvline(x=4,color='g',linestyle='-.')plt.annotate('Maximum',xy=(4,0),xytext=(4.5,0.4),arrowprops=dict(facecolor='black',shrink=0...
self.fig.canvas.restore_region(self.background)ymin,ymax=self.axes.get_ylim()x=event.xdata-1# draw each vertical lineforlineinself.verticalLines:line.set_xdata((x,))line.set_ydata((ymin,ymax))self.axes.draw_artist(line)x+=1self.fig.canvas.blit(self.axes.bbox)defsetFig(self):'''...
Also, check:Draw vertical line matplotlib In this Python tutorial, we have discussed the “Matplotlib dashed line” and we have also covered some examples related to it. There are the following topics that we have discussed in this tutorial. ...
# draw line # https://stackoverflow.com/questions/36470343/how-to-draw-a-line-with-matplotlib/36479941 def newline(p1, p2, color='black'): ax = plt.gca() l = mlines.Line2D([p1[0],p2[0]], [p1[1],p2[1]], color='red' if p1[1]-p2[1] > 0 else 'green', marker='o',...
line.set_ydata(np.sin(x)) return line, # call the animator. blit=True means only re-draw the parts that have changed. # blit=True dose not work on Mac, set blit=False # interval= update frequency #frames帧数 ani = animation.FuncAnimation(fig=fig, func=animate, frames=100, init_func...
line1.set_xdata(x) line1.set_ydata(updated_y) figure.canvas.draw() ...
self.horizontal_line.set_ydata(y) self.vertical_line.set_xdata(x) self.text.set_text('x=%1.2f, y=%1.2f' % (x, y)) self.ax.figure.canvas.draw() y = np.arange(0, 1, 0.01) x = np.sin(2 * 2 * np.pi * y) fig, ax = plt.subplots() ...