需要帮助,以mplot3d调整多边形的3D集合

时间:2018-10-30 02:21:58

标签: python numpy matplotlib graph

我正在使用当前代码根据常见的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()

大多数情况下都可以,但是我有几个问题。

  1. 网格未在预期平面中显示(例如x = 0,y = 0,z = 0)。当所有三个轴的'0'刻度线不在角落或沿边缘对齐时,我最终会遇到一些视差问题,这些问题确实使视角无法正常工作。我该如何解决?
  2. 从某些角度看,多边形看起来顺序错误。例如,蓝绿色实际上在蓝色的前面。是什么原因造成的?
  3. 打开xkcd样式会使我的网格线消失。我试图将其修复无济于事。这有什么区别?我知道我已经看过带有网格线的3D xkcd图了-是打破它的3D吗?
  4. 我可以更改3D图上刻度线和刻度线标签之间的间距吗?很难确定哪个网格线与哪个温度一致。
  5. 感谢您的光临!

Parallax issue (orange curve appears to be at 80C

Orange curve is actually at 85C

enter image description here

0 个答案:

没有答案