SORU
5 AĞUSTOS 2011, Cuma


pyplot eksenleri subplots için etiketler

Şu var:

import matplotlib.pyplot as plt

fig2 = plt.figure()
ax3 = fig2.add_subplot(2,1,1)
ax4 = fig2.add_subplot(2,1,2)
ax4.loglog(x1, y1)
ax3.loglog(x2, y2)
ax3.set_ylabel('hello')

Eksen etiketleri ve başlıkları sadece iki subplots, ama aynı zamanda her iki subplots yayılan ortak etiketlerin her biri için oluşturmak mümkün olmak istiyorum. Her iki arsa aynı eksen beri, örneğin, Sadece x bir set lazım ve y - eksen etiketleri. Her sahne için farklı başlıkları olsa da istiyorum.

Birkaç şey denedim ama hiçbiri işe yaramıştı

CEVAP
8 AĞUSTOS 2011, PAZARTESİ


İki subplots kapakları ve ortak markasını büyük bir sahne oluşturabilirsiniz.

import random
import matplotlib.pyplot as plt

x = range(1, 101)
y1 = [random.randint(1, 100) for _ in xrange(len(x))]
y2 = [random.randint(1, 100) for _ in xrange(len(x))]

fig = plt.figure()
ax = fig.add_subplot(111)    # The big subplot
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)

# Turn off axis lines and ticks of the big subplot
ax.spines['top'].set_color('none')
ax.spines['bottom'].set_color('none')
ax.spines['left'].set_color('none')
ax.spines['right'].set_color('none')
ax.tick_params(labelcolor='w', top='off', bottom='off', left='off', right='off')

ax1.loglog(x, y1)
ax2.loglog(x, y2)

# Set common labels
ax.set_xlabel('common xlabel')
ax.set_ylabel('common ylabel')

ax1.set_title('ax1 title')
ax2.set_title('ax2 title')

plt.savefig('common_labels.png', dpi=300)

common_labels.png

Başka bir şekilde incir kullanıyor.() metin ortak etiketlerin konumları doğrudan ayarlamak için.

import random
import matplotlib.pyplot as plt

x = range(1, 101)
y1 = [random.randint(1, 100) for _ in xrange(len(x))]
y2 = [random.randint(1, 100) for _ in xrange(len(x))]

fig = plt.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)

ax1.loglog(x, y1)
ax2.loglog(x, y2)

# Set common labels
fig.text(0.5, 0.04, 'common xlabel', ha='center', va='center')
fig.text(0.06, 0.5, 'common ylabel', ha='center', va='center', rotation='vertical')

ax1.set_title('ax1 title')
ax2.set_title('ax2 title')

plt.savefig('common_labels_text.png', dpi=300)

common_labels_text.png

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Jonah Penna

    Jonah Penna

    11 EYLÜL 2005
  • NYLON Video

    NYLON Video

    11 Aralık 2006
  • TastyTuts | Creative video tutorials by Gareth David

    TastyTuts |

    6 Temmuz 2011