Ich möchte eine Figur mit vier Unterplots erstellen. Jedes Diagramm in einer Reihe hat die gleiche y
Achse und die Diagramme in derselben Spalte teilen sich dieselbe x
Achse. Auf jeder Achse verwende ich die wissenschaftliche Notation. Während ich die Nummern der Ticks mit ticklabel_format
entfernen kann, entfernt das den Exponenten an der Achse nicht. Mit ax1.xaxis.set_visible(False)
wird die 1e5
an der x-axis
entfernt aber auch die Häkchen entfernt. Wie kann ich nur die 1eX
an den Unterplots entfernen, die die Achse mit einer anderen teilen, während die Teilstriche beibehalten werden? Zum Beispiel, wie werde ich die 1e5
und 1e2
in Teilplot 2 loswerden?Matplotlib: Entfernen Sie die wissenschaftliche Notation im Unterplot
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax3 = fig.add_subplot(223)
ax1 = fig.add_subplot(221, sharex = ax3)
ax4 = fig.add_subplot(224, sharey = ax3)
ax2 = fig.add_subplot(222, sharex = ax4, sharey = ax1)
#First plot
x = np.arange(0, 10**5, 100)
y = x
ax1.plot(x,y)
ax1.set_title('Subplot 1')
# Third plot
y = -x
ax3.plot(x,y)
ax3.set_title('Subplot 3')
#Second plot
x = np.arange(0, 100)
y = 10**3 * x + 100
ax2.plot(x,y)
ax2.set_title('Subplot 2')
#Fourth plot
y = -10**3 * x - 100
ax4.plot(x,y)
ax4.set_title('Subplot 4')
ax4.ticklabel_format(style = 'sci', axis='x', scilimits=(0,0))
ax3.ticklabel_format(style = 'sci', axis='x', scilimits=(0,0))
ax1.ticklabel_format(style = 'sci', axis='y', scilimits=(0,0))
ax3.ticklabel_format(style = 'sci', axis='y', scilimits=(0,0))
plt.setp(ax1.get_xticklabels(), visible=False)
plt.setp(ax2.get_xticklabels(), visible=False)
plt.setp(ax2.get_yticklabels(), visible=False)
plt.setp(ax4.get_yticklabels(), visible=False)
plt.show()
kehrt:
Die letzten beiden Zeilen scheinen redundant zu sein. Die x-Achse von Teilplot 1 hat immer noch den 1e5 und der Teilplot 4 fehlt die Ticklabels der x-Achse. – jan