我有以下代码:
def compare(f,a,b,c,d,n,points):
"""Plots 2 figures - one of the color map of f, and one of the color map of a rectangle [a,b] x [c,d], split
into n^2 subareas, using the list of points to estimate the color map"""
#fig, axes = plt.subplots(nrows=2, ncols=2)
q = plt.figure(1)
colorMapList(f,a,b,c,d,n,points)
#q.show()
p = plt.figure(2)
colorMap(f)
plt.show()
函数colorMapList
和colorMap
均返回ax.contourf(Y,X,z)
。
当我以自己的方式获得代码时,程序将输出两个图,一个在另一个图的下方。我怎样才能使图表水平并排显示? 谢谢!
答案 0 :(得分:1)
如果要将两个图形都放在一个图形上,则可以使用plt.subplot(121)
和plt.subplot(122)
。第一个索引是行数,第二个索引是cols数。第三个索引是图形布局的位置计数,因此,如果它是subplot(221),将是2x2的图形显示,而1则表示左上方的图形。然后,子图(222)将在右上方,子图(223)在左下,子图(224)在右下。这遵循每一行从左上到右的顺序。
但是,如果要并排绘制2个不同的图形,则可以查看this解决方案。