Python中直线(数字线)上的图形点
发布时间:2020-10-19 16:44:20 所属栏目:Python 来源:互联网
导读:试图弄清楚在 python中绘制数字线上点的最佳方法是什么.基本上尝试制作类似于下图的内容: 我一直在尝试使用Matplotlib来做到这一点,但似乎无法弄明白.有人知道我可以使用的包裹或任何东西吗? 我不知道具体的包装,但你可以使用 hlines, vlines和 plot在Matpl
|
试图弄清楚在 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() (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
