I like to use a python script to generate a figure. That figure should have the script filename (with full path) as part of the title. For example:
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['text.usetex'] = True
x = np.linspace(0, 10, 10)
titleString = __file__.replace('_', '\_')
plt.plot(x, x)
plt.title(titleString)
plt.show()
The IPython console in Spyder shows the title correctly:
However, if I run the script (on Windows 7, using Anaconda with Jupyter Notebook 4.2.1 and Spyder 2.3.9) from within a Jupyter Notebook via
%matplotlib inline
%run 'H:/Python/Playground/a_test'
I get the following result:
Note that the scripts path and filename is not correct. Is there a way to fix this?