Matplotlib로 반 픽셀을 나타내지 않음
Oct 30 2020
누구든지 사용하여 대각선 행렬 의 픽셀 의 절반 을 표현하지 못할 수 있는지 알고 plt.imshow()있습니까?
이것은 내가 찾고있는 것을 그래픽으로 표현했습니다.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
import matplotlib
bins = 5
Z = np.random.rand(bins, bins)
# Select lower triangle values:
condition = np.tril(np.ones((Z.shape))).astype(np.bool)
Z = np.where(condition, Z, np.nan)
fig, ax = plt.subplots(figsize = (8,8))
ax.imshow(Z, cmap = 'Spectral')
마스크로 이미지를 덮어서이 작업을 수행 할 수 있다고 생각 하지만, 오히려 피하고 싶은 옵션 입니다.
답변
2 DizietAsahi Oct 30 2020 at 22:06
Patchmatplotlib에서 객체를 클리핑 마스크로 사용할 수 있습니다 . 보다https://matplotlib.org/3.1.0/gallery/images_contours_and_fields/image_clip_path.html
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
import matplotlib
bins = 5
Z = np.random.rand(bins, bins)
# Select lower triangle values:
condition = np.tril(np.ones((Z.shape))).astype(np.bool)
Z = np.where(condition, Z, np.nan)
fig, ax = plt.subplots()
im = ax.imshow(Z, cmap = 'Spectral')
tri = matplotlib.patches.Polygon([(0,0),(1,0),(0,1)], closed=True, transform=ax.transAxes)
im.set_clip_path(tri)