Проблемы со Spy, Imshow и Matshow от Matplotlib - PullRequest
0 голосов
/ 04 мая 2019

У меня есть следующий простой код, использующий Python (я использую Python 3) matplotlib.pyplot spy, imshow и matshow.

from scipy import rand, floor
import matplotlib.pyplot as plt

Lx=30; Ly=20
p=0.4

r=rand(Lx,Ly) # Generates random numbers across the 2D lattice of size Lx*Ly
A = floor(r+p)

# Using spy 
plt.xlabel('$L_x$'); plt.ylabel('$L_y$')
plt.spy(A, origin='lower')
plt.title("Figure 1")
plt.savefig('fig1.png')

# Using imshow
plt.xlabel('$L_x$'); plt.ylabel('$L_y$')
plt.imshow(r,  cmap='rainbow', origin='lower', extent=[0,Lx,0,Ly])
plt.title("Figure 2")
plt.colorbar(orientation='horizontal')
plt.savefig('fig2.png')

# Using matshow
plt.xlabel('$L_x$'); plt.ylabel('$L_y$')
plt.matshow(r,  cmap='rainbow', origin='lower', extent=[0,Lx,0,Ly]) 
plt.colorbar(orientation='horizontal')
plt.title("Figure 3")
plt.savefig('fig3.png')


plt.show()

#Issues

# 1) plt.show() doesn't show spy-plot (Figure 1). 
# 2) Axes labels don't pass to matshow-plot (Figure 3).
# 3) spy-plot shows wrong-label ($L_x$ and $L_y$ are interchanged in Figure 2).
# 4) None of the plots set origin at 'lower', i.e. at the bottom-left position.

4 проблемыупоминается в конце комментариев кода.Основным из них является установка источника в крайнем нижнем левом углу и размещение подписей внизу.

Можно ли их разрешить или объяснить ограничения?

Выходные изображения прилагаются ниже.

enter image description here enter image description here enter image description here

...