matplotlib4 详解 复杂图形

lesson17两根坐标轴

x= np.arange(2,20,1)

y1 = x*x

y2 = np.log(x)

plt.plot(x,y1)

plt.twinx()

plt.plot(x,y2,color ='r')

plt.show()


面向对象的做法

x= np.arange(2,20,1)

y1 = x*x

y2 = np.log(x)

fig = plt.figure()

ax1= fig.add_subplot(111)

ax1.plot(x,y1)

ax1.set_ylabel('Y1')

ax2 = ax1.twinx()

ax2.plot(x,y2,'r')

ax2.set_ylabel('Y2')

ax1.set_xlabel('Compare Y1 and Y2')

plt.show(ax1)



双X轴

x= np.arange(2,20,1)

y1 = x*x

y2 = np.log(x)

fig = plt.figure()

ax1= fig.add_subplot(111)

ax1.plot(y1,x)

ax1.set_xlabel('Y1')

ax2 = ax1.twiny()

ax2.plot(y2,x,'r')

ax2.set_xlabel('Y2')

#ax1.set_xlabel('Compare Y1 and Y2')

plt.show(ax1)




lesson 18 画标志性箭头说明

 

x = np.arange(-10,11,1)

y = x*x

plt.plot(x,y)

plt.annotate('this is the bottom',xy=(0,1),xytext = (0,20),

arrowprops =dict(facecolor ='r',frac=0.2,headwidth =30, width =20))

plt.show()



lesson 19 如何画出文字

x = np.arange(-10,11,1)

y = x*x

plt.text(-2,40,"function: y=x*x", family = 'fantasy',size =20, color ='g',style ='italic',

weight =1000, bbox=dict(facecolor='r',alpha= 0.5))

plt.plot(x,y)

plt.show()






http://matplotlib.org/users/mathtext.html

lesson 20 数学公式

fig=plt.figure()

ax=fig.add_subplot(111)

ax.set_xlim(1,7)

ax.set_ylim(1,5)

ax.text(2,4,r"$ \alpha_i \beta_j \pi\lambda \omega $", size =15)

ax.text(4,4,r"$ \sina(0) =\cos(\frac{\pi}{2})  $", size =15)

ax.text(2,2,r"$ \lim_{x \rightarrow y}\frac{1} {x^3} $", size =15)

ax.text(4,2,r"$ \sqrt[4]{x} = \sqrt{y}$", size =15)

plt.show()




lesson 21 弹出框的技巧

N =1000

x = np.random.rand(N)

y = np.random.rand(N)

colors = np.random.rand(N)

area = np.pi*(15*np.random.rand(N)**2)

plt.scatter(x,y, s=area, c=colors,alpha=0.5)

plt.show()



lesson 22 填充颜色

 

x=np.linspace(0,5*np.pi,1000)

y1=np.sin(x)

y2=np.sin(2*x)

plt.fill(x,y1,"b",alpha =0.3)

plt.fill(x,y2,'r',alpha =0.3)

plt.show()



x=np.linspace(0,5*np.pi,1000)

y1=np.sin(x)

y2=np.sin(2*x)

fig=plt.figure()

ax=plt.gca()

#ax.plot(x,y1,x,y2,color ='k')

#ax.fill_between(x,y1,y2,facecolor ='blue')

ax.fill_between(x,y1,y2, where= y1>=y2,facecolor ='yellow',interpolate = True)

ax.fill_between(x,y1,y2, where= y2>=y1,facecolor ='green',interpolate = True)

plt.show()


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值