Was ist das Problem? Die Beschriftung der oberen Grafik befindet sich unter der unteren Grafik ... Ich kann mir wirklich nicht vorstellen, wie ich das beheben kann. Ich dachte, es wird normal funktionieren.Unterer Graph überlappt das Etikett des oberen Graphen
Der folgende Code ist von der Website http://www.physics.nyu.edu/pine/pymanual/html/chap5/chap5_plot.html#basic-plotting.
Das Bild, wie das Diagramm sein muss, ist in der Verbindung http://www.physics.nyu.edu/pine/pymanual/html/_images/subplotDemo.png.
Das Bild meines Diagramms, das durch Kopieren des Codes von der obigen Website erhalten wurde, befindet sich im Link My overlapped graph.
import numpy as np
import matplotlib.pyplot as plt
theta = np.arange(0.01, 8., 0.04)
y = np.sqrt((8./theta)**2-1.)
ytan = np.tan(theta)
ytan = np.ma.masked_where(np.abs(ytan)>20., ytan)
ycot = 1./np.tan(theta)
ycot = np.ma.masked_where(np.abs(ycot)>20., ycot)
plt.figure(1)
plt.subplot(2, 1, 1)
plt.plot(theta, y)
plt.plot(theta, ytan)
plt.ylim(-8, 8)
plt.axhline(color="gray", zorder=-1)
plt.axvline(x=np.pi/2., color="gray", linestyle='--', zorder=-1)
plt.axvline(x=3.*np.pi/2., color="gray", linestyle='--', zorder=-1)
plt.axvline(x=5.*np.pi/2., color="gray", linestyle='--', zorder=-1)
plt.xlabel("theta")
plt.ylabel("tan(theta)")
plt.subplot(2, 1, 2)
plt.plot(theta, -y)
plt.plot(theta, ycot)
plt.ylim(-8, 8)
plt.axhline(color="gray", zorder=-1)
plt.axvline(x=np.pi, color="gray", linestyle='--', zorder=-1)
plt.axvline(x=2.*np.pi, color="gray", linestyle='--', zorder=-1)
plt.xlabel("theta")
plt.ylabel("cot(theta)")
plt.show()
Es funktioniert perfekt! Vielen Dank! –
Kennen Sie andere Lösungen? –
Ja, Sie könnten 'subplots_adjust' verwenden, um den Abstand genauer anzupassen. Hier finden Sie weitere Informationen: [sublots_adjust] (https://stackoverflow.com/a/6541454/7846567) – Max