我有一个带有三个子图的人物。前两个子图共享相似的数据范围,而下一个子图显示具有不同数据范围的数据。我只想对整个图形使用一个颜色条,在颜色条的左边有两个顶部的子图,而在颜色条的右边有下面两个子图的对号(参见下面的图)。
我已经能够使用肮脏的技巧做到这一点,即通过在彼此顶部显示两个颜色条并将其中一个的刻度线向左移动。例如,我修改了this matplotlib example:
import matplotlib.pyplot as plt
import numpy as np
# Fixing random state for reproducibility
np.random.seed(19680801)
# create three subplots
fig, axes = plt.subplots(3)
# filling subplots with figures and safing the map of the first and third figure.
# fig 1-2 have a data range of 0 - 1
map12 =axes[0].imshow(np.random.random((100, 100)), cmap=plt.cm.BuPu_r)
axes[1].imshow(np.random.random((100, 100)), cmap=plt.cm.BuPu_r)
# figure 3 has a larger data range from 0 - 5
map3 = axes[2].imshow(np.random.random((100, 100))*5, cmap=plt.cm.BuPu_r)
# Create two axes for the colorbar on the same place.
# They have to be very slightly missplaced, else a warning will appear and only the second colorbar will show.
cax12 = plt.axes([0.85, 0.1, 0.075, 0.8])
cax3 = plt.axes([0.85, 0.100000000000001, 0.075, 0.8])
# plot the two colorbars
cbar12 = plt.colorbar(map12, cax=cax12, label='ticks for top two figs')
cbar3 = plt.colorbar(map3, cax=cax3, label='ticks for bottom fig')
# move ticks and label of second plot to the left
cbar12.ax.yaxis.set_ticks_position('left')
cbar12.ax.yaxis.set_label_position('left')
## display image
plt.show()
虽然我对视觉效果感到满意,但我认为必须有更好的方法来做到这一点。一个问题是,如果将其另存为矢量图形,最终将出现重叠的形状。另外,如果您对下部颜色栏的颜色有误,您可能不会意识到这是因为颜色被隐藏了,或者如果您出于某种原因要使颜色栏明显透明,则可能会令您头痛。因此,我想知道如何才能做到这一点?或者,如果有更好的破解方法,如果无法做到这一点呢?