如何在Python中显示AxesSubplot?

use*_*587 20 python matplotlib

我有一个对象fig2,它是一个类mathplotlib.axes.axessubplot,但是当我尝试执行fig2.show()时,python说axessubplot对象没有属性显示.如何显示AxesSubplot?

hel*_*ker 39

你应该调用matplotlib.pyplot.show(),这是一个显示所有数字的方法.

如果您已导入为plt,则:

import matplotlib.pyplot as plt

# create fig1 (of type plt.figure)
# create fig2

plt.show()  # will display fig1 and fig2 in different windows
Run Code Online (Sandbox Code Playgroud)


Byt*_*hon 13

或者,您可以调用fig2的figure属性:

fig2.figure 
Run Code Online (Sandbox Code Playgroud)

  • 对于 Seaborn 线图当前返回的对象非常有用。您可以在另一个 Jupyter 单元中再次显示绘图,而无需再次运行所有代码。 (2认同)