반응형
matplotlib 플롯에서 xticks를 제거 하시겠습니까?
semilogx 플롯이 있고 xticks를 제거하고 싶습니다. 나는 시도했다 :
plt.gca().set_xticks([])
plt.xticks([])
ax.set_xticks([])
그리드가 사라지지만 (주) 진드기 자리에 작은 진드기가 남아 있습니다. 그것들을 제거하는 방법?
이 tick_params
방법은 이와 같은 것들에 매우 유용합니다. 이 코드는 주 눈금과 부 눈금을 끄고 x 축에서 레이블을 제거합니다.
from matplotlib import pyplot as plt
plt.plot(range(10))
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom=False, # ticks along the bottom edge are off
top=False, # ticks along the top edge are off
labelbottom=False) # labels along the bottom edge are off
plt.show()
plt.savefig('plot')
plt.clf()
OP가 요구하는 것이 아니라 모든 축 선, 눈금 및 레이블을 비활성화하는 간단한 방법은 다음과 같습니다.
plt.axis('off')
matplotlib 메일 링리스트 에서 찾은 대체 솔루션은 다음과 같습니다 .
import matplotlib.pylab as plt
x = range(1000)
ax = plt.axes()
ax.semilogx(x, x)
ax.xaxis.set_ticks_position('none')
또는 빈 눈금 위치를 전달하고 레이블을 다음과 같이 지정할 수 있습니다.
plt.xticks([], [])
John Vinyard가 제공하는 것보다 더 좋고 더 간단한 해결책이 있습니다. 사용 NullLocator
:
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.show()
plt.savefig('plot')
희망이 도움이됩니다.
레이블을 제거하려면이 방법을 시도하십시오 (틱은 제외).
import matplotlib.pyplot as plt
plt.setp( ax.get_xticklabels(), visible=False)
이 스 니펫은 xticks 만 제거하는 데 도움이 될 수 있습니다.
from matplotlib import pyplot as plt
plt.xticks([])
이 스 니펫은 xticks와 yticks를 모두 제거하는 데 도움이 될 수 있습니다.
from matplotlib import pyplot as plt
plt.xticks([]),plt.yticks([])
# remove all the ticks (both axes), and tick labels on the Y axis
plt.tick_params(top='off', bottom='off', left='off', right='off', labelleft='off', labelbottom='on')
참고 URL : https://stackoverflow.com/questions/12998430/remove-xticks-in-a-matplotlib-plot
반응형
'Programing' 카테고리의 다른 글
이미지 아래의 공백 제거 (0) | 2020.04.11 |
---|---|
여러 단계 항목에 대한 자식에서 치명적인 오류가 발생합니다. (0) | 2020.04.11 |
헤더를 사용하여 C #에서 CSV 파일 구문 분석 (0) | 2020.04.11 |
쿼리 문자열없이 URL을 얻는 방법이 있습니까? (0) | 2020.04.11 |
루비 버전을 바꾸지 않는 rbenv (0) | 2020.04.11 |