matplotlib可视化基本操作

来源:互联网 发布:python处理ajax请求 编辑:程序博客网 时间:2024/06/05 14:04
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-1,1,50)y1 = x ** 2y2 = 2*x + 1plt.figure()plt.plot(x,y1)plt.figure(num=3,figsize=(8,5))plt.xlim((-1,2))plt.ylim((-2,3))plt.xlabel('I am x')plt.ylabel('I am y')new_ticks = np.linspace(-1,2,5)plt.xticks(new_ticks)plt.yticks([-2,0.5,1],[r'$bad$',r'$good$',r'$very\ good$'])#gca = 'get current axis'ax = plt.gca()ax.spines['right'].set_color('none')ax.spines['top'].set_color('none')plt.plot(x,y1,label='up')plt.plot(x,y2,color='blue',linewidth=2.0,linestyle='--',label='down')plt.legend(loc='lower center')#loc='best'x0 = 0.5y0 = 2 * x0 + 1plt.scatter(x0,y0,s=50,color='b')plt.plot([x0,x0],[y0,0],'k--',lw=2.5)#method 1plt.annotate(r'$2x+1=%s$'%y0,xy=(x0,y0),xycoords='data',xytext=(+30,-30),textcoords='offset points',fontsize=16,arrowprops=dict(arrowstyle='->',connectionstyle='arc3,rad=.2'))#method 2plt.text(-0.5,1,r'$This\ is\ some\ text.\ \mu\ \sigma_i\ \alpha_t$',fontdict={'size':16,'color':'r'})plt.show()          


import matplotlib.pyplot as pltplt.figure()ax1 = plt.subplot2grid((3,3),(0,0),colspan=3,rowspan=1)ax1.plot([1,2],[1,2])ax1.set_title('ax1_title')ax1 = plt.subplot2grid((3,3),(1,0),colspan=2,rowspan=1)ax1 = plt.subplot2grid((3,3),(1,2),rowspan=2)ax1 = plt.subplot2grid((3,3),(2,0))                                                                                                                                                                         ax1 = plt.subplot2grid((3,3),(2,1))plt.show()


0 0
原创粉丝点击