4
私は、左と下の軸だけを持つmatplotlibプロットを作成したいと思います。それらのそれぞれが独自に取り組む上軸と右軸を同時に削除し、ティックを外向きにプロットする方法はありますか?
が、残念ながら、両方のソリューションは、それぞれに互換性がないように見える:私は別に、両方の話題を扱う二つの質問を見つけましたその他。
:いくつかの時間のために私の頭を叩いた後、私はを言うthe
axes_grid
documentationに警告が
「をいくつかのコマンド(主にダニ関連)が動作しない」これは私が持っているコードですました(?あるいはハック)
from matplotlib.pyplot import *
from mpl_toolkits.axes_grid.axislines import Subplot
import matplotlib.lines as mpllines
import numpy as np
#set figure and axis
fig = figure(figsize=(6, 4))
#comment the next 2 lines to not hide top and right axis
ax = Subplot(fig, 111)
fig.add_subplot(ax)
#uncomment next 2 lines to deal with ticks
#ax = fig.add_subplot(111)
#calculate data
x = np.arange(0.8,2.501,0.001)
y = 4*((1/x)**12 - (1/x)**6)
#plot
ax.plot(x,y)
#do not display top and right axes
#comment to deal with ticks
ax.axis["right"].set_visible(False)
ax.axis["top"].set_visible(False)
#put ticks facing outwards
#does not work when Sublot is called!
for l in ax.get_xticklines():
l.set_marker(mpllines.TICKDOWN)
for l in ax.get_yticklines():
l.set_marker(mpllines.TICKLEFT)
#done
show()
のために、そのページの検索では、これは完璧に動作します。実際には、最後の 'for'ループは' ax.tick_params(axis = 'both'、direction = 'out') 'を使うことで回避できることを発見しました。これは同じくy軸の外側のティックを設定します時間。もう1つのことは、 'ax.get_xaxis()。tick_bottom()'と 'ax.get_yaxis()。tick_left()'をそれぞれ使って、上と下のティックを削除することです。そして 'rc'のチップのおかげで、それは役に立つでしょう! – englebip
@englebipああ、素晴らしい。これを答えに編集しました。 –