1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| x=np.arange(-5,5,0.1) y=x*3
fig = plt.figure(num=1, figsize=(15, 8),dpi=80)
ax1 = fig.add_subplot(2,1,1)
ax2 = fig.add_subplot(2,1,2)
print(fig,ax1,ax2)
fig,axarr = plt.subplots(4,1)
ax1 = axarr[0]
print(fig,ax1)
ax1 = plt.subplot(1,1,1,facecolor='white')
print(ax1)
ax1.set_title('python-drawing')
ax1.set_xlabel('x-name')
ax1.set_ylabel('y-name')
plt.axis([-6,6,-10,10])
ax1.set_xlim(-5,5)
ax1.set_ylim(-10,10)
xmajorLocator = MultipleLocator(2)
ymajorLocator = MultipleLocator(3)
ax1.xaxis.set_major_locator(xmajorLocator)
ax1.yaxis.set_major_locator(ymajorLocator)
ax1.xaxis.grid(True, which='major')
ax1.yaxis.grid(True, which='major')
ax1.set_xticks([])
ax1.set_xticks((-5,-3,-1,1,3,5))
ax1.set_xticklabels(labels=['x1','x2','x3','x4','x5'],rotation=-30,fontsize='small')
plot1=ax1.plot(x,y,marker='o',color='g',label='legend1')
plot2=ax1.plot(x,y,linestyle='--',alpha=0.5,color='r',label='legend2')
ax1.legend(loc='upper left')
ax1.text(2.8, 7, r'y=3*x')
ax1.annotate('important point', xy=(2, 6), xytext=(3, 1.5), arrowprops=dict(facecolor='black', shrink=0.05),)
ax1.grid(b=True,which='major',axis='both',alpha= 0.5,color='skyblue',linestyle='--',linewidth=2)
axes1 = plt.axes([.2, .3, .1, .1], facecolor='y')
axes1.plot(x,y)
plt.savefig('aa.jpg',dpi=400,bbox_inches='tight')
plt.show()
|