3d folded chart with matplotlib

I worked on a simple 3D diagram using the following code:

from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection = "3d") ax.set_xlabel("x") ax.set_ylabel("y") ax.set_zlabel("z") ax.set_xlim3d(0,10) ax.set_ylim3d(0,10) ax.set_zlim3d(0,2) xpos = [2,5,8,2,5,8,2,5,8] ypos = [1,1,1,5,5,5,9,9,9] zpos = np.zeros(9) dx = np.ones(9) dy = np.ones(9) dz = np.ones(9) ax.bar3d(xpos, ypos, zpos, dx, dy, dz) plt.gca().invert_xaxis() plt.show() 

Thinking of it as a test, everything seems clear so far. I just wondered how I can build each of these 9 bars in a complex way, so, for example, each bar is divided into 4 parts, which make up the whole bar.

Basically, I think about it in the example here.

But instead of two stacks, I want to have 4. Any ideas how to proceed from what I am now? Every hint would be so appreciated.

Thanks!

edit: if I want to implement the given values ​​for each laid out line, for example:

 ... z = [np.array([ 0.2, 0.6, 0.3, 0.6, 0.4, 0.3, 0.8, 0.5, 0.7]), np.array([ 0.8, 0.4, 0.5, 0.2, 0.8, 0.7, 0.4, 0.2, 0.9]), np.array([ 0.1, 0.2, 0.4, 0.4, 0.2, 0.6, 0.3, 0.6, 0.9]), np.array([ 0.9, 0.5, 0.7, 0.2, 0.5, 0.6, 0.7, 0.9, 0.7])] dz = [z for i in range(4)] ... 

This doesn't seem to work, and I don't know why?

+5
source share
1 answer

To create a complex 3d bar chart, you can copy the dz values ​​and use them as a base for each next line. Here is an example:

enter image description here

 from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection = "3d") ax.set_xlabel("x") ax.set_ylabel("y") ax.set_zlabel("z") ax.set_xlim3d(0,10) ax.set_ylim3d(0,10) xpos = [2,5,8,2,5,8,2,5,8] ypos = [1,1,1,5,5,5,9,9,9] zpos = np.zeros(9) dx = np.ones(9) dy = np.ones(9) dz = [np.random.random(9) for i in range(4)] # the heights of the 4 bar sets _zpos = zpos # the starting zpos for each bar colors = ['r', 'b', 'g', 'y'] for i in range(4): ax.bar3d(xpos, ypos, _zpos, dx, dy, dz[i], color=colors[i]) _zpos += dz[i] # add the height of each bar to know where to start the next plt.gca().invert_xaxis() plt.show() 
+5
source

All Articles