在 matplotlib 中拆分图形的标题 [英] split title of a figure in matplotlib

查看:29
本文介绍了在 matplotlib 中拆分图形的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 matplotlib 创建一个包含 4 个子图的图形.

I use matplotlib to create a figure with 4 sub-plots in it.

我想分割一个子图的标题,这样每一行都会相对于子图居中.

I would like to split one of my title of a subplot, such that each line would be in the centered with respect to subplot.

我尝试了

import matplotlib.pylab as plt

fig = plt.figure(num=0,figsize=(8.27, 11.69), dpi=300)
ax  = fig.add_subplot(2, 2, 1)
ax.set_title(r'Normalized occupied \\ Neighbors')

我得到的是 Neighbors 缩进到左侧.

and what i get is that Neighbors is indent to left side.

我该如何纠正?

推荐答案

以这种方式格式化字符串时,我得到正确的对齐方式:

I get the correct alignment when I format the string this way:

import matplotlib.pylab as plt

fig = plt.figure()#num=0,figsize=(8.27, 11.69), dpi=300)
ax  = fig.add_subplot(2, 2, 1)
ax.set_title('Normalized occupied \n Neighbors')

plt.show()

这篇关于在 matplotlib 中拆分图形的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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