I have a plot in which I merge two datas. Given that, I have to show two different color bars, one for each data. I’m currently plotting my datas as follows:
plt.figure()
# Data 1
fig = plt.imshow(data1, interpolation='nearest', cmap='binary', vmin=0, vmax=1)
# Plotting just the nonzero values of data2
data2_x = numpy.nonzero(data2)[0]
data2_y = numpy.nonzero(data2)[1]
pts = plt.scatter(data2_x, data2_y, marker='s', c=data2[data2_x, data2_y])
plt.colorbar(pts)
plt.colorbar(fig, orientation="horizontal")
And this is the plot that I get:
However, I would like to reposition the color bars to have something like this (made with Photoshop):
Is that possible?
Thank you in advance.
2
Answers
you can link the colorbar to the axes with the ax-keyword, plt.gca() gives you the current axes:
Probably the ‘easiest’ way to do this is to lay the axes to be used for the color bars out by hand (via
cbax = fig.add_axes([....])
). You can then pass that axes to the color bar calls:Something like: