美文网首页
matploblib 分格显示

matploblib 分格显示

作者: Do_More | 来源:发表于2017-07-19 09:42 被阅读0次

1.方法1 subplot2grid

image.png
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

# method 1: subplot2grid
plt.figure()
ax1 = plt.subplot2grid((3,3),(0,0),colspan=3,rowspan=1)
ax1.plot([1,2],[1,2])
ax1.set_title('ax1_title')
ax2 = plt.subplot2grid((3,3),(1,0),colspan=2,)
ax3 = plt.subplot2grid((3,3),(1,2),rowspan=2)
ax4 = plt.subplot2grid((3,3),(2,0))
ax5 = plt.subplot2grid((3,3),(2,1))

plt.tight_layout()
plt.show()

2.方法2 gridspec

image.png
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

# method 2: gridspec
plt.figure()
gs = gridspec.GridSpec(3,3)
ax1 = plt.subplot(gs[0,:])
ax2 = plt.subplot(gs[1,:2])
ax3 = plt.subplot(gs[1:,2])
ax4 = plt.subplot(gs[-1,0])
ax5 = plt.subplot(gs[-1,-2])

plt.tight_layout()
plt.show()

3.方法3

image.png
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

# method 3: easy to define structure
f,((ax11, ax12),(ax21, ax22)) = plt.subplots(2,2,sharex=True,sharey=True)
ax11.scatter([1,2],[1,2])

plt.tight_layout()
plt.show()

相关文章

网友评论

      本文标题:matploblib 分格显示

      本文链接:https://www.haomeiwen.com/subject/wkokkxtx.html