小编jke*_*s99的帖子

将 AstroPy 与 matplotlib 结合使用,由于使用了 plt.colorbar(),我收到一条警告,要求首先调用 grid(False)

尝试从 AstroPy:docs 运行此代码

    import matplotlib.pyplot as plt
    from astropy.visualization import astropy_mpl_style
    plt.style.use(astropy_mpl_style)
    
    from astropy.utils.data import get_pkg_data_filename
    from astropy.io import fits
    
    image_file = get_pkg_data_filename('tutorials/FITS-images/HorseHead.fits')
    fits.info(image_file)
    
    image_data = fits.getdata(image_file, ext=0)
    
    print(image_data.shape)
    
    plt.figure()
    plt.imshow(image_data, cmap='gray')
    
    plt.colorbar()
Run Code Online (Sandbox Code Playgroud)

我收到警告:

第 19 行 plt.colorbar() MatplotlibDeprecationWarning:自 3.5 起,pcolor() 和 pcolormesh() 自动删除网格已被弃用,并将在两个小版本后删除;请先调用 grid(False) 。

我尝试调用 plt.grid(False),但继续收到此警告/错误。有谁知道如何解决这个问题?

python matplotlib astropy

6
推荐指数
1
解决办法
3303
查看次数

标签 统计

astropy ×1

matplotlib ×1

python ×1