시간이지나면서 진화하는 3D 선 궤도를 그려보고자하며, 시간이 지나가도록 색을 변경하고 싶습니다 (예 : 하늘색에서 진한 파란색까지). 그러나 matplotlib의 Line3DCollection
사용에 대한 자습서가 부족합니다. this is the closest 찾을 수는 있지만 모두 내가 흰 선을 얻고 있습니다.Matplotlib Line3 시간에 따라 변하는 색상을위한 색상 표기
여기 내 코드가 있습니다.
import matplotlib.pyplot as plot
from mpl_toolkits.mplot3d.axes3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Line3DCollection
import numpy as np
# X has shape (3, n)
c = np.linspace(0, 1., num = X.shape[1])[::-1]
a = np.ones(shape = c.shape[0])
r = zip(a, c, c, a) # an attempt to make red vary from light to dark
# r, which contains n tuples of the form (r,g,b,a), looks something like this:
# [(1.0, 1.0, 1.0, 1.0),
# (1.0, 0.99998283232330165, 0.99998283232330165, 1.0),
# (1.0, 0.9999656646466033, 0.9999656646466033, 1.0),
# (1.0, 0.99994849696990495, 0.99994849696990495, 1.0),
# ...,
# (1.0, 1.7167676698312416e-05, 1.7167676698312416e-05, 1.0),
# (1.0, 0.0, 0.0, 1.0)]
fig = plot.figure()
ax = fig.gca(projection = '3d')
points = np.array([X[0], X[1], X[2]]).T.reshape(-1, 1, 3)
segs = np.concatenate([points[:-1], points[1:]], axis = 1)
lc = Line3DCollection(segs, colors = r)
ax.add_collection3d(lc)
ax.set_xlim(-0.45, 0.45)
ax.set_ylim(-0.4, 0.5)
ax.set_zlim(-0.45, 0.45)
plot.show()
그러나, 여기에 내가 무엇을 얻을 : 흰색 선 세그먼트의
그냥 무리, 색상에 어떤 변화. 내가 도대체 뭘 잘못하고있는 겁니까? 감사!
무엇 '과 같이 r'는 무엇입니까? 작은 샘플이면 충분합니다. 시작과 끝 부분에 몇 줄이 좋습니다! – PearsonArtPhoto
정의 아래에'r'의 구조를 추가했습니다. – Magsol