python注释换行,Python:Matplotlib注释换行符(带和不带胶乳)

I have a very basic question : how to do a line break with matplotlib in python with an "annotate" command. I tried "\" and "\n" but it does not work. And how to do this for a "Latex" annotation and for a normal text annotation ?

Thank you very much.

解决方案

What exactly did you try?

Were you, by chance, using a raw string (e.g. r"whatever")?

'\n' works perfectly, but if you're using a raw string to avoid latex sequences being interpreted as an escape, it will be interpreted by python as '\' and 'n' instead of a newline.

As an example:

import matplotlib.pyplot as plt

plt.annotate('Testing\nThis\nOut', xy=(0.5, 0.5))

plt.show()

6248ffe98df97f076319eb3676fad332.png

On the other hand, if we use a raw string:

import matplotlib.pyplot as plt

plt.annotate(r'Testing\nThis\nOut', xy=(0.5, 0.5))

plt.show()

1f62ef3e07fb02d4f91b7ec2e2c0025a.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值