为什么我不能将标签放在一行内?

huangapple go评论61阅读模式
英文:

Why I can't put the lable in one line?

问题

我尝试绘制拟合线并添加标签:

```python
plt.plot(Tem, fitK[0] * Tem + fitK[1], label=('拟合动能 \n $E\_{k}^{拟合}=$ ' + fun1), color='red')

这是结果:

为什么我不能将标签放在一行内?

我可以让第二行和第三行出现在同一行吗?


<details>
<summary>英文:</summary>

I tried to plot the fitted line and add a label: 

```python
plt.plot(Tem, fitK[0] * Tem + fitK[1], label = (&#39;fitted kinetic energy \n $E\_{k}^{fitted}=$ &#39; + fun1), color = &#39;red&#39;)

Here is the result:

为什么我不能将标签放在一行内?

Can I make the second and third rows appear on the same line?

答案1

得分: 0

import numpy as np 
import matplotlib.pyplot as plt 
x = np.arange(1,11,1) 
y = np.arange(1,11,1) 
plt.plot(x, y, label='非常长的字符串在这里被截断\n而且没有其他地方有换行,即使有像 $E_{k}^{fitted}=$ 和其他字符串附加在它后面')
plt.legend() 
plt.show()
英文:
import numpy as np 
import matplotlib.pyplot as plt 
x = np.arange(1,11,1) 
y = np.arange(1,11,1) 
plt.plot(x,y, label=&#39;incredibly long string that is broken here \n and nowhere else at all even with terms like $E_{k}^{fitted}=$ &#39; + &#39;or even other strings attached to it&#39;) 
plt.legend() 
plt.show()

There is no second new line for me, no matter how long the string is. Does your fun1 contain a \n?

huangapple
  • 本文由 发表于 2023年4月19日 16:25:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76052273.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定