Renyi-Fan

matplotlib_200730系列---13、次坐标轴

一、总结

一句话总结:

I、ax2=axl.twinx(); #Create a twin Axes sharing the xaxis
II、axl.plot(x,y1,\'g-\'); ax2.plot(x,y2,\'b--\');
import matplotlib.pyplot as plt 
import numpy as np

x=np.arange(0,10,0.1)
y1=0.05*x**2
y2=-1*y1

fig,axl=plt.subplots()
# 镜像
# Create a twin Axes sharing the xaxis
ax2=axl.twinx()
axl.plot(x,y1,\'g-\')
ax2.plot(x,y2,\'b--\')
axl.set_xlabel(\'X data\')
axl.set_ylabel(\'Y1\', color=\'g\') 
ax2.set_ylabel(\'Y2\', color=\'b\')

plt.show()       
               

 

 

 

二、次坐标轴

博客对应课程的视频位置:

 

import matplotlib.pyplot as plt 
import numpy as np

x=np.arange(0,10,0.1)
y1=0.05*x**2
y2=-1*y1

fig,axl=plt.subplots()
# 镜像
# Create a twin Axes sharing the xaxis
ax2=axl.twinx()
axl.plot(x,y1,\'g-\')
ax2.plot(x,y2,\'b--\')
axl.set_xlabel(\'X data\')
axl.set_ylabel(\'Y1\', color=\'g\') 
ax2.set_ylabel(\'Y2\', color=\'b\')

plt.show()       
               

 

 

 

 

 

 

分类:

技术点:

相关文章: