在 matplotlib 的子图中使用 pdf 图像

using a pdf image inside a subplot in matplotlib

我想要 matplotlib 子图中的 pdf(最好)图像,以显示周期不同阶段的图。我尝试使用 imshow 但无法将其放入子图中。有没有办法做到这一点?此刻,我不得不将子图的 pdf 导入 inkscape 并编辑矢量图形以添加这些曲线位置!并且很难创建正确的对齐方式!非常感谢任何建议。

ax2 = f.add_subplot(182, sharex=ax1)
ax2.plot(P1_05[:,1], P1_05[:,0], 'k-')
im = plt.imread('./1_cycle.png') #I want to add a pdf if possible!
implot = plt.imshow(im, extent=[0.01,0.8,1.2,2.0])
xlim(0,1.4)
ylim(0,2)

也许作为开始的想法:

x1=np.linspace(0,np.pi)
y1=np.sin(x1)

y2=np.sin(x1)

rect1=[0.1,0.1,0.8,0.8]
ax1=plt.axes(rect,frameon=True)
ax1.yaxis.tick_left()
plt.plot(x1,y1)
plt.ylabel('axis 1')
plt.xlabel('x')


rect2=[0.1,1,0.2,0.2]
ax2=plt.axes(rect2,frameon=False)
ax2.yaxis.tick_right()
ax2.plot(x1,y2)

percent = 0.2
xp = percent*np.pi
yp = np.sin(xp)
ax2.plot(xp,yp, marker='o')

ax2.yaxis.set_label_position('right')
ax2.axes.get_xaxis().set_visible(False)
ax2.axes.get_yaxis().set_visible(False)

ax2.annotate('%d Percent' %(percent*100), xy=(0.5, 0.))


rect3=[0.3,1,0.2,0.2]
ax3=plt.axes(rect3,frameon=False)
ax3.yaxis.tick_right()
ax3.plot(x1,y2)

percent = 0.4
xp = percent*np.pi
yp = np.sin(xp)
ax3.plot(xp,yp, marker='o')

ax3.yaxis.set_label_position('right')
ax3.axes.get_xaxis().set_visible(False)
ax3.axes.get_yaxis().set_visible(False)

ax3.annotate('%d Percent' %(percent*100), xy=(0.5, 0.))




plt.show()

这就是我调整 Moritz 代码的方式:

ax2 = f.add_subplot(182, sharex=ax1)
ax2.plot(P1_05[:,1], P1_05[:,0], 'k-')   
plt.tick_params(axis='both', which='major', labelsize=14)
xlim(0,1.4)
ylim(0,2)
#-------------------------nested plot for cycle position at the top-----------------
x1=np.linspace(0,2*np.pi) # length between 0 to 2pi
y1=np.sin(x1)
rect=[0.125,0.82,0.095,0.08] #x, y,width,height
plt.axes(rect)
plt.tick_params(bottom='off',labeltop='off',labelbottom='off', labelleft='off', left='off',top='off',right='off') #this turns off all the ticks for this plot
plot(x1,y1,'k-') # for the sine curve   
xlim(0,6.28) #limits for this plot(0,2pi)
ylim(-1.5,1.5) #limits are (-1,1) but .5 for space
percent = 0.2
xp = percent*np.pi
yp = np.sin(xp)
plot(xp,yp, marker='o') 
plt.annotate('%d \%%' %(percent*100), xy=(1.14, -1),fontsize=10)  #after much searching finally found this \%% for a percentage sign!
#-------------end of nested plot------------------