Birçok alt olay örgüsü içeren bir figürüm var.
fig = plt.figure(num=None, figsize=(26, 12), dpi=80, facecolor='w', edgecolor='k')
fig.canvas.set_window_title('Window Title')
# Returns the Axes instance
ax = fig.add_subplot(311)
ax2 = fig.add_subplot(312)
ax3 = fig.add_subplot(313)
Alt olay örgülerine nasıl başlık ekleyebilirim?
fig.suptitletüm grafiklere bir başlık ekler ve
ax.set_title()` mevcut olmasına rağmen, ikincisi alt grafiklerime herhangi bir başlık eklemez.
Yardımlarınız için teşekkür ederim.
Düzenle: set_title()` ile ilgili yazım hatası düzeltildi. Teşekkürler Rutger Kassies
ax.set_title()` ayrı alt grafikler için başlıkları ayarlamalıdır:
import matplotlib.pyplot as plt
if __name__ == "__main__":
data = [1, 2, 3, 4, 5]
fig = plt.figure()
fig.suptitle("Title for whole figure", fontsize=16)
ax = plt.subplot("211")
ax.set_title("Title for first plot")
ax.plot(data)
ax = plt.subplot("212")
ax.set_title("Title for second plot")
ax.plot(data)
plt.show()
Bu kodun sizin için çalışıp çalışmadığını kontrol edebilir misiniz? Belki bir şey daha sonra onların üzerine yazıyordur?
ax.title.set_text('Arsa Başlığım')` da işe yarıyor gibi görünüyor.
fig = plt.figure()
ax1 = fig.add_subplot(221)
ax2 = fig.add_subplot(222)
ax3 = fig.add_subplot(223)
ax4 = fig.add_subplot(224)
ax1.title.set_text('First Plot')
ax2.title.set_text('Second Plot')
ax3.title.set_text('Third Plot')
ax4.title.set_text('Fourth Plot')
plt.show()
Kısaltılmış bir cevap varsayarak
import matplotlib.pyplot as plt
:
plt.gca().set_title('title')
olduğu gibi:
plt.subplot(221)
plt.gca().set_title('title')
plt.subplot(222)
etc...
O halde gereksiz değişkenlere gerek yoktur.