如何在Python中使用matplotlib使x轴穿过(0,0)?

编程入门 行业动态 更新时间:2024-10-25 06:33:13
本文介绍了如何在Python中使用matplotlib使x轴穿过(0,0)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何让横轴通过原点?

import numpy as np import matplotlib.pyplot as plt rateList=[0,0.08,.1,.12,.15,.175,.225,.25,.275,.3,.325,.35] list1=[-316.8,-424,-2.8,622,658,400,83,16.8,0] NPV_Profile1=[np.npv(x,list1) for x in rateList] list2=[-496,-760,84,1050.4,658,400,83,16.8,0] NPV_Profile2=[np.npv(x,list2) for x in rateList] plt.plot(rateList,NPV_Profile1,rateList,NPV_Profile2) plt.show()

推荐答案

尝试:

import numpy as np import matplotlib.pyplot as plt rateList=[0,0.08,.1,.12,.15,.175,.225,.25,.275,.3,.325,.35] list1=[-316.8,-424,-2.8,622,658,400,83,16.8,0] NPV_Profile1=[np.npv(x,list1) for x in rateList] list2=[-496,-760,84,1050.4,658,400,83,16.8,0] NPV_Profile2=[np.npv(x,list2) for x in rateList] fig, ax = plt.subplots() ax.plot(rateList,NPV_Profile1,rateList,NPV_Profile2) # set the x-spine ax.spines['left'].set_position('zero') # turn off the right spine/ticks ax.spines['right'].set_color('none') ax.yaxis.tick_left() # set the y-spine ax.spines['bottom'].set_position('zero') # turn off the top spine/ticks ax.spines['top'].set_color('none') ax.xaxis.tick_bottom() plt.show()

输出:

更多推荐

如何在Python中使用matplotlib使x轴穿过(0,0)?

本文发布于:2023-10-08 02:50:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471293.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Python   matplotlib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!