在matplotlib的子图中使用pdf图像 [英] using a pdf image inside a subplot in matplotlib

查看:100
本文介绍了在matplotlib的子图中使用pdf图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在matplotlib的子图中包含pdf(最好是)图像,以显示周期不同阶段的图.我尝试使用imshow,但无法在子图中获取它.有没有办法做到这一点?此刻,我必须导入子图的pdf进行墨迹绘制,并编辑矢量图形以添加这些曲线位置!!而且很难建立正确的对齐方式!!不胜感激任何建议.

I want a pdf(preferably) image inside a subplot in matplotlib to show the plots at different stages of the cycle. I tried with imshow but could not get it inside the subplot. Is there a method to do this? At the moment, I had to import the pdf of subplots to inkscape and edit the vector graphics to add these curve positions!! and its difficult to create the right alignment!! Would appreciate any suggestions.

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)

推荐答案

也许是从以下几点开始的想法:

Maybe as an idea to start with:

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()

这篇关于在matplotlib的子图中使用pdf图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆