複数の機能を持つ1つのdfから1つの図を作成したいとします。私は機能を別々に構築することができますが、それらを組み合わせるには問題があります。主な理由は、私がsubplots()とadd_subplot()を使用していて、それらを組み合わせる方法がわからないことだと思います。 これらの機能は次のとおりです。ヒストグラムとpandas:add_subplotとsubplots()を使用してマルチプロットグラフでx軸が破損する
- 4つのグラフが
- すべてのグラフ
でブレークをx軸、この関数はhere
import numpy as np
import matplotlib.pyplot as plt
def breakX(ax1,ax2):
ax=ax1
ax2=ax2
ax.set_ylim(.78, 1.)
ax2.set_ylim(0, .22)
ax.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax.xaxis.tick_top()
ax.tick_params(labeltop='off')
ax2.xaxis.tick_bottom()
d = .015
kwargs = dict(transform=ax.transAxes, color='black', clip_on=False)
ax.plot((-d, +d), (-d, +d), **kwargs)
ax.plot((1 - d, 1 + d), (-d, +d), **kwargs)
kwargs.update(transform=ax2.transAxes)
ax2.plot((-d, +d), (1 - d, 1 + d), **kwargs)
ax2.plot((1 - d, 1 + d), (1 - d, 1 + d), **kwargs)
# breakX is used in this function to create a figure with three histograms:
def figure2():
fig=plt.figure()
pts = np.array([0.015, 0.166, 0.133, 0.159, 0.041, 0.024, 0.195, 0.039, 0.161, 0.018, 0.143, 0.056, 0.125, 0.096, 0.094, 0.051, 0.043, 0.021, 0.138, 0.075, 0.109, 0.195, 0.050, 0.074, 0.079, 0.155, 0.020, 0.010, 0.061, 0.008])
pts[[3, 14]] += .8
ax=fig.add_subplot(221)
ax2=fig.add_subplot(221)
f, (ax, ax2) = plt.subplots(2, 1, sharex=True)
ax.plot(pts)
ax2.plot(pts)
breakX(ax,ax2)
ax3=fig.add_subplot(222)
ax4=fig.add_subplot(222)
f, (ax3, ax4) = plt.subplots(2, 1, sharex=True)
ax3.plot(pts)
ax4.plot(pts)
breakX(ax3,ax4)
ax5=fig.add_subplot(223)
ax6=fig.add_subplot(223)
f, (ax5, ax6) = plt.subplots(2, 1, sharex=True)
ax5.plot(pts)
ax6.plot(pts)
breakX(ax5,ax6)
plt.show()
から構成されている私の問題は、私ですadd_subplot()とsubplots()が一緒に動作していないことを示す、1つではなく4つの数字を取得します。何がしたいことは4回2つのプロットとサブプロットのグリッドで、原理的には
問題の[mcve]を入力して、問題が2つの方法を組み合わせている場所を正確に説明してください。 – ImportanceOfBeingErnest
今は良いですか? – SGeuer
[mcve]は、コードをコピーして実行し、問題のある動作を観察できることを意味します。なぜツイン軸が必要ですか?ヒストグラムが同じ場合は、それらを同じ軸にプロットしてみませんか?全体として、結果のプロットがどれだけ望ましくないかは実際にはわかりません。 – ImportanceOfBeingErnest