Matplotlib에서 해치 밀도를 줄이기 위해 다음 단계를 수행할 수 있습니다. -
-
Figure 크기를 설정하고 서브플롯 사이와 주변의 패딩을 조정합니다.
-
밀도를 재정의하는 사용자 정의 수평 해치 클래스를 만듭니다.
-
수평 해치 클래스를 추가합니다.
-
새 그림을 만들거나 기존 그림을 활성화하세요.
-
'ax1' 추가 하위 플롯 배열의 일부로 그림에.
-
데이터 포인트 목록을 만드십시오.
-
x로 막대 그래프 만들기 및 y 데이터 포인트, hatch='o', color='green' 및 edgecolor='빨간색' .
-
그림을 표시하려면 show()를 사용하세요. 방법.
예시
from matplotlib import pyplot as plt, hatch
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
class MyHorizontalHatch(hatch.HorizontalHatch):
def __init__(self, hatch, density):
char_count = hatch.count('o')
if char_count > 0:
self.num_lines = int((1.0 / char_count) * density)
else:
self.num_lines = 0
self.num_vertices = self.num_lines * 2
super().__init__(hatch, density)
hatch._hatch_types.append(MyHorizontalHatch)
fig = plt.figure()
ax1 = fig.add_subplot(111)
x = [3, 6, 1]
y = [4, 6, 1]
ax1.bar(x, y, color='green', edgecolor='red', hatch="o", lw=1., zorder=0)
plt.show() 출력
