我尝试了下面的代码,但没有成功...它说“提高AttributeError('未知属性%s'%k)AttributeError:未知属性头宽” ...
xyfrom=[10,620]
xyto=[130,620]
ax.annotate("",xyfrom,xyto,arrowprops=dict(arrowstyle='<->',linewidth = 2, headwidth=10,color = 'k'
))
ax.text((xyto[0]+xyfrom[0])/2-15,(xyto[1]+xyfrom[1])/2+10,"headwidth is too small",fontsize=24)
Run Code Online (Sandbox Code Playgroud)
我相信这是因为您需要在字符串中提供arrowstyle参数。尝试这个:
arrowprops=dict(arrowstyle='<->, head_width=10', facecolor='k')
Run Code Online (Sandbox Code Playgroud)
,请注意这是一个完整的字符串:
'<->, head_width=10'
Run Code Online (Sandbox Code Playgroud)
在matplotlib中,这是一个非常奇怪的选择,我真的不明白为什么要这样。无论如何,看看是否能解决您的问题。
...由于上述答案都不适合我...这是我的解决方案:
使用“mutation_scale”参数!(参见FancyArrowPatch的文档)
import matplotlib.pyplot as plt
f, ax = plt.subplots()
ax.scatter([1,2,3,4,5],[1,2,3,4,5])
ann = ax.annotate(rf'small head annotation',
xy=(2,2), xycoords='data',
xytext=(.28, .5), textcoords='figure fraction',
size=10, va="center", ha="center",
bbox=dict(boxstyle="round4", fc="w"),
arrowprops=dict(arrowstyle="-|>",mutation_scale=25,
connectionstyle="arc3,rad=-0.2", fc="w"))
ann2 = ax.annotate(rf'BIG head annotation',
xy=(2,2), xycoords='data',
xytext=(.75, .15), textcoords='figure fraction',
size=10, va="center", ha="center",
bbox=dict(boxstyle="round4", fc="w"),
arrowprops=dict(arrowstyle="-|>",mutation_scale=50,
connectionstyle="arc3,rad=-0.2", fc="w"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1977 次 |
| 最近记录: |