s = '''def my_plot_func():
from matplotlib import pyplot as plt
plt.plot([1, 2, 3])
plt.savefig('my_plot_via_func.png')'''
%store s >plot_func.py
Writing 's' (str) to file 'plot_func.py'.
cat plot_func.py
def my_plot_func(): from matplotlib import pyplot as plt plt.plot([1, 2, 3]) plt.savefig('my_plot_via_func.png')
from plot_func import my_plot_func
my_plot_func();
from IPython.display import Image
Image("my_plot_via_func.png")