python 点_在Python中的直线(数字线)上绘制点

1586010002-jmsa.png

Trying to figure out what's the best way to graph a point on a number line in python. Essentially trying to make something similar to the image below:

7G4tc.gif

I've been trying to use Matplotlib to do this but can't seem to figure it out. Anyone know of a package or anything out there I can use?

解决方案

I don't know of a specific package for this but you could do something like this in Matplotlib using hlines, vlines and plot.

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., 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, y, '80', horizontalalignment='right')

plt.text(xmax + 0.1, y, '115', horizontalalignment='left')

plt.axis('off')

plt.show()

mbX11.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值