back to thematplotlib-gallery
athttps://github.com/rasbt/matplotlib-gallery
%load_ext watermark
%watermark -u -v -d -p matplotlib,numpy
Last updated: 16/08/2014 CPython 3.4.1IPython 2.0.0matplotlib 1.3.1numpy 1.8.2
%matplotlib inline
frommatplotlibimportpyplotaspltimportnumpyasnpplt.pie((10,5),labels=('spam','ham'),shadow=True,colors=('yellowgreen','lightskyblue'),explode=(0,0.15),# space between slicesstartangle=90,# rotate conter-clockwise by 90 degreesautopct='%1.1f%%',# display fraction as percentage)plt.legend(fancybox=True)plt.axis('equal')# plot pyplot as circleplt.tight_layout()plt.show()
frommatplotlibimportpyplotaspltimportmatplotlib.triastriimportnumpyasnprand_data=np.random.randn(50,2)triangulation=tri.Triangulation(rand_data[:,0],rand_data[:,1])plt.triplot(triangulation)plt.show()
importmatplotlib.pyplotaspltx=[1,2,3]y_1=[50,60,70]y_2=[20,30,40]withplt.xkcd():plt.plot(x,y_1,marker='x')plt.plot(x,y_2,marker='^')plt.xlim([0,len(x)+1])plt.ylim([0,max(y_1+y_2)+10])plt.xlabel('x-axis label')plt.ylabel('y-axis label')plt.title('Simple line plot')plt.legend(['sample 1','sample2'],loc='upper left')plt.show()
importnumpyasnpimportrandomfrommatplotlibimportpyplotaspltdata=np.random.normal(0,20,1000)bins=np.arange(-100,100,5)# fixed bin sizewithplt.xkcd():plt.xlim([min(data)-5,max(data)+5])plt.hist(data,bins=bins,alpha=0.5)plt.title('Random Gaussian data (fixed bin size)')plt.xlabel('variable X (bin size = 5)')plt.ylabel('count')plt.show()
frommatplotlibimportpyplotaspltimportnumpyasnpwithplt.xkcd():X=np.random.random_integers(1,5,5)# 5 random integers within 1-5cols=['b','g','r','y','m']plt.pie(X,colors=cols)plt.legend(X)plt.show()