def test_xaxes_pos_ValueError(pos): fig.clear() ax1 = fig.add_subplot(111) ax2 = ax1.twiny() org1 = 0.0 org2 = 0.0 with pytest.raises(ValueError): align.xaxes(ax1, org1, ax2, org2, pos)
def test_xaxes_outrange_ValueError(): fig.clear() ax1 = fig.add_subplot(111) ax2 = ax1.twiny() ax1.set_xlim(-1.0, 0.0) ax2.set_xlim(0.0, 1.0) org1 = 0.5 org2 = 1.1 with pytest.raises(ValueError): align.xaxes(ax1, org1, ax2, org2)
def test_xaxes_simple2(): fig.clear() ax1 = fig.add_subplot(111) ax2 = ax1.twiny() ax1.set_xlim(-1.0, 0.0) ax2.set_xlim(0.0, 1.0) org1 = 0.0 org2 = 0.0 align.xaxes(ax1, org1, ax2, org2) assert ax1.get_xlim() == (-1.0, 1.0) assert ax2.get_xlim() == (-1.0, 1.0)
def test_xaxes_axes_TypeError(): fig.clear() ax1 = fig.add_subplot(111) ax2 = ax1.twiny() ax3 = ax1.get_xaxis() org1 = 0.0 org2 = 0.0 pos = 0.5 with pytest.raises(TypeError): align.xaxes(ax3, org1, ax2, org2, pos) with pytest.raises(TypeError): align.xaxes(ax1, org1, ax3, org2, pos)
def test_xaxes_inverted(): fig.clear() ax1 = fig.add_subplot(111) ax2 = ax1.twiny() ax1.set_xlim(1.0, -1.0) ax2.set_xlim(1.5, 0.0) org1 = 0.0 org2 = 0.0 pos = 0.5 align.xaxes(ax1, org1, ax2, org2, pos) lim1 = list(ax1.get_xlim()) lim2 = list(ax2.get_xlim()) assert lim1[0] > lim1[1] assert lim2[0] > lim2[1]
# instantiate a second axes that shares the same x-axis #------------------------------------------------------ Axe2 = Axe1.twiny() Axe2.set_xticks(Xaxe2) Axe2.set_xlabel('Frequence (en HZ) ') # naming the y axis Axis1 = 'y - DSP (Densité Spectrale de Puissance ' Axe1.set_ylabel(Axis1) #plt.ylabel('y - DSP (Densité Spectrale de Puissance ') # giving a title to my graph red_patch = mpatches.Patch(color='blue', label='|X(f)|*|X(f)|/N') plt.legend(handles=[red_patch]) #Ajustement et alignement des deux axes x ---- on affiche 10 points #------------------------------------------------------------------ Axe1.set_xticks(np.linspace(0, Xaxe1[Len - 1], 10)) Axe2.set_xticks(np.linspace(0, Xaxe2[Len - 1], 10)) # Adjust the plotting range of two X axes org1 = 0 # Origin of first axis org2 = 0 # Origin of second axis pos = 0.1 # Position the two origins are aligned align.xaxes(Axe1, org1, Axe2, org2, pos) #plt.tight_layout() # function to show the plot plt.show()