python - Matplotlib - 如何将数字彼此相邻放置?
问题描述
我有以下代码:
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)
。
当我按照我的方式编写代码时,程序会输出两个图表,一个在另一个之下。我怎样才能让图表彼此水平显示?谢谢!
解决方案
如果您希望两个图都在一个图形上,那么您可以使用plt.subplot(121)
和plt.subplot(122)
。第一个索引是行数,第二个索引是列数。第三个索引是图形布局的位置计数,因此如果它是 subplot(221) 将是 2x2 显示的图形,1 表示左上角的图形。然后,subplot(222) 将位于右上角,subplot(223) 位于左下角,subplot(224) 位于右下角。这遵循每行从左上到右的顺序。
但是,如果您想并排绘制 2 个不同的图形,则可以查看此解决方案。
推荐阅读
- c++ - VS2019内联函数的一些问题
- java - WebLogic 12c 中 WebAppModule 的 Weblogic 未解析的 Webapp 库引用
- php - 使用 Doctrine Query Language 应用多个条件
- json - 如何使用 Gson TypeAdapter 摆脱价值?
- webstorm - 如何通过 RubyMine 中的 Reformat Code 命令修复 ESLint 错误
- python-3.x - updating rows using python
- python - python pool不会按列表中的每个项目运行函数
- react-native - 键盘进入时Webview页面不滚动反应本机
- node.js - 自动完成 Nodejs 在 VScode 中不起作用
- mysql - 什么被视为临时表中的会话