我希望您能在IPython Notebook中使用Matplotlib创建一个图形,并从一个函数中返回多个子图:
import matplotlib.pyplot as plt
%matplotlib inline
def create_subplot(data):
more_data = do_something_on_data()
bp = plt.boxplot(more_data)
# return boxplot?
return bp
# make figure with subplots
f, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(10,5))
ax1 -> how can I get the plot from create_subplot() and put it on ax1?
ax1 -> how can I get the plot from create_subplot() and put it on ax2?
我知道可以直接将一个图形添加到坐标轴上:
ax1.boxplot(data)
但是我该如何从一个函数中返回一个图形并将其用作子图呢?