[英]Setting the x and y limits according to arrays using Matplotlib
I am plotting a density map according to arrays, x
, y
, and z
.我正在根据 arrays、 x
、 y
和z
绘制密度 map。 I want to have the x-
and y-
limits to be the same as the values in arrays x
and y
.我想让x-
和y-
限制与 arrays x
和y
中的值相同。 I present the current and expected outputs.我介绍了当前和预期的输出。
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
x=np.array([1., 3., 4., 5., 1., 3., 4., 5., 1., 3., 4., 5.])
y=np.array([0.1 , 0.1 , 0.1 , 0.1 , 0.01 , 0.01 , 0.01 , 0.01 , 0.001,
0.001, 0.001, 0.001])
z = np.array([[-1.18976, -0.95538, -1.1647 , -1.11199],
[-1.02719, -0.83643, -0.94146, -0.97814],
[-1.27374, -1.58571, -1.65026, -1.62557]])
plt.imshow(z,cmap=cm.hot,label="R0")
cbar=plt.colorbar()
plt.xlabel("var",size=20)
plt.ylabel("\u03B2",size=20)
plt.show()
The current output is当前output是
The expected output is预期的 output 是
Add the following code to the main script.将以下代码添加到主脚本中。
yticklabs = [0.1,0.01,0.001]
xticklabs = [1,3,4,5]
plt.xticks(range(4), xticklabs)
plt.yticks(range(3), yticklabs)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.