반응형
그래프 위트 Matplotlib의 배경색 불투명도를 설정하는 방법
저는 Matplotlib를 가지고 놀았는데 그래프의 배경색을 변경하는 방법이나 배경을 완전히 투명하게 만드는 방법을 알 수 없습니다.
그림과 좌표축 모두의 전체 배경을 투명하게 사용 transparent=True
하여 그림 을 간단하게 사용할 수 있습니다 fig.savefig
.
예 :
import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot(range(10))
fig.savefig('temp.png', transparent=True)
보다 세밀한 제어를 원하면 그림 및 좌표축 배경 패치에 대한 얼굴 색상 및 / 또는 알파 값을 설정하기 만하면됩니다. (패치를 완전히 투명하게 만들기 위해 알파를 0으로 설정하거나 얼굴 색상을 'none'
(객체가 아닌로 None
!)로 접근 할 수 있습니다 .
예 :
import matplotlib.pyplot as plt
fig = plt.figure()
fig.patch.set_facecolor('blue')
fig.patch.set_alpha(0.7)
ax = fig.add_subplot(111)
ax.plot(range(10))
ax.patch.set_facecolor('red')
ax.patch.set_alpha(0.5)
# If we don't specify the edgecolor and facecolor for the figure when
# saving with savefig, it will override the value we set earlier!
fig.savefig('temp.png', facecolor=fig.get_facecolor(), edgecolor='none')
plt.show()
반응형
'ProgramingTip' 카테고리의 다른 글
자바 펼쳐에서 '정의되지 않음'을 처리하는 방법 (0) | 2020.12.08 |
---|---|
이 UI 패턴은 무엇입니까? (0) | 2020.12.08 |
Jenkins / Hudson- 현재 빌드 번호에 액세스하고 있습니까? (0) | 2020.12.08 |
numpy에서 부울 배열을 그대로 배열로 바꾸는 방법 (0) | 2020.12.08 |
네트워크 인터페이스와 올바른 IPv4 주소는 어떻게 얻습니까? (0) | 2020.12.08 |