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

  • BrandonHarrisWalker

    BrandonHarri

    27 Kasım 2006
  • edwin maldonado

    edwin maldon

    28 Mart 2009
  • TheMasterOfHell100

    TheMasterOfH

    13 AĞUSTOS 2011