作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我想在我的一个情节中指出一个距离。我想到的是他们在技术图纸中的做法,显示一个双头箭头,旁边是距离作为文本。
示例:
from matplotlib.pyplot import *
hlines(7,0,2, linestyles='dashed')
hlines(11,0,2, linestyles='dashed')
hlines(10,0,2, linestyles='dashed')
hlines(8,0,2, linestyles='dashed')
plot((1,1),(8,10), 'k',) # arrow line
plot((1,1),(8,8), 'k', marker='v',) # lower arrowhead
plot((1,1),(10,10), 'k', marker='^',) # upper arrowhead
text(1.1,9,"D=1")
这会导致类似这样的结果(其中两条线并不是真正需要的,它们只是增加了绘图区域...):
有没有更快的方法来做到这一点,最好是使用在确切位置结束的箭头,而不是低于/高于它们应该在的位置?自动放置文本的加分项。
编辑:我一直在玩 annotate
但由于必须牺牲字符串,这个解决方案对我失去了一些吸引力。感谢您指出箭头样式,但当我尝试类似的东西时它不起作用。我想没有办法通过一个调用来编写一个小函数......
最佳答案
import matplotlib.pyplot as plt
plt.hlines(7, 0, 2, linestyles='dashed')
plt.hlines(11, 0, 2, linestyles='dashed')
plt.hlines(10, 0, 2, linestyles='dashed')
plt.hlines(8, 0, 2, linestyles='dashed')
plt.annotate(
'', xy=(1, 10), xycoords='data',
xytext=(1, 8), textcoords='data',
arrowprops={'arrowstyle': '<->'})
plt.annotate(
'D = 1', xy=(1, 9), xycoords='data',
xytext=(5, 0), textcoords='offset points')
# alternatively,
# plt.text(1.01, 9, 'D = 1')
plt.show()
产量
有关 plt.annotate
的许多可用选项的详细信息,请参阅 this page .
如上所示,文本可以使用 plt.annotate
或 plt.text
放置。使用 plt.annotate
您可以指定偏移量(例如 (5, 0)
),而使用 plt.text
您可以指定数据坐标中的文本位置(例如 (1.01, 9)
)。
关于python - 在技术图纸中绘制距离箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14612637/
如何在MKCircleview中绘制文字?我必须在 MKMapview 的覆盖层上打印文本。这可能吗? 最佳答案 在我的 MKOverlayView 的叠加 View 子类的这一部分中: - (voi
有没有人做过这样的事? 我需要导入在 AutoCAD 或 Solidworks 中完成的 3d 对象,并将它们绘制到 Windows 窗体中。我只需要以 3D 方式查看对象并四处移动 - 无需任何操作
我是一名优秀的程序员,十分优秀!