这篇文章主要介绍Python中Matplotlib库怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
from pylab import * n = 256 X = np.linspace(-np.pi,np.pi,n,endpoint=True) Y = np.sin(2*X) plt.axes([0.025,0.025,0.95,0.95]) plt.plot (X, Y+1, color='blue', alpha=1.00) plt.fill_between(X,1,Y+1,color='b',alpha=.25) plt.plot (X, Y-1, color='blue', alpha=1.00) plt.fill_between(X,-1,Y-1,(Y-1)>-1,color='b',alpha=.25) plt.fill_between(X,-1,Y-1,(Y-1)<-1,color='r',alpha=.25) plt.xticks([]) plt.yticks([]) plt.show()
from pylab import * n = 1024 X = np.random.normal(0,1,n) Y = np.random.normal(0,1,n) T=np.arctan2(Y,X) plt.axes([0.025,0.025,0.95,0.95]) plt.scatter(X,Y,s=60,c=T,alpha=.5) plt.xlim(-1.5,1.5) plt.ylim(-1.5,1.5) plt.xticks([]) plt.yticks([]) plt.show()
from pylab import * n = 12 X = np.arange(n) Y1 = (1-X/float(n)) * np.random.uniform(0.5,1.0,n) Y2 = (1-X/float(n)) * np.random.uniform(0.5,1.0,n) plt.bar(X, +Y1, facecolor='#9999ff', edgecolor='white') plt.bar(X, -Y2, facecolor='#ff9999', edgecolor='white') for x,y in zip(X,Y1): plt.text(x, y+0.05, '%.2f' % y, ha='center', va= 'bottom') for x1,y1 in zip(X,Y2): plt.text(x1, -y1-0.05, '%.2f' % y1, ha='center', va= 'top') plt.xlim(-.5,n),plt.xticks([]) plt.ylim(-1.25,+1.25),plt.yticks([]) plt.show()
from pylab import * def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2) n = 256 x = np.linspace(-3,3,n) y = np.linspace(-3,3,n) X,Y = np.meshgrid(x,y) plt.axes([0.025,0.025,0.95,0.95]) plt.contourf(X,Y,f(X,Y),8, alpha=.75, cmap=plt.cm.hot) C = plt.contour(X, Y, f(X,Y), 8, colors='black', linewidth=.5) plt.clabel(C,inline=1,fontsize=10) plt.xticks([]),plt.yticks([]) plt.show()
from pylab import * def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2) n = 10 x = np.linspace(-3,3,4*n) y = np.linspace(-3,3,3*n) X,Y = np.meshgrid(x,y) Z=f(X,Y) plt.axes([0.025,0.025,0.95,0.95]) plt.imshow(Z,interpolation='bicubic',cmap='bone',origin='lower') plt.colorbar(shrink=.92) plt.xticks([]), plt.yticks([])
from mpl_toolkits.mplot3d import Axes3D fig=plt.figure() ax=Axes3D(fig) x=np.arange(-4.0,4.0,0.25) y=np.arange(-4.0,4.0,0.25) X,Y=np.meshgrid(x,y) Z=np.sin(np.sqrt(X**2+Y**2)) surf=ax.plot_surface(X,Y,Z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow')) ax.contourf(X,Y,Z,zdir='z',offset=-2,cmap=plt.cm.hot) ax.set_zlim(-2,2) fig.colorbar(surf,shrink=0.5,aspect=8)
以上是“Python中Matplotlib库怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。