我目前正在尝试使用在函数中创建的传递轴对象,例如:
def drawfig_1():
import matplotlib.pyplot as plt
# Create a figure with one axis (ax1)
fig, ax1 = plt.subplots(figsize=(4,2))
# Plot some data
ax1.plot(range(10))
# Return axis object
return ax1
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何在另一个图中使用返回的轴对象 ax1?例如,我想以这种方式使用它:
# Setup plots for analysis
fig2 = plt.figure(figsize=(12, 8))
# Set up 2 axes, one for a pixel map, the other for an image
ax_map = plt.subplot2grid((3, 3), (0, 0), rowspan=3)
ax_image = plt.subplot2grid((3, 3), (0, 1), colspan=2, rowspan=3)
# Plot the image
ax_psf.imshow(image, vmin=0.00000001, vmax=0.000001, cmap=cm.gray)
# …Run Code Online (Sandbox Code Playgroud)