【发布时间】:2016-04-16 03:27:03
【问题描述】:
我正在尝试制作一个包含六个独立地块的图形,以两排三个地块组织。每行图都应该有自己的颜色条,对应于水平组中三个图中显示的图像。从视觉上看,该图应如下所示:
image_type1 | image_type1 | image_type1 | colorbar_for_type1_images
image_type2 | image_type2 | image_type2 | colorbar_for_type2_images
上图中的竖线只是为了分隔图形的不同组成部分。我的图中实际上不需要垂直线。
下面显示了我正在尝试做的一个示例,以及我尝试使用每行中的第三个图像绘制颜色条的失败尝试。
过去,当我将自己的颜色图用于一系列绘制线时,我已经能够使用类似于下面显示的代码成功地做到这一点,而不是像我一样用于图像正在尝试在下面做。
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.cbook import get_sample_data
#Make 6 plotting areas of the same dimensions
figuresizex = 9.0
figuresizey = 6.1
lowerx = .07
lowery = .09
upperx = .92
uppery = .97
xspace = .05
yspace = .11
xwidth = (upperx-lowerx-2*xspace)/3.
ywidth = (uppery-lowery-yspace)/2.
fig = plt.figure(figsize=(figuresizex,figuresizey))
ax1 = fig.add_axes([lowerx,lowery+ywidth+yspace,xwidth,ywidth])
ax2 = fig.add_axes([lowerx+xwidth+xspace,lowery+ywidth+yspace,xwidth,ywidth])
ax3 = fig.add_axes([lowerx+2*xwidth+2*xspace,lowery+ywidth+yspace,xwidth,ywidth])
ax4 = fig.add_axes([lowerx,lowery,xwidth,ywidth])
ax5 = fig.add_axes([lowerx+xwidth+xspace,lowery,xwidth,ywidth])
ax6 = fig.add_axes([lowerx+2*xwidth+2*xspace,lowery,xwidth,ywidth])
axlist = [ax1,ax2,ax3,ax4,ax5,ax6]
#Start plotting images
image = np.identity(5)
for i in range(0,3):
vmin, vmax = image.min(),image.max()
axuse = axlist[i]
im = axuse.imshow(image, vmin=vmin, vmax=vmax)
if i == 3:
cbar = axuse.colorbar(im)
cbar = plt.colorbar(im)
image_2 = np.arange(16).reshape((4,4))
for i in range(0,3):
vmin, vmax = image_2.min(),image_2.max()
axuse = axlist[i+3]
axuse.imshow(image_2,vmin=vmin, vmax=vmax)
if i == 3:
cbar = axuse.colorbar()
cbar = plt.colorbar()
plt.show()
【问题讨论】:
标签: python matplotlib plot colorbar