SORU
1 Kasım 2011, Salı


Nasıl matplotlib içinde en boy oranını ayarlayabilir miyim?

Yani 1:1, En-Boy oranı ama yapamam kare bir arsa (imshow kullanarak) yapmaya çalışıyorum. Bu iş hiçbiri:

import matplotlib.pyplot as plt

ax = fig.add_subplot(111,aspect='equal')
ax = fig.add_subplot(111,aspect=1.0)
ax.set_aspect('equal')
plt.axes().set_aspect('equal')

Herhangi bir fikir? Eğer diğer telefonları daha fazla bilgi örneğin bilgi ihtiyacınız varsa bana bildirin. Aramalar sadece (ben sık sık matplotlib ile ilgili bir sorun var gibi) gözardı ediliyor gibi görünüyor.

Teşekkürler!

CEVAP
1 Kasım 2011, Salı


Üçüncü kez cazibesi. Benim tahminim, bu bir hata olduğunu ve Zhenya's answer en son sürümü sabit olduğunu gösteriyor. Sürüm 0.99.1.1 var ve aşağıdaki çözüm yarattık:

import matplotlib.pyplot as plt
import numpy as np

def forceAspect(ax,aspect=1):
    im = ax.get_images()
    extent =  im[0].get_extent()
    ax.set_aspect(abs((extent[1]-extent[0])/(extent[3]-extent[2]))/aspect)

data = np.random.rand(10,20)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(data)
ax.set_xlabel('xlabel')
ax.set_aspect(2)
fig.savefig('equal.png')
ax.set_aspect('auto')
fig.savefig('auto.png')
forceAspect(ax,aspect=1)
fig.savefig('force.png')

Bu kuvvet.':png enter image description here

Aşağıda başarısız, henüz umarım bilgilendirici benim girişimleri.

İkinci Cevap:

Benim orijinal cevap bir şey axes.set_aspect() benzer gibi.' aşağıda overkill, axes.set_aspect('auto') kullanmak istediğiniz düşünüyorum. Bu durumda, ama benim için görüntü kare bir arsa üretir, neden, örneğin, bu komut anlamıyorum:

import matplotlib.pyplot as plt
import numpy as np

data = np.random.rand(10,20)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(data)
ax.set_aspect('equal')
fig.savefig('equal.png')
ax.set_aspect('auto')
fig.savefig('auto.png')

Resim ve komplo üreten 'eşit' En-Boy oranı: enter image description here ve 'otomatik' En-Boy oranı ile bir enter image description here

Kod aşağıda 'orijinal cevap' açıkça kontrol boy oranı için bir başlangıç noktası sağlar, ama bir imshow denir bir kez göz ardı gibi görünüyor.

Orijinal Cevabı:

Burada istenilen En Boy oranı almak için alt taslak parametrelerini ayarlamak olacak bir rutin bir örnek:

import matplotlib.pyplot as plt

def adjustFigAspect(fig,aspect=1):
    '''
    Adjust the subplot parameters so that the figure has the correct
    aspect ratio.
    '''
    xsize,ysize = fig.get_size_inches()
    minsize = min(xsize,ysize)
    xlim = .4*minsize/xsize
    ylim = .4*minsize/ysize
    if aspect < 1:
        xlim *= aspect
    else:
        ylim /= aspect
    fig.subplots_adjust(left=.5-xlim,
                        right=.5 xlim,
                        bottom=.5-ylim,
                        top=.5 ylim)

fig = plt.figure()
adjustFigAspect(fig,aspect=.5)
ax = fig.add_subplot(111)
ax.plot(range(10),range(10))

fig.savefig('axAspect.png')

Bu yüzden böyle bir rakam üretir: enter image description here

Eğer sahip birden fazla şekil içinde subplots eğer hayal edebiliyorum, y sayısı da dahil etmeniz gerekir ve x rutin için anahtar parametreleri (1) Her varsayarak) sunulan subplots. O zaman bu rakamları hspace wspace anahtar kelimeleri kullanarak, tüm subplots doğru Orana sahip olun.

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Ampisound

    Ampisound

    12 Kasım 2006
  • campos9896

    campos9896

    24 Mart 2012
  • Joe DiFeo

    Joe DiFeo

    7 AĞUSTOS 2012