gpt4 book ai didi

python - 在 matplotlib 的子图中使用 pdf 图像

转载 作者:行者123 更新时间:2023-11-28 17:36:08 24 4
gpt4 key购买 nike

我想要 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)

I want a pdf(preferably) image inside a subplot in matplotlib to show the plots at different stages of the cycle. I tried with <code>imshow</code> 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.

最佳答案

也许作为一个开始的想法:

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

enter image description here

关于python - 在 matplotlib 的子图中使用 pdf 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30437381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com