2016-08-17 20 views
2

twinx()を使用して同じアスペクト比の軸にセカンダリ軸を作成しようとしていますが、次の例に示すように、セカンダリ軸はオリジナル。同じアスペクト比のMatplotlibセカンダリ軸

何か追加する必要がありますか、これはmatplotlibのバグですか?


コード:

from matplotlib import pyplot as plt 

fig = plt.figure() 
ax1 = fig.add_subplot(111, adjustable='box-forced', aspect='equal') 
ax2 = ax1.twinx() 
plt.show() 

出力図は:

matplotlib output

+0

でホスト軸を作成することによって、私の実際のプログラムで使用されるオブジェクト指向のAPIを使用して上記と同じことを達成することができました - 強制? – tacaswell

+0

'box-forced'を使わないとプロット領域が同じサイズに見えますが、2番目の軸にプロットしてウィンドウのサイズを変更すると、アスペクト比が変化しています – user3419537

+0

興味深いことに、上記のコードサンプルは' ax1 '' fig.add_subplot'の代わりに 'mpl_toolkits.axes_grid1'からインポートした' host_subplot'を使用しています。しかし、実際のコードではオブジェクト指向のAPIを使用しているので、 'host_subplot'を使うことはできません。 – user3419537

答えて

0

が寄生軸の代わりに、fig.add_subplotmatplotlib exampleに似host_subplotを持つホストの軸を作成するに表示されますr問題を解決してください。プロットは同じ空間を占有し、同じアスペクト比を持つようになりました。

from matplotlib import pyplot as plt 
from mpl_toolkits.axes_grid1 import host_subplot 

fig = plt.figure() 
ax1 = host_subplot(111, adjustable='box-forced', aspect='equal') 
ax2 = ax1.twinx() 
plt.show() 

私はそれが出て `ボックスで作業していSubplotHost

from PyQt5 import QtWidgets 
from matplotlib.figure import Figure 
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 
from mpl_toolkits.axes_grid1.parasite_axes import SubplotHost 

app = QtWidgets.QApplication([]) 

fig = Figure() 
ax1 = SubplotHost(fig, 111, adjustable='box-forced', aspect='equal') 
ax2 = ax1.twinx() 
fig.add_subplot(ax1) 
canvas = FigureCanvas(fig) 
canvas.show() 

app.exec_() 
関連する問題