调整subplot()函数的子图间距
import numpy as np
import matplotlib.pyplot as plt
for i in range(1,7):figsize = 10,6plt.subplot(2,3,i)plt.text(0.5,0.5,str((2,3,i)),fontsize=18,ha='center')
**plt.subplots_adjust(hspace=3.3, wspace=0.3)**
plt.show()
import numpy as np
import matplotlib.pyplot as plt**plt.subplots_adjust(hspace=3.3, wspace=0.3)**
for i in range(1,7):figsize = 10,6plt.subplot(2,3,i)plt.text(0.5,0.5,str((2,3,i)),fontsize=18,ha='center')plt.show()
将plt.subplots_adjust(hspace=3.3, wspace=0.3)代码置于plt.subplot()函数前面或者后面,均可以对子图横向和纵向的间距起作用
调整subplots()函数子图间距
plt.subplots_adjust(hspace=0.2, wspace=0.9)放在subplots函数的后面
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(13,22),dpi=10)
figsize = 17,8
#plt.subplots_adjust(hspace=0.3, wspace=0.9) ## 不能设置subplots的子图大小,可以设置subplot的子图大小
fig, ax = plt.subplots(2,3,sharex='col',sharey='row',figsize=figsize)
plt.subplots_adjust(hspace=0.2, wspace=0.9)
plt.savefig("test_plt.png")
print(ax)
plt.show()
可以看到,子图间距调整成功
plt.subplots_adjust(hspace=0.2, wspace=0.9)放在subplots函数前面
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(13,22),dpi=10)
figsize = 17,8
#plt.subplots_adjust(hspace=0.3, wspace=0.9) ## 不能设置subplots的子图大小,可以设置subplot的子图大小
plt.subplots_adjust(hspace=0.2, wspace=0.9)
fig, ax = plt.subplots(2,3,sharex='col',sharey='row',figsize=figsize)
plt.savefig("test_plt.png")
print(ax)
plt.show()
可以看到无法调整子图间距
plt.subplots_adjust(hspace=0.2, wspace=0.9)放置再