环绕情节标题

发布于 2025-01-10 03:05:32 字数 653 浏览 4 评论 0原文

我正在尝试为我的(非常简单的)情节添加标题。这是到目前为止我的标题代码:

t = "Figure 1: This caption is too long to be displayed over one line, in fact it will have to be spread over multiple lines. The whole plot is described in this caption so it goes on and on forever."

plt.figtext(0.1, -0.3, t, wrap = True, horizontalalignment = 'left', fontsize = 12, style = 'italic')

这些是我导入的库:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

我认为 plt.figtext 中的 wrap = True 会整理换行,但事实并非如此。相反,我的标题会在一行上继续,并且不会换行。我正在使用 Jupyter 笔记本。

我确信有一个简单的方法可以解决这个问题,但我只是无法弄清楚。

感谢您的帮助!

I'm trying to wrap the caption for my (very simple) plot. This is my code for the caption so far:

t = "Figure 1: This caption is too long to be displayed over one line, in fact it will have to be spread over multiple lines. The whole plot is described in this caption so it goes on and on forever."

plt.figtext(0.1, -0.3, t, wrap = True, horizontalalignment = 'left', fontsize = 12, style = 'italic')

And these are the libraries I have imported:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

I thought the wrap = True in plt.figtext would sort out the line wrapping, but it doesn't. Instead, my caption goes continues on one line and doesn't wrap. I'm using a Jupyter notebook.

I'm sure there is a simple way to fix this, I have just not been able to figure it out.

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小傻瓜 2025-01-17 03:05:32

Wrap 在 Jupyter Notebook 中不起作用:

换行不能与 savefig(..., bbox_inches='tight') 一起使用(它也由 IPython/Jupyter 中的 %matplotlib inline 内部使用)。 “紧密”设置会重新缩放画布以容纳所有内容,并在换行之前发生。

查看包装文档

Wrap does not work in Jupyter notebook:

Wrapping does not work together with savefig(..., bbox_inches='tight') (which is also used internally by %matplotlib inline in IPython/Jupyter). The 'tight' setting rescales the canvas to accommodate all content and happens before wrapping.

Checkout wrap documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文