2017-07-03 3 views

Antwort

2

Also vielleicht nicht genau das, was Sie suchen (vielleicht ein guter Ausgangspunkt für Sie), aber verwenden

Getting individual colors from a color map in matplotlib

kann für die Stäbe unterschiedlicher Unifarben geben:

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt 
import matplotlib.cm as cm   # import colormap stuff! 
import numpy as np 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
x, y = np.random.rand(2, 100) * 4 
hist, xedges, yedges = np.histogram2d(x, y, bins=4, range=[[0, 4], [0, 4]]) 

# Construct arrays for the anchor positions of the 16 bars. 
# Note: np.meshgrid gives arrays in (ny, nx) so we use 'F' to flatten xpos, 
# ypos in column-major order. For numpy >= 1.7, we could instead call meshgrid 
# with indexing='ij'. 
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25) 
xpos = xpos.flatten('F') 
ypos = ypos.flatten('F') 
zpos = np.zeros_like(xpos) 

# Construct arrays with the dimensions for the 16 bars. 
dx = 0.5 * np.ones_like(zpos) 
dy = dx.copy() 
dz = hist.flatten() 

cmap = cm.get_cmap('jet') # Get desired colormap 
max_height = np.max(dz) # get range of colorbars 
min_height = np.min(dz) 

# scale each z to [0,1], and get their rgb values 
rgba = [cmap((k-min_height)/max_height) for k in dz] 

ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=rgba, zsort='average') 

plt.show() 

enter image description here

Persönlich finde ich das hässlich wie Sünde! Aber es wird wahrscheinlich nicht schlecht mit einer sequentiellen Farbkarte aussehen - https://matplotlib.org/examples/color/colormaps_reference.html