简体   繁体   English

Matplotlib标记文本会根据字符数更改大小,我如何找出原因

[英]Matplotlib marker text changes size based on number of characters how can I figure out why

marker font seems to have a sizing algorithm dependent on length. 标记字体似乎具有取决于长度的大小调整算法。 I want to research this myself BUT don't know where to start? 我想自己研究一下,但不知道从哪里开始? The code line is below and I send about 12 symbols to it and the font size changes. 代码行在下面,我向它发送了大约12个符号,并且字体大小发生了变化。 How do I step through this problem and find the root cause for it please? 我该如何解决这个问题并找到根本原因?

plt.plot(x,y,lw=2.5,color='g',linestyle='solid',marker=r"$\mathsf{%s}$" % symbol, markersize=30,
     markeredgewidth=1, markeredgecolor='k' , markerfacecolor= 'None')

here is the output from sending 12 different symbols to it ie AAPL, AIG,C 这是向它发送12个不同符号的输出,即AAPL,AIG,C

在此处输入图片说明

If you vary markersize with the number of characters, the font is the same size: 如果您根据字符数改变markersize大小,则字体大小相同:

for t in (1,2,3):
    plt.plot([t*a for a in x], y, marker=r"$\mathsf{%s}$" % (t*'A'), markersize=10*t)

在此处输入图片说明

I guess the width is constant either if specified as a constant or if unspecified (must be a constant default) and the font size gets adjusted to fit. 我猜宽度是恒定的,无论是指定为常量还是未指定(默认为常量),并且字体大小都会调整为适合的大小。

Now, how to have figured that out... I kept throwing things out to make a minimal complete example, and just looked at what changed and thought about it. 现在,如何弄清楚这一点...我一直在扔东西,以使它成为一个最小的完整示例,而只是看一下发生了什么变化并进行思考。

so I FINALLY found a possible explanation to my problem by THINKING about what I was REALLY asking. 因此,通过思考我真正在问的问题,我终于找到了一个可能的解释我的问题的方法。 I found the answer 我找到了答案

"This can be a somewhat confusing way of defining the size but you are basically specifying the area of the marker. This means, to double the width (or height) of the marker you need to increase s by a factor of 4. [because A = WH => (2W)(2H)=4A] " “这种定义大小的方法可能有些混乱,但是您基本上是在指定标记的区域。这意味着,要使标记的宽度(或高度)加倍,您需要将s增加4倍。[因为A = WH =>(2W)(2H)= 4A]“

here. 这里。

enter link description here 在此处输入链接说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM