'Matplotlib multiple colorbars

I need four different color bars for a single plot. My plot consists of 5 subplots, but only the first one requires four different color bar plots. I would like to position them below a graph. I achieved it, but my color bars are of different sizes:

enter image description here

For your reference, my figure is split into 5 figures using the matplotlib subplot2grid method. A minimal working example (without subplot2grid) is shown below:

import matplotlib.pyplot as plt
import numpy as np

frame = np.zeros([512, 512])

fig = plt.figure(figsize=(16, 8))
ax = plt.imshow(frame)

for i in range(4):
    plt.colorbar(fraction=0.046, pad=0.04, location="bottom")

plt.show()

How do I position the color bar plots below the plot and them next to each other and of the same length (e.g. the same length as the first bar plot, or image size)?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source