首页 > 解决方案 > matplotlib 在 Python 3.6.5 上不显示任何带有 xarray 的 plot() 的绘图窗口

问题描述

我试图在 Python 3.6.5 上使用 matplotlib 和 xarray 进行绘图。

我的代码实际上来自xarray 文档

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import xarray as xr

airtemps = xr.tutorial.open_dataset('air_temperature')
print(airtemps)

air = airtemps.air - 273.15
air.attrs = airtemps.air.attrs
air.attrs['units'] = 'deg C'
air1d = air.isel(lat=10, lon=10)
air1d.plot()      # using xarray.DataArray's plot()

当我运行代码(在 virturlenv 中)时,它没有显示任何绘图窗口,也没有引发错误。

标签: pythonmatplotlibpython-xarray

解决方案


我的错误我忘了在最后调用 plt.show() 。


推荐阅读