Skip to main content
 首页 » 编程设计

python之pcolormesh 与坐标的奇怪行为

2024年10月17日7mq0036

我想使用 matplotlib 的 pcolormesh 函数绘制颜色网格。但是,它会根据我是否指定坐标给出不同的结果。

import numpy as np 
from matplotlib import pyplot as plt 
 
np.random.seed(9) 
x = np.arange(10) 
z = np.random.normal(0, 1, (10, 10)) 
 
plt.subplot(121) 
plt.pcolormesh(x, x, z) 
 
plt.subplot(122) 
plt.pcolormesh(z) 

我希望这两个调用产生相同的图像,但最终会出现以下情节。例如,绘图的右上角不同。

请您参考如下方法:

来自帮助(pcolor)

... 
Ideally the dimensions of X and Y should be one greater than those of C; 
if the dimensions are the same, then the last row and column of C will be ignored. ... 

您得到的左侧图是右侧图的放大图,其中删除了顶行和最右侧的列。