Choose colors for bar3d matplotlib plot

Viewed 88

My data looks like that (but way bigger):

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

data = np.array([[0.1 , 0.1 , 0.3 , 27 , 27 ],
                [0.1 , 0.1 , 0.3 , 27 , 27 ],
                [0.1 , 0.1 , 0.3, 7, 7 ],
                [11 , 11, 9.01, 0.1, 0.1 ],
                [11 , 11, 0.3, 0.1, 0.1 ]])

My plot works like that:

fig = plt.figure(figsize=(5, 5), dpi=150)
ax1 = fig.add_subplot(111, projection='3d')

xpos = np.arange(data.shape[0])
ypos = np.arange(data.shape[1])
xposM, yposM = np.meshgrid(xpos, ypos, copy=False)

dx = 1
dy = 1
dz = data.ravel()

values = np.linspace(0.2, 1., xposM.ravel().shape[0])
colors = cm.rainbow(values)
ax1.bar3d(xposM.ravel(), yposM.ravel(), dz * 0, dx, dy, dz, color=colors)

And the result is a nice colorful plot (something like that How to make error bars for a 3D Bar graph?) but I would like to choose the colors for the plot according to the following list. The problem is, that I need these specific values for the z axis to represent height, that is why I can not just normalize the data.

color_list = [[0.1, 'grey'], [0.3, 'yellowgreen'], [7, 'black'], [9.01, 'darkgreen'], [11, 'black'], [27, 'black']]

Does anyone have an idea how to do this? Thanks in advance!

0 Answers
Related