python绘图内容怎么保存,使用保存到文件时,Python绘图元素无法正确呈现

我使用matplotlib获得了以下Python图:

697f287ae9e163d68cb556f81ca78565.png

但我需要将其保存为pdf。当我这样做时,它不能正确渲染,许多元素都在错误的位置,有些甚至不会出现。我搜索了但没有找到如何解决这个在我的情况:

ff38080d768c89654db671cc7c7e00da.png

这是我的剧情代码:

plt.plot(0, 0)

plt.tick_params(

axis='both',

which='both',

bottom='off',

top='off',

left='off',

right='off',

labelleft='off',

labelbottom='off',

labelsize=8)

a = plt.axes([.36, .2, .6, .6])

plt.tick_params(

axis='both',

which='both',

labelsize=8)

a.spines['left'].set_position('center')

a.spines['bottom'].set_position('center')

a.spines['right'].set_color('none')

a.spines['top'].set_color('none')

a.xaxis.set_ticks_position('bottom')

a.yaxis.set_ticks_position('left')

plt.plot(x,y1, 'g--',label='m$_{1}$=' +str(mass1)+'M$_{\odot}$')

plt.plot(x,y2, 'b--',label='m$_{2}$=' +str(mass2)+'M$_{\odot}$')

plt.plot(x,y1n, 'g--')

plt.plot(x,y2n, 'b--')

plt.plot(start1[0],start1[1], 'xr',label='Position at \ntime t=0')

plt.plot(start2[0],start2[1], 'xr')

plt.plot(stop1[0],stop1[1], 'og', label='Position at \ntime t=' + str(t) + ' yr')

plt.plot(stop2[0],stop2[1], 'og')

plt.text(-75,-10, r'Binary period ' + str(period(m1+m2,a1+a2)) + 'yr',fontsize=8)

plt.text(-75,-15, r'm$_{1}$ period ' + str(period(m1,a1)) + ' yr',fontsize=8)

plt.text(-75,-20, r'm$_{2}$ period ' + str(period(m2,a2)) + ' yr',fontsize=8)

plt.text(-75,-25, r'a$_{1}$ = ' + str(a1) + ' AU', fontsize=8)

plt.text(-75,-30, r'b$_{1}$ = ' + str(sigfigs(LOSorbit(0,a1))) + ' AU',fontsize=8)

plt.text(-75,45, 'Apparent Orbits of Circular Binary System', fontsize=8, fontweight='bold')

plt.text(-75,-35, r'a$_{2}$ = ' + str(a2) + ' AU', fontsize=8)

plt.text(-75,-40, r'b$_{2}$ = ' + str(sigfigs(LOSorbit(0,a2))) + ' AU',fontsize=8)

plt.xlabel('x /AU', fontsize=8)

h = plt.ylabel('y /AU', fontsize=8)

h.set_rotation(0)

a.xaxis.set_label_coords(1.06, 0.54)

a.yaxis.set_label_coords(0.55, 1.01)

plt.savefig('binary_sys.pdf', bbox_inches='tight')

plt.grid()

box = a.get_position()

a.set_position([box.x0, box.y0, box.width * 0.8, box.height])

a.legend(numpoints=1,loc='center left',bbox_to_anchor=(-0.46, 0.75),prop={'size':8})

plt.show()如何正确保存文件?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值