주 x 및 y 축 zorder를 엉망으로 만들지 않고 그래프 아래에 그리드 선을 그리는 데 어려움을 겪고 있습니다.
import matplotlib.pyplot as plt
import numpy as np
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd, alpha=0.9, linewidth = 0,zorder=3)
womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd, alpha=0.9, linewidth = 0,zorder=3)
# add some
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind+width)
ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') )
ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
fig.gca().yaxis.grid(True, which='major', linestyle='-', color='#D9D9D9',zorder=2, alpha = .9)
[line.set_zorder(4) for line in ax.lines]
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
plt.show()
이 예제는 matplotlib 자체에서 가져 왔으며 문제를 표시하는 방법을 보여주기 위해 약간 조정했습니다. 이미지를 게시 할 수는 없지만 코드를 실행하면 막대가 가로 격자 선과 x 및 y 축 위에 표시되는 것을 볼 수 있습니다. 특히 틱이 막힐 때 x 및 y 축이 그래프에 의해 숨겨지는 것을 원하지 않습니다.
나는 matplotlib 1.2.1, 1.3.1rc2 및 마스터를 시도했습니다 (06d014469fc5c79504a1b40e7d45bc33acc00773)
막대 위에 축 척추를 얻으려면 다음을 수행 할 수 있습니다.
for k, spine in ax.spines.items(): #ax.spines is a dictionary
spine.set_zorder(10)
편집하다
틱 라인을 막대 위에 올릴 수없는 것 같습니다. 난 노력 했어
1. ax.tick_params(direction='in', length=10, color='k', zorder=10)
#This increases the size of the lines to 10 points,
#but the lines stays hidden behind the bars
2. for l in ax.yaxis.get_ticklines():
l.set_zorder(10)
결과가없는 다른 방법. 막대를 그릴 때 위에 놓이고 zorder가 무시되는 것 같습니다.
해결 방법은 눈금 선을 바깥쪽으로 그리는 것입니다.
ax.tick_params(direction='out', length=4, color='k', zorder=10)
또는 안팎으로 direction='inout'
EDIT2
@tcaswell 댓글 후에 몇 가지 테스트를 수행했습니다.
경우 zorder
에서 ax.bar
기능 <= 2로 설정되며, 축이 ticklines 및 그리드 선 막대 위에 그려. valus가> 2.01 (축의 기본값)이면 막대가 축, 눈금 선 및 그리드 위에 그려집니다. 그런 다음 척추에 더 큰 값을 설정할 수 있지만 (위와 같이) zorder
눈금 선 을 변경하려는 시도 는 무시됩니다 (해당 아티스트에서 값이 업데이트되지만).
내가 사용하는 시도했습니다 zorder=1
에 대한 bar
및 zorder=0
그리드를위한 그리드가 그려 위에 막대의. 따라서 zorder는 무시됩니다.
요약
눈금과 격자 zorder
는 무시되고 기본값으로 유지되는 것 같습니다 . 나를 위해이 어떻게 든 관련 버그 bar
또는 일부 patches
.
BTW, 사용할 때 눈금 선에서 zorder를 성공적으로 변경 한 것을 기억합니다. imshow
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다