<i id='bRjmA'><tr id='bRjmA'><dt id='bRjmA'><q id='bRjmA'><span id='bRjmA'><b id='bRjmA'><form id='bRjmA'><ins id='bRjmA'></ins><ul id='bRjmA'></ul><sub id='bRjmA'></sub></form><legend id='bRjmA'></legend><bdo id='bRjmA'><pre id='bRjmA'><center id='bRjmA'></center></pre></bdo></b><th id='bRjmA'></th></span></q></dt></tr></i><div id='bRjmA'><tfoot id='bRjmA'></tfoot><dl id='bRjmA'><fieldset id='bRjmA'></fieldset></dl></div>

  1. <small id='bRjmA'></small><noframes id='bRjmA'>

    <tfoot id='bRjmA'></tfoot>

    <legend id='bRjmA'><style id='bRjmA'><dir id='bRjmA'><q id='bRjmA'></q></dir></style></legend>

        <bdo id='bRjmA'></bdo><ul id='bRjmA'></ul>

      在 Jupyter-Notebook 中使用循环的图像网格.如何?

      Grid of images using a loop in Jupyter-Notebook. How?(在 Jupyter-Notebook 中使用循环的图像网格.如何?)

      <small id='CyeNE'></small><noframes id='CyeNE'>

      <legend id='CyeNE'><style id='CyeNE'><dir id='CyeNE'><q id='CyeNE'></q></dir></style></legend>
        <i id='CyeNE'><tr id='CyeNE'><dt id='CyeNE'><q id='CyeNE'><span id='CyeNE'><b id='CyeNE'><form id='CyeNE'><ins id='CyeNE'></ins><ul id='CyeNE'></ul><sub id='CyeNE'></sub></form><legend id='CyeNE'></legend><bdo id='CyeNE'><pre id='CyeNE'><center id='CyeNE'></center></pre></bdo></b><th id='CyeNE'></th></span></q></dt></tr></i><div id='CyeNE'><tfoot id='CyeNE'></tfoot><dl id='CyeNE'><fieldset id='CyeNE'></fieldset></dl></div>
        <tfoot id='CyeNE'></tfoot>
          <bdo id='CyeNE'></bdo><ul id='CyeNE'></ul>
            <tbody id='CyeNE'></tbody>

                本文介绍了在 Jupyter-Notebook 中使用循环的图像网格.如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在 Jupyter Notebook 中以 2x3 矩阵格式显示图像 var_1.png,...,var_40.png.但是,我只能手动完成:

                I want to show images var_1.png,...,var_40.png in a 2x3 matrix format inside a Jupyter Notebook. However, I only manage to do it manually:

                import matplotlib.pyplot as plt
                import matplotlib.image as mpimg
                
                %matplotlib inline
                
                img1=mpimg.imread('Variable_8.png')
                img2=mpimg.imread('Variable_17.png')
                img3=mpimg.imread('Variable_18.png')
                          ...
                
                fig, ((ax1, ax2, ax3), (ax4,ax5,ax6)) = plt.subplots(2, 3, sharex=True, sharey=True) 
                
                ax1.imshow(img1)
                ax1.axis('off')
                ax2.imshow(img2)
                ax2.axis('off')
                   ....
                

                我想要更干净的东西.类似于指定

                I want something cleaner. Something like a list comprehension that specifies

                image=[img(i)=mpimg.imread('Variable_(i).png') for i in [8,17,28, ..]
                
                [ax[j].imshow(img(j)),ax[j].axis('off') for j in range(len(image))]
                

                一些帮助?

                推荐答案

                如果列表推导不止一件事,它们很快就会变得不可读.此外,如果列表的内容根本没有被实际使用,那么使用列表推导似乎被认为是不好的风格.

                List comprehensions quickly become unreadable if there is more than one thing they do. Also it appears it is considered bad style to use list comprehensions if the content of the list is not actually used at all.

                因此我会提出以下建议

                import matplotlib.pyplot as plt
                
                images = [plt.imread(f"Variable_{i}.png") for i in [8,17,28,29,31,35]]
                
                fig, axes = plt.subplots(2, 3, sharex=True, sharey=True) 
                
                for img, ax in zip(images, axes.flat):
                    ax.imshow(img)
                    ax.axis('off')
                

                这篇关于在 Jupyter-Notebook 中使用循环的图像网格.如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                      <tfoot id='w3pxX'></tfoot>

                    • <i id='w3pxX'><tr id='w3pxX'><dt id='w3pxX'><q id='w3pxX'><span id='w3pxX'><b id='w3pxX'><form id='w3pxX'><ins id='w3pxX'></ins><ul id='w3pxX'></ul><sub id='w3pxX'></sub></form><legend id='w3pxX'></legend><bdo id='w3pxX'><pre id='w3pxX'><center id='w3pxX'></center></pre></bdo></b><th id='w3pxX'></th></span></q></dt></tr></i><div id='w3pxX'><tfoot id='w3pxX'></tfoot><dl id='w3pxX'><fieldset id='w3pxX'></fieldset></dl></div>
                    • <legend id='w3pxX'><style id='w3pxX'><dir id='w3pxX'><q id='w3pxX'></q></dir></style></legend>
                        <tbody id='w3pxX'></tbody>
                        <bdo id='w3pxX'></bdo><ul id='w3pxX'></ul>

                          <small id='w3pxX'></small><noframes id='w3pxX'>