혼동 문서화 오프셋 및 transOffset의 역할. PolyCollection의 데이터 좌표에 offsets
을 사용하려면 transOffset
을 ID 변환으로 설정하고 offset_position
을 "데이터"로 변경해야합니다.
collections.PolyCollection([vtx], offsets=[(0,0),(20,10),(40,60)],
transOffset=mtransforms.IdentityTransform(),
offset_position="data")
완벽한 예 :
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import collections
import matplotlib.transforms as mtransforms
subplot_kw = dict(xlim=(0, 100), ylim=(0, 100))
fig, ax = plt.subplots(subplot_kw=subplot_kw, figsize=(5,5))
ivtx = 10 * np.array([-1,-1,1,1])/2.0
jvtx = 20 * np.array([-1,1,1,-1])/2.0
vtx = np.array(zip(jvtx, ivtx))
rectangles = collections.PolyCollection([vtx], offsets=[(0,0),(20,10),(40,60)],
transOffset=mtransforms.IdentityTransform(),
offset_position="data")
ax.add_collection(rectangles)
plt.show()
대안은 즉 수동으로 변환, 직접 정점을 계산하는 과정이다 :
import numpy as np
from matplotlib import collections
import matplotlib.pyplot as plt
subplot_kw = dict(xlim=(-20,70), ylim=(-20, 70))
fig, ax = plt.subplots(figsize=(5,5),subplot_kw=subplot_kw) #,
ivtx = 10 * np.array([-1,-1,1,1])/2.0
jvtx = 20 * np.array([-1,1,1,-1])/2.0
vtx = np.array(zip(jvtx, ivtx))
def o(vtx, o):
vtx = np.copy(vtx)
vtx[:,0] = vtx[:,0]+o[0]
vtx[:,1] = vtx[:,1]+o[1]
return vtx
offsets=[(0,0),(20,10),(40,60)]
rectangles = collections.PolyCollection([o(vtx,offset) for offset in offsets])
ax.add_collection(rectangles)
plt.show()
것을 무엇 나는 끝났다. 하고있어. 그래도 나는 오프셋이 얼마나 효과적인지 궁금하다. – physcheng