问题:matplotlib的轮廓期望输入2D数组的顺序是什么?matplotlib轮廓输入数组顺序
精心:Matplotlib轮廓文件说,日常通话
x_axis = np.linspace(10,100,n_x)
y_axis = np.linspace(10,100,n_y)
matplotlib.pyplot.contour(x_axis, y_axis, scalar_field)
凡scalar_field必须是一个二维数组。例如,可以通过
scalar_field = np.array([(x*y) for x in x_axis for y in y_axis])
scalar_field = scalar_field.reshape(n_x, n_y)
生成scalar_field如果scalar_field给予轮廓,
plt.contour(x_axis, y_axis,scalar_field) #incorrect
图的取向不正确(旋转)。要恢复正确的方向scalar_field必须调换:
plt.contour(x_axis, y_axis,scalar_field.transpose()) #correct
那么,什么是为了使轮廓预计scalar_field了?
请您详细说明索引部分和顺序吗? – Ivan
@Ivan当你使用''xy''索引时,你可以想象你从上面看矩阵,x坐标从左到右,而y坐标从底部到顶部。这不是你想要的,所以你可以选择'ij''索引,其中第一个索引可以看作是行,第二个索引可以看作是列... –