matplotlib子图的行标题 [英] Row titles for matplotlib subplot

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

问题描述

在matplotlib中,除了整个图的标题集和每个单独图的标题集之外,是否还可以为子图的每一行设置单独的标题?这将与下图中的橙色文本相对应.

In matplotlib, Is it possible to set a a separate title for each row of subplots in addition to the title set for the entire figure and the title set for each individual plot? This would correspond to the orange text in the figure below.

如果没有,您将如何解决此问题?在左侧创建一列空白子图,并用橙色文字填充它们?

If not, how would you get around this problem? Create a separate column of empty subplots to the left and fill them with the orange text?

我知道可以使用text()annotate()手动定位每个标题,但这通常需要进行大量调整,而且我有很多子图.有更流畅的解决方案吗?

I am aware that it is possible to manually position each single title using text() or annotate(), but that usually requires a lot of tweaking and I have many subplots. Is there a smoother solution?

推荐答案

一个想法是创建三个大子图",给每个子图一个标题,并使它们不可见.最重要的是,您可以创建较小的子图矩阵.

An idea is to create three "big subplots", to give each of them a title, and make them invisible. On the top of that you can create your matrix of smaller subplots.

此解决方案完全基于此帖子,除了已引起更多关注支付了实际删除背景子图的费用.

This solution is entirely based on this post, except that more attention has been paid to actually removing the background subplot.

import matplotlib.pyplot as plt

fig, big_axes = plt.subplots( figsize=(15.0, 15.0) , nrows=3, ncols=1, sharey=True) 

for row, big_ax in enumerate(big_axes, start=1):
    big_ax.set_title("Subplot row %s \n" % row, fontsize=16)

    # Turn off axis lines and ticks of the big subplot 
    # obs alpha is 0 in RGBA string!
    big_ax.tick_params(labelcolor=(1.,1.,1., 0.0), top='off', bottom='off', left='off', right='off')
    # removes the white frame
    big_ax._frameon = False


for i in range(1,10):
    ax = fig.add_subplot(3,3,i)
    ax.set_title('Plot title ' + str(i))

fig.set_facecolor('w')
plt.tight_layout()
plt.show()

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

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