SORU
28 EKİM 2010, PERŞEMBE


Matplotlib arsa içinde sol ve sağ kenar boşluklarını azaltın

Matplotlib, arsa benim marjları ile başa çıkmak için mücadele ediyorum. Aşağıdaki kod benim grafik üretmek için kullandım:

plt.imshow(g)
c = plt.colorbar()
c.set_label("Number of Slabs")
plt.savefig("OutputToUse.png")

Bununla birlikte, bu plan her iki tarafında da boşluk dolu bir çıkış şekil alıyorum. Google Arama ve matplotlib belgeleri okudum, ama bu azaltmak için nasıl bulmak için görünmüyor olabilir.

CEVAP
28 EKİM 2010, PERŞEMBE


Otomatik olarak bunu yapmanın bir yolu plt.savefig bbox_inches='tight' kwarg.

E. g.

import matplotlib.pyplot as plt
import numpy as np
data = np.arange(3000).reshape((100,30))
plt.imshow(data)
plt.savefig('test.png', bbox_inches='tight')

Başka bir yolu fig.tight_layout() kullanmaktır

import matplotlib.pyplot as plt
import numpy as np

xs = np.linspace(0, 1, 20); ys = np.sin(xs)

fig = plt.figure()
axes = fig.add_subplot(1,1,1)
axes.plot(xs, ys)

# This should be called after all axes have been added
fig.tight_layout()
fig.savefig('test.png')

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • GoldgenieOfficial

    GoldgenieOff

    23 Temmuz 2009
  • Apple&Tech Reviews & Giveaways

    Apple&Tech R

    12 Temmuz 2008
  • JayzTwoCents

    JayzTwoCents

    26 AĞUSTOS 2012