我想在matplotlib绘图中的一些文本周围添加一个边框,我可以使用patheffects.withStroke
。但是,对于某些字母和数字,符号右上角有一个小间隙。你知道吗
有没有办法避免这种差距?你知道吗
最小工作示例:
import matplotlib.pyplot as plt
import matplotlib.patheffects as patheffects
fig, ax = plt.subplots()
ax.text(
0.1, 0.5, "test: S6",
color='white',
fontsize=90,
path_effects=[patheffects.withStroke(linewidth=13, foreground='black')])
fig.savefig("text_stroke.png")
我正在使用matplotlib 1.5.1。你知道吗
文档没有提到它(或者我没有找到它),但是在代码中搜索时,我们可以看到
patheffects.withStroke
方法接受许多关键字参数。你知道吗通过在交互式会话中执行以下命令,可以获得这些关键字参数的列表:
您要查找的参数是
capstyle
,它接受3个可能的值:在您的例子中,“round”值似乎解决了问题。 考虑下面的代码。。。你知道吗
。。。它产生了:
接受的关键字参数实际上是GraphicsContextBase类的所有
set_*
(减去“set”前缀)方法。您可以在类文档中找到接受值的详细信息。你知道吗相关问题 更多 >
编程相关推荐