Python:Matplotlib注释换行符(带和不带胶乳) [英] Python : Matplotlib annotate line break (with and without latex)

查看:528
本文介绍了Python:Matplotlib注释换行符(带和不带胶乳)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的问题:如何使用注释"命令在python中使用matplotlib进行换行.我尝试了"\"和"\ n",但是它不起作用.以及如何针对"Latex"注释和普通文本注释执行此操作?

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 ?

非常感谢您.

推荐答案

您到底尝试了什么?

您是不是偶然使用了原始字符串(例如r"whatever")?

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

'\n'可以完美地工作,但是如果您使用原始字符串来避免将乳胶序列解释为转义符,那么它将被python解释为'\''n'而不是换行符.

'\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.

例如:

import matplotlib.pyplot as plt

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

plt.show()

另一方面,如果我们使用原始字符串:

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()

这篇关于Python:Matplotlib注释换行符(带和不带胶乳)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆