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

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

本文来自网络,不代表青岛站长网立场。转载请注明出处: https://www.0532zz.com/html/kaifa/python/20201019/11623.html
上一篇
下一篇

作者: dawei

【声明】:青岛站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

返回顶部