Issue
I have some 2d data which I plot using this code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def f():
x=np.linspace(0,100,20000)
return x, np.sin(x)*np.exp(x)
#this is the plotting function
def symp(l,label,x_scale,y_scale):
linthresh=10e-32
for i in range(len(l)):
style=[':','dashed','dashdot','dotted']
dashes=[(5, 1),(3, 5),(3, 5, 1, 5), (1,1)]
col=['Red','Green','Orange','Blue']
csfont = {'fontname':'Leelawadee UI'}
line= plt.plot(l[i][0],l[i][1])
plt.xscale(x_scale)
plt.yscale(y_scale,linthreshy=linthresh)
plt.xticks(fontsize=10, fontweight='bold',**csfont)
plt.yticks(fontsize=10, fontweight='bold',**csfont)
plt.xlabel('x',fontsize=26, fontweight='bold',**csfont)
plt.ylabel(label,fontsize=26, fontweight='bold',**csfont)
plt.setp(line, linestyle=style[i],color=col[i],dashes=dashes[i])
plt.locator_params(axis='y')
plt.tight_layout()
# plt.savefig(str(label+'.eps'), format='eps')
plt.show()
symp([f()],r'${v}_{a}(x)$','log','symlog')
My goal is to plot only part of 1 array (for example f()[200:1000]) but linearly on the main plot. (In other words, I'm just zooming on my plot, I need it for my paper): How can I do this properly?
Solution
Inspired by How to add different graphs (as an inset) in another python graph ,
import numpy as np
import matplotlib.pyplot as plt
def zsymp(l,label,x_scale,y_scale):
linthresh=10e-32
zf=np.where(va[0][1] > 0, va[0][1], np.inf).argmin()
f=200
fig, ax1 = plt.subplots()
for i in range(len(l)):
style=[':','dashed','dashdot','dotted']
dashes=[(5, 1),(3, 5),(3, 5, 1, 5), (1,1)]
col=['Red','Green','Orange','Blue']
csfont = {'fontname':'Leelawadee UI'}
line= plt.plot(l[i][0],l[i][1])
plt.xscale(x_scale)
plt.yscale(y_scale,linthreshy=linthresh)
plt.xticks(fontsize=10, fontweight='bold',**csfont)
plt.yticks(fontsize=10, fontweight='bold',**csfont)
plt.xlabel('x',fontsize=26, fontweight='bold',**csfont)
plt.ylabel(label,fontsize=26, fontweight='bold',**csfont)
plt.setp(line, linestyle=style[i],color=col[i],dashes=dashes[i])
plt.locator_params(axis='y')
left, bottom, width, height = [0.2, 0.3, 0.28, 0.28]
ax2 = fig.add_axes([left, bottom, width, height])
line2=ax2.plot(l[0][0][zf-f:zf+f],l[0][1][zf-f:zf+f])
plt.setp(line2, linestyle=style[0],color=col[0],dashes=dashes[0])
# plt.tight_layout()
plt.show()
def f():
x=np.linspace(0,100,20000)
return x, np.sin(x)*np.exp(x)
zsymp([f()],r'${v}_{a}(x)$','log','symlog')
I achieved my desired result:
Answered By - Amirhossein Rezaei
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.