Matplotlib
Matplotlibで再利用可能なaxessubplotオブジェクトを作成すると、axessubplotオブジェクトを追加するための標準的なアプローチとして図を提供します。これは効果的ですが、図とは独立してaxessubplotオブジェクトを作成することが望ましいシナリオがある場合があります。たとえば、
def plot(x、y、ax = none): axがなしである場合: ax = plt.gca()#現在のaxesインスタンスを取得(デフォルト) ax.plot(x、y、 'go') ax.set_ylabel( 'yabba dabba do!')
def plot(x, y, ax=None): if ax is None: ax = plt.gca() # Get the current axes instance (default) ax.plot(x, y, 'go') ax.set_ylabel('Yabba dabba do!')
さらに、axesインスタンスは既存の図に追加でき、再利用を可能にします:
# Create a figure with two subplots fig1, (ax1, ax2) = plt.subplots(nrows=2) plot(x, np.sin(x), ax1) # Use the first axes instance plot(x, np.random.random(100), ax2) # Use the second axes instance # Create a new figure fig2 = plt.figure() plot(x, np.cos(x)) # Use the new figure's axes instance plt.show()
特定の「形状」に適合するように軸インスタンスをさらにカスタマイズすることは可能かもしれませんが、インスタンスのインスタンスや軸のリストを容易にすることは、一般的に複雑なシナリオに対してより実用的で効率的です。
免責事項: 提供されるすべてのリソースの一部はインターネットからのものです。お客様の著作権またはその他の権利および利益の侵害がある場合は、詳細な理由を説明し、著作権または権利および利益の証拠を提出して、電子メール [email protected] に送信してください。 できるだけ早く対応させていただきます。
Copyright© 2022 湘ICP备2022001581号-3