# 绘制第一条线 ax.plot(x, y1, label='sin(x)') ax.set_xlabel('x') ax.set_ylabel('y') ax.set_title('Multiple Lines on a Graph') ax.set_xticks([0, 2.5, 5, 7.5, 10]) # 设置刻度位置 ax.set_xticklabels(['0', '2.5', '5', '7.5', '10']) # 设置刻度标签 ax.legend(...
linewidth=2,label='Line 1')plt.axvline(x=0.5,color='blue',linestyle='--',linewidth=2,label='Line 2')plt.axvline(x=0.8,color='green',linestyle=':',linewidth=2,label='Line 3')plt.title('Multiple Vertical Lines - how2matplotlib.com')plt.xlabel('X-axis')plt.ylabel('Y-axis')plt...
importmatplotlib.pyplotasplt x=[1,2,3,4,5]y1=[2,4,6,8,10]y2=[1,3,5,7,9]plt.plot(x,y1,color='blue',label='Line 1')plt.plot(x,y2,color='red',label='Line 2')plt.title('Multiple Lines with Different Colors - how2matplotlib.com')plt.legend()plt.show() Python Copy Outpu...
y1,label='y = 0.5x + 1',color='b')plt.plot(x,y2,label='y = x - 2',color='r')plt.plot(x,y3,label='y = -0.5x + 10',color='g')# 添加标题和标签plt.title('Multiple Lines')plt.xlabel('x')plt.ylabel('y
>>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2') If you specify multiple lines with one plot call, the kwargs apply to all those lines. In case the label object is iterable, each ele...
()) ax2.yaxis.label.set_color(p2.get_color()) #倾斜的坐标轴ticklabel plt.setp(ax1.get_xticklabels(), rotation=30, ha="right",rotation_mode="anchor") #格网 ax1.grid(which='both',ls='--',alpha=0.4) #图例 lines=[p1,p2] ax1.legend(lines,[i.get_label() for i in lines]...
Example:: >>> plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2) >>> plot([1,2,3], [1,4,9], 'rs', label='line 2') If you make multiple lines with one plot command, the kwargs apply to all those lines. Here is a list of available `.Line2D` ...
# lets plot two lines Sin(x) and Cos(x)# loc is used to set the location of the legend on the plot# label is used to represent the label for the line in the legend# generate the random numberx= np.arange(0,1500,100)plt.plot(np.sin(x),label='sin function x')plt.plot(np.co...
→ fig.show(block=False), time.sleep(1) ax.grid() ax.patch.set_alpha(0) ax.set_[xy]lim(vmin, vmax) ax.set_[xy]label(label) ax.set_[xy]ticks(list) ax.set_[xy]ticklabels(list) ax.set_[sup]title(title) ax.tick_params(width=10, …) ax.set_axis_[on|off]() ax.tight_lay...
...plot(X, C, color="blue", linewidth=2.5, linestyle="-", label="cosine")plot(X, S, color="red", linewidth=2.5, linestyle="-", label="sine")legend(loc='upper left')...给一些特殊点做注释 我们希望在 $2\pi/3$ 的位置给两条函数曲线加上一个注释。首先,我们在对应的函数图像...