param = {'a': 10, 'b': 20}
s = [r"$%s = %f$" % (k, v) for k, v in param.items()]
label = s[0]
for _s in s[1:]:
label += r", " + _s
print label
$a = 10.000000$, $b = 20.000000$
%matplotlib inline
import numpy as np
def myplot1(x, y, xfit=np.array([]), yfit=np.array([]), param=None):
"""
x: {"label_x", xdata}
y: {"label_y", ydata}
"""
if param:
s = [r'$%s = %f$' % (k, v) for k, v in param.items()]
label = s[0]
for _s in s[1:]:
label += ", " + _s
label_x, xdata = x.items()[0]
label_y, ydata = y.items()[0]
fig = plt.figure(figsize=(8, 12))
ax1 = fig.add_subplot(211)
ax1.plot(xdata, ydata)
if len(xfit):
ax1.plot(xfit, yfit, label=label)
ax1.legend(loc='best')
ax1.set_xlabel(label_x)
ax1.set_ylabel(label_y)
ax1.set_xscale('linear')
ax1.set_yscale('linear')
ax2 = fig.add_subplot(212)
ax2.plot(xdata, ydata)
if len(xfit):
ax2.plot(xfit, yfit, label=label)
ax2.legend(loc='best')
ax2.set_xlabel(label_x)
ax2.set_ylabel(label_y)
ax2.set_xscale('log')
ax2.set_yscale('log')
plt.show()
d = {r'$x$': x}
c,e=d.items()[0]
c
'$x$'
x = np.arange(100)
y = param['a']*x + param['b']
import matplotlib.pyplot as plt
myplot1(x={r'$x$': x}, y={r'$y$': y}, xfit=x, yfit=y, param=param)