2017-03-20 29 views
2

このプロットで軸ラベルの配置に問題があります。私はパイプがグリッド、右と左のラベルがプロットに触れないようにアライメントするようにトップラベルを配置するのが好きです。matplotlibの対数プロット軸ラベルの配置

私は

ax.tick_params(axis='both', which='both', pad=15) 

をしようとしたが、それは効果がありません。また、

rcParams 

は、プロットのログスケールと矛盾するようです。ハックとして、私は空白を試しましたが、これらはLaTeXを各単語の最初と最後に削除しました。最後に、私は見えないUnicode記号を試しましたが、matplotlibだけがクラッシュしました。

ご協力いただきありがとうございます。

log-polar plot

enter image description here

import numpy 
from matplotlib import pyplot as plt 
ax = plt.subplot(111, polar=True) 
plt.rc('text', usetex=True) 
plt.rc('font', family='serif') 
ax.set_xticks(numpy.linspace(0, 2 * 3.14, 4, endpoint=False)) 
ax.set_theta_direction(-1) 
ax.set_theta_offset(3.14/2.0) 
plt.ylim(0, 2.5) 
ax.set_xticklabels([ 
    r'$100,000\,{\rm yr}|10\,{\rm yr}$', 
    r'$100\,{\rm yr}$', 
    r'$1000\,{\rm yr}$', 
    r'$10,000\,{\rm yr}$'], 
    fontsize=16) 
plt.show() 

答えて

0

トリックは、それらの位置に応じて異なるtextlabelsを整列させることができます。つまり、左のラベルは右揃え、右のラベルは左揃えにする必要があります。

トップラベルの場合は、最初のラベルが左揃えになり、最後のラベルが右揃えになるように分割すると意味があります。

import numpy as np 
from matplotlib import pyplot as plt 

ax = plt.subplot(111, polar=True) 
ticks = np.linspace(0, 2 * np.pi, 5, endpoint=True) 
ax.set_xticks(ticks) 
ax.set_theta_direction(-1) 
ax.set_theta_offset(3.14/2.0) 
plt.ylim(0, 2.5) 
ax.set_xticklabels([ 
    r'$10\,{\rm yr}$', 
    r'$100\,{\rm yr}$', 
    r'$1000\,{\rm yr}$', 
    r'$10,000\,{\rm yr}$', r"$100,000\,{\rm yr}|$"], 
    fontsize=16) 

aligns = ["left", "left", "center", "right", "right"] 
for tick, align in zip(ax.get_xticklabels(), aligns): 
    tick.set_ha(align) 

plt.show() 

enter image description here

+0

ありがとう!よく働く。 – Michael

関連する問題