我正在使用当前代码根据常见的PolyCollection示例创建3D图形:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.collections import PolyCollection
from matplotlib.colors import colorConverter
import matplotlib.pyplot as plt
import numpy as np
#plt.xkcd()
fig = plt.figure()
ax = fig.gca(projection='3d')
def cc(arg):
return colorConverter.to_rgba(arg, alpha=0.6)
cap = 0.55 #initial capacity
xs = np.arange(0, 50, 0.02) #Time
verts = []
zs = [0.0, 20.0, 40.0, 60.0, 85.0, 100.0, 125.0] #Temps
ds = [.002, .005, .015, .03, .06, .10, .60] #Discharge rates, percent per year
drain = [190, 212, 230, 285, 460, 600, 700] #Circuit drain in nA
drain = [(d+250) * 1e-9 for d in drain] #Add in 250nA for ADC/etc, convert to A
idx = 0
for z in zs:
ys = cap*((1-ds[idx])**xs) - drain[idx]*xs*8760
ys[0], ys[-1] = 0, 0
ys[ys<0] = np.nan
verts.append(list(zip(xs, ys)))
idx+=1
poly = PolyCollection(verts, facecolors=[cc('b'), cc('teal'), cc('g'),
cc('y'), cc('orange'), cc('red'), cc('salmon')])
poly.set_alpha(0.7)
poly.set_edgecolor('k')
ax.add_collection3d(poly, zs=zs, zdir='x')
ax.set_title('Discharge Curves', loc='center')
ax.set_xlabel('Temperature (C)')
ax.set_xlim3d(0, 125)
ax.set_ylabel('Time (yrs)')
ax.set_ylim3d(0, 50)
ax.set_zlabel('Capacity (mAh)')
ax.set_zlim3d(0, 0.6)
ax.grid(True, lw=1, zorder=0)
plt.show()
大多数情况下都可以,但是我有几个问题。