2017-09-15 3 views
8

나는 극 'sypder'음모를 만들려고하지만 축 레이블에 문제가 있습니다. x 축 틱 lables는 항상 y 축 그리드 아래의 레이어로 끝나는 것 같습니다 (아래 그림에서와 같이 글자는 그리드 선으로 덮여 있음).축 레이블이 플롯에서 축으로 숨겨져 있습니까?

zorders를 설정하려했지만 성공하지 못했습니다. 2 위의 플롯 된 선의 zorder를 설정하면 축과 그리드의 맨 위 (레이어 측면에서)가되지만 그래도 레이블이 플롯 맨 위에 표시되기를 원합니다. 내가 2보다 낮게 설정하면 선이 그리드 아래로 이동합니다. 눈금 또는 틱 레이블의 zorder를 설정해도 효과가없는 것 같습니다.

내 시도입니다. 그리드의 빨간색 선이 '업계'텍스트 상단에 표시되는 것처럼 보이지만 그리드의 회색 선은 아래에 있습니다. 내가 두 라인의 상단에와 플롯

import matplotlib.pyplot as plt 
import numpy as np 
import pandas as pd 
import random 

data = random.sample(range(100), 5) 
data[0] = 100 
data[3] = 50 
index = ['industry', 'residential', 'agriculture', 'transport', 'other'] 
df1 = pd.DataFrame(data, index=index, columns=['data']) 
df2 = pd.DataFrame(np.array(data)/2, index=index, columns=['data']) 

fig = plt.figure() 

ax = fig.add_subplot(111, projection="polar") 

ax.grid(True) 
ax.yaxis.grid(color='r') 
ax.xaxis.grid(color='#dddddd') 

for spine in ax.spines.values(): 
    spine.set_edgecolor('None') 

theta = np.arange(len(df1))/float(len(df1))*2.*np.pi 

l1, = ax.plot(theta, df1["data"], color="gold", marker="o", label=None, zorder=1) # , zorder = -3) 
l2, = ax.plot(theta, df2["data"], color='tomato', marker="o", label=None, zorder=1.1) #, zorder =-2) 

def _closeline(line): 
    x, y = line.get_data() 
    x = np.concatenate((x, [x[0]])) 
    y = np.concatenate((y, [y[0]])) 
    line.set_data(x, y) 
[_closeline(l) for l in [l1, l2]] 

ax.fill(theta, df1["data"], "gold", alpha=1, zorder=1) 
ax.fill(theta, df2["data"], 'tomato', alpha=1, zorder=1.1) 

ax.set_rlabel_position(216) 
ax.set_xticks(theta) 
ax.set_xticklabels(df2.index, fontsize=12)#, zorder=1) 

legend = plt.legend(handles=[l1,l2], labels =['first','second'], loc='lower right') 

plt.title("data [unit]", fontsize = 16, y = 1.2) 


plt.savefig('atlas//trial2.png', bbox_inches='tight', dpi = 300) 
plt.show() 

Here is my attempt: as you can see the red lines of the grid end up on top of the text 'industry' while the gray line of the grid stays below. I would like 'industry' to be on top of both line and of the plots

+1

나는 당신의 문제에 영향을 줄 수있는'zorder'의 여러 조합을 시도했지만 아무 소용이 없습니다. 이것은 [이 것과 유사한] 버그 일 수 있습니다 (https://github.com/matplotlib/matplotlib/issues/5045). 극좌표는 항상 직교 좌표보다 조금 더 문제가있는 것처럼 보입니다. 실행 가능한 예제로 완전한 형식의 질문에 대한 명성을! –

답변

0

음의 수 '산업'을 원하는이 그것이 좋은 대답하지 비록 내 문제를 해결합니다.

위의 스크립트에서 ax.set_xticklabels(df2.index, fontsize=12)을 다음으로 대체하여 축 레이블 대신 동등한 텍스트로 대체하십시오.

for it in np.arange(len(theta)): 
    txt = ax.text(theta[it], maxy*1.1, index[it], va = 'center', ha = 'center', fontsize = 12) 

ax.set_xticklabels('') 

이제 '레이블'이 축과 격자 위에 있습니다.

+0

현상금에 현상금이있는 동안 답변을 수락하면 다른 사람이 더 이상 문제를 조사하지 않을 수도 있습니다. 질문에 이미 수용된 해결책이 있음을 알기 때문입니다. – ImportanceOfBeingErnest

+0

덕분에, 덕분에 포인트를 되 찾을 수 있었는지 그냥 시험해 보았습니다 :) – esperluette

+0

아니요, 자신의 대답을 수락하면 점수가 손실됩니다. 다른 사람의 답변을 수락하면 해당 사람에게 보상이 주어집니다. – ImportanceOfBeingErnest

관련 문제