본문 바로가기
파이썬

파이썬 그리드를 유지하면서 x 축 눈금 제거 (matplotlib)

by º기록 2020. 12. 28.
반응형

x 축의 틱을 제거하고 싶지만 수직 띠는 유지합니다. 다음을 수행하면 x 축 눈금과 그리드가 모두 손실됩니다.

import matplotlib.pyplot as plt
fig = plt.figure() 
figr = fig.add_subplot(211)
...
figr.axes.get_xaxis().set_visible(False)
figr.xaxsis.grid(True)

x 축 눈금을 보이지 않게하는 동안 그리드를 유지하려면 어떻게해야합니까?

 

해결 방법

 

진드기를 제거한다는 것은 진드기 레이블이나 진드기 자체를 제거한다는 의미입니까? 그러면 레이블이 제거됩니다.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2*np.pi, 100)

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(x, np.sin(x))

ax.grid(True)
ax.set_xticklabels([])


plt.show()

작은 눈금 선을 정말로 없애고 싶다면 다음을 추가 할 수 있습니다.

for tic in ax.xaxis.get_major_ticks():
    tic.tick1On = tic.tick2On = False


import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2*np.pi, 100)

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(x, np.sin(x))

ax.grid(True)
for tic in ax.xaxis.get_major_ticks():
    tic.tick1On = tic.tick2On = False
    tic.label1On = tic.label2On = False

plt.show()

 

참조 페이지 https://stackoverflow.com/questions/20416609

 

 

반응형

댓글