Python中jpg图像的显示网格

2024-05-27 11:17:10 发布

您现在位置:Python中文网/ 问答频道 /正文

让下面的笑话熊猫.DataFrame公司名称:

import pandas as pd

Cat=pd.DataFrame(({'RA' :[230.82102945, 173.65985309999999, 173.66313018, 
                          173.84698746999999, 189.96874310999999, 
                          170.20006370999999, 170.20416528000001,
                          170.16438034000001, 170.24896294000001, 
                          189.84348857000001, 212.74040604000001, 
                          212.68784378000001, 154.36278941, 
                          154.40930130000001, 154.41919107000001],
                    'Dec': [-1.0481932199999999, 0.18865839000000001, 0.1247615, 
                            0.090550759999999994, 0.12548559000000001, 
                            0.46857110000000002, 0.45924195000000001, 
                            0.45747362000000003, 0.53422636000000001, 0.46023247, 
                            1.03574006, 1.04634373, -0.49560479000000002,
                            -0.45308465999999997, -0.48165697000000002],
                  'Morph':['Ei', 'Er', 'Sc', 'Er', 'Sb', 'Ser', 'Er', 'Ser', 
                        'Sc', 'Ec', 'Sb', 'Sb', 'Ser', 'Ei(o)', 'Ei(o)']}))

我想在一个Jupyter笔记本上显示一个网络图像网格。这些图像是来自SDSS的星系,在我的数据帧中,它们的坐标在度上。他们是jpg。我不需要把它们存储在磁盘上,但这是我找到的唯一方法。我只能在列中显示它们,并且我使用打印作为标题,方法是:

^{pr2}$

这将产生以下输出:

enter image description here

enter image description here

我想在4x4网格上显示这个(带标签)。我试图在显示之前插入类似plt.subplot(441+i)的内容,但它不起作用。此外,如果有可能不把图像存储在磁盘上,那就太完美了。在

谢谢。在


Tags: 方法图像import名称网格dataframe公司磁盘
1条回答
网友
1楼 · 发布于 2024-05-27 11:17:10

所以我终于解决了。我回来发布我的代码。在

import matplotlib as plt

def getgal(x,i):
    query_string = urllib.urlencode(dict(ra=x['RA'],
                                         dec=x['Dec'],
                                         width=impix, height=impix,
                                         scale=imsize.to(u.arcsec).value/impix))
    return cutoutbaseurl + '?' + query_string

def url_to_image(url):
    resp = urllib.urlopen(url)
    image = np.asarray(bytearray(resp.read()), dtype="uint8")
    image = cv2.imdecode(image, cv2.IMREAD_COLOR)
    return image

def galshow(size,width,height,start):
    fig = plt.figure(figsize=(size,size))
    for i in range(0,width*height):
        j = i+start
        url = getgal(Yang.iloc[j],j)
        img = url_to_image(url)
        plt.subplot(height,width,i+1)
        SpecObjID, RA, Dec = Yang.iloc[j]['SpecObjID'],Yang.iloc[j]['RA'],Yang.iloc[j]['Dec']
        label = "%i\nRA %f, Dec %f\n%s"%(SpecObjID, RA, Dec,Yang.iloc[j]['Morph'])
        plt.title(label)    
        plt.xticks([]), plt.yticks([])
        plt.tight_layout()
        plt.imshow(img)
    plt.show()

相关问题 更多 >

    热门问题