【问题标题】:Plotting series of images using matplot使用 matplotlib 绘制一系列图像
【发布时间】:2020-09-03 17:27:57
【问题描述】:

我正在尝试找到一种有效的方法来使用 matplotlib 在 Python 中的图形中绘制任意数量的图像。

这就是我想要实现的目标:

每张图片的宽度不同,但高度相同。当然,我们可以使用 subplot,但 subplot 图像的问题必须具有相同的宽度加上不同列之间的间距问题。

如果我需要使用另一个库/包来实现,那对我来说完全没问题。

注意事项:

  1. 每张图片的边框不应该存在,这只是为了说明。
  2. 我想将图形视为一个区域,我可以在其中在任何位置绘制图像并在特定位置添加文本。

【问题讨论】:

  • 您可以使用 gridspec 定义自定义网格
  • 您可以在需要 plt m*n 个图像的地方使用plt.subplots(m,n)

标签: python python-3.x matplotlib


【解决方案1】:

您可以使用gridspec 并指定leftrightbottomtopwidth_ratiosheight_ratios 以非常灵活的方式生成子图。详情请见doc

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
nrows=2
ncols=2

fig = plt.figure(figsize=(7.2, 7.2))

gs = fig.add_gridspec(nrows=nrows, ncols=ncols, left=0.1, right=0.6, bottom=0.55, top=0.95, width_ratios=[1, 2], height_ratios=[1, 1])

axes = [fig.add_subplot(gs[row, col]) for row in range(nrows) for col in range(ncols)]

【讨论】:

    猜你喜欢
    • 2012-04-10
    • 2021-01-31
    • 2019-04-13
    • 2017-06-07
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    • 2014-02-01
    • 1970-01-01
    相关资源
    最近更新 更多