加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python中直线(数字线)上的图形点

发布时间:2020-12-16 23:34:49 所属栏目:Python 来源:网络整理
导读:试图弄清楚在 python中绘制数字线上点的最佳方法是什么.基本上尝试制作类似于下图的内容: 我一直在尝试使用Matplotlib来做到这一点,但似乎无法弄明白.有人知道我可以使用的包裹或任何东西吗? 解决方法 我不知道具体的包装,但你可以使用 hlines,vlines和 pl
试图弄清楚在 python中绘制数字线上点的最佳方法是什么.基本上尝试制作类似于下图的内容:

我一直在尝试使用Matplotlib来做到这一点,但似乎无法弄明白.有人知道我可以使用的包裹或任何东西吗?

解决方法

我不知道具体的包装,但你可以使用 hlines,vlines和 plot在Matplotlib中做这样的事情.
import matplotlib.pyplot as plt

# set up the figure
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim(0,10)
ax.set_ylim(0,10)

# draw lines
xmin = 1
xmax = 9
y = 5
height = 1

plt.hlines(y,xmin,xmax)
plt.vlines(xmin,y - height / 2.,y + height / 2.)
plt.vlines(xmax,y + height / 2.)

# draw a point on the line
px = 4
plt.plot(px,y,'ro',ms = 15,mfc = 'r')

# add an arrow
plt.annotate('Price five days ago',(px,y),xytext = (px - 1,y + 1),arrowprops=dict(facecolor='black',shrink=0.1),horizontalalignment='right')

# add numbers
plt.text(xmin - 0.1,'80',horizontalalignment='right')
plt.text(xmax + 0.1,'115',horizontalalignment='left')

plt.axis('off')
plt.show()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读