栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

一个窗口中有多个图形

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

一个窗口中有多个图形

您可以基于的subplots命令(请注意末尾的
s ,与

subplot
urinieto指向的命令不同)来定义函数
matplotlib.pyplot

下面是基于您的函数的一个示例,允许在图中绘制多个轴。您可以在图形布局中定义所需的行数和列数。

def plot_figures(figures, nrows = 1, ncols=1):    """Plot a dictionary of figures.    Parameters    ----------    figures : <title, figure> dictionary    ncols : number of columns of subplots wanted in the display    nrows : number of rows of subplots wanted in the figure    """    fig, axeslist = plt.subplots(ncols=ncols, nrows=nrows)    for ind,title in enumerate(figures):        axeslist.ravel()[ind].imshow(figures[title], cmap=plt.gray())        axeslist.ravel()[ind].set_title(title)        axeslist.ravel()[ind].set_axis_off()    plt.tight_layout() # optional

基本上,该函数根据所需的行(

nrows
)和列(
ncols
)的数量在图中创建多个轴,然后在轴列表上进行迭代以绘制图像并为每个图像添加标题。

请注意,如果词典中只有一个图像,则以前的语法

plot_figures(figures)
从那时起将起作用,
nrows
并且默认
ncols
设置为
1

您可以获取的示例:

import matplotlib.pyplot as pltimport numpy as np# generation of a dictionary of (title, images)number_of_im = 6figures = {'im'+str(i): np.random.randn(100, 100) for i in range(number_of_im)}# plot of the images in a figure, with 2 rows and 3 columnsplot_figures(figures, 2, 3)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/648047.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号