python - Matplotlib 的 Spy、Imshow 和 Matshow 的问题
问题描述
我有以下使用 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 个问题。一个主要的是将原点设置在最左下角,并将标题放在底部。
可以解决这些问题或解释限制吗?
输出图像附在下面。
解决方案
推荐阅读
- c - 我正在尝试使用 COM Moniker 抑制 UAC 提示
- python - SymPy 用符号代替向量
- laravel - 有没有办法在没有数据的情况下返回 0 几个月?
- mongodb - Mongo Spring JPA 在 findAll() 调用中给出 IndexOutOfBoundsException
- python - Python 库安装但无法导入
- javascript - 鼠标悬停时如何获取DOM列表?
- php - 在 Powershell 中运行 PHP 脚本会一直打开 NotePad++ 而不是执行 PHP 脚本
- python - NameError:未定义名称“驱动程序”
- docker - Docker - 数据库容器的最佳实践?
- postgresql - Hibernate:如何自动生成 36 个基本字符串的 id