import matplotlib.pyplot as plt
import numpy as np
import random
fig, ax = plt.subplots(figsize=(10, 6), dpi=300)
for i in range(1,7):
# This simply creates some random data to populate with
a = np.arange(10)
x, y = np.meshgrid(a, a)
z = np.random.randint(0, 7, (10, 10))
plt.subplot(2,3,i)
im=plt.contourf(x, y, z)
# Tight layout is optional
fig.tight_layout()
fig.subplots_adjust(right=0.825)
cax = fig.add_axes([0.85, 0.06, 0.035, 0.91])
fig.colorbar(im, cax=cax)
plt.show()
您可以通过在其自己的轴上添加
colorbar
来完成此操作。这可以通过手动创建一个附加轴并根据需要使用subplots_adjust()
和add_axes()
移动现有绘图来完成在本例中,
add_axes()
的参数是[left, bottom, width, height]
。这会产生类似编辑
要删除图间坐标轴标签、刻度线等,需要对上面的方法进行一些不平凡的修改,其中
^{pr2}$plt.subplots()
用于填充子图对象的2x3
数组,然后我们对其进行迭代。E、 g相关问题 更多 >
编程相关推荐