我想绘制一个常数场,但它不是很漂亮...... 它的值为零,我想要一个介于 -1 和 1 之间的颜色条! 我尝试这样做:
import numpy as np
import numpy.ma as ma
import matplotlib.pyplot as plt
from matplotlib import cm
plt.rcParams['text.usetex']=True
plt.rcParams['text.latex.unicode']=True
Lx=80.
Ly=120.
x0 = 30.
y0 = Ly/2.
YA, XA = np.mgrid[0:Ly, 0:Lx]
Order0 = 0*np.ones((YA.shape[0], YA.shape[1]))
plt.imshow(Order0,aspect='auto',cmap=plt.cm.hot,origin="lower")
plt.colorbar()
plt.show()
fig, ax = plt.subplots()
cax = ax.imshow(Order0, interpolation='nearest', cmap=cm.hot)
ax.set_title(r"\ test",fontsize=20)
plt.axis('off')
cbar = fig.colorbar(cax, ticks=[-1, -0.5, 0, 0.5, 1])
cbar.ax.set_yticklabels(['-1', '-0.5', '0','0.5' ' 1'])# vertically oriented colorbar
plt.show()
我想得到这样的图像以尊重其他结果:
最佳答案
我怀疑您想更改线路:
plt.imshow(Order0,aspect='auto',cmap=plt.cm.hot,origin="lower")
添加 vmin 和 vmax:
plt.imshow(Order0,aspect='auto',cmap=plt.cm.hot,origin="lower", vmin=-1, vmax=1)
给予:
关于Python - Matplotlib,绘制常量场,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26218794/