importmatplotlib.pyplotasplt# 定义数据x=[0,1,2,3]y1=[0,1,2,3]y2=[3,2,1,0]y3=[2,1,2,1]# 创建新图形plt.figure()# 绘制不同的直线和虚线plt.plot(x,y1,label='Straight Line',color='blue',linewidth=2)plt.plot(x,y2,label='Dashed Lin
plt.plot([1,2,3,4]) plt.xlabel('some numbers') plt.ylabel('some numbers') plt.title('a straight line') 1. 2. 3. 4. 5. 6. 解释: 可以看到,画最简单的图只需要两行代码就够了 先导入plt→import matplotlib.pyplot as plt,然后画图→plt.plot([1,2,3,4]),这实际上就是5步中的第3...
关联图例的方法是plt.legend,不过需要注意的是legend方法一定要在plot完成之后调用,否则将无法呈现图例(这其实呼应了之前xlim和xticks取值的后设置后决定,这强调了plt对于图像绘制是线性执行的特点)。比如如下代码: plt.figure() plt.plot(x,y1,label='straight line') plt.plot(x,y2,linestyle='dashed',linewidth...
axes=plt.subplots(2)x=np.linspace(-2,2,10)axes[0].plot(x)axes[1].plot(x,2*x)foraxinaxes:ax.annotate('Straight Line',xy=(1,0),xycoords='axes fraction',fontsize=10,horizontalalignment='right',verticalalignment='bottom')plt.show()...
fig=Figure()canvas=FigureCanvas(fig)ax=fig.add_axes([0.1,0.1,0.8,0.8])line,=ax.plot([0,1],[0,1])ax.set_title("a straight line (OO)")ax.set_xlabel("x value")ax.set_ylabel("y value")canvas.print_figure('demo.jpg')
line,= ax.plot([0,1], [0,1]) ax.set_title("a straight line (OO)") ax.set_xlabel("x value") ax.set_ylabel("y value") canvas.print_figure('demo.jpg') 上面的例子中,我们至少构建了四个对象: fig, canvas, ax, line。它们分别属于Figure类,FigureCanvas类,Axes类和Line2D类。(使用obj...
plot([0,1], [0,1]) ax.set_title("a straight line (OO)") ax.set_xlabel("x value") ax.set_ylabel("y value") canvas.print_figure('demo.jpg') 新的demo.jpg如下: 10、理解对象 上面的例子中,我们至少构建了四个对象: fig, canvas, ax, line。它们分别属于Figure类,FigureCanvas类,Axes类...
8,6))ax.plot(x,y1,c='r',label='expoential')ax.plot(x,y2,c='g',label='Straight line...
It's a shortcut string notation described in the *Notes* section below. >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(...
cities # https://matplotlib.org/stable/users/explain/colors/colormaps.html fig, ax = plt.subplots(figsize=(12,8)) for i,v in enumerate(cityl): ax.plot(ncwide['Date'],ncwide[v],'-',color=cm.tab10(i),label=v) ax.legend() fig.savefig('Line04.png', dpi=500, bbox_inches='...