import os
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
os.chdir('/home/vg/Downloads/projects/ex12')
os.getcwd()
fig = plt.figure(figsize=(10,8))
def f(x):
return 1/(1+x**2) + 0.1/(1+((3-x)/0.1)**2)
def plot_and_format_axes(ax,x,f,fontsize):
ax.plot(x,f(x),linewidth=2)
ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(5))
ax.yaxis.set_major_locator(mpl.ticker.MaxNLocator(4))
ax.set_xlabel(r"$x$",fontsize=fontsize)
ax.set_ylabel(r"$f(x)$",fontsize=fontsize)
ax=fig.add_axes([0.1,0.15,0.8,0.8],facecolor="#f5f5f5")
x = np.linspace(-4,14,1000)
plot_and_format_axes(ax,x,f,18)
plt.title('Plot with inset')
x0,x1=2.5,3.5
ax.axvline(x0,ymax=0.3,color="grey",linestyle=":")
ax.axvline(x1,ymax=0.3,color="grey",linestyle=":")
ax_insert=fig.add_axes([0.5,0.5,0.38,0.42],facecolor='none')
x=np.linspace(x0,x1,1000)
plot_and_format_axes(ax_insert,x,f,14)
plt.savefig("example12.png", dpi=100)
plt.show()
plt.close()
Like this:
Like Loading...
Related
Recent Comments