2017-09-15 7 views
8

極座標「sypder」を作成しようとしていますが、軸ラベルに問題があります。 x軸の目盛りは、常にy軸のグリッドの下のレイヤーに表示されているように見えます(下の図に示すように、グリッドラインで囲まれています)。軸ラベルがプロットの軸によって隠されていますか?

ゾーデを設定しようとしましたが、成功しませんでした。 プロットされた線のzorderを2以上に設定すると、軸とグリッドの上に(層の点で)表示されますが、プロットの上にラベルが表示されます。私が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

関連する問題