小编Håk*_* T.的帖子

子图内的居中标题(matplotlib、pyplot)

我有一个大小相等的 3x2 网格。我使用命令

plt.suptitle("Awesome title")     # (1)
Run Code Online (Sandbox Code Playgroud)

在 6 个图上方有一个居中的标题。我使用命令

plt.title("Almost awesome title") # (2)
Run Code Online (Sandbox Code Playgroud)

对于每个子图上方的特定标题。现在是棘手的部分:我想要在子图的第一行和第二行之间有一个居中的标题。将 (2) 的位置参数操作为 (1.1 , 1.0) 之类的值后,我似乎无法获得格式正确/格式良好的图形。

TL; DR:我想要一个附加的plt.suptitle("Title"),如下图所示:(photoshopped)

任意图来说明子图中居中标题的点

matplotlib title python-2.7 subplot

5
推荐指数
1
解决办法
9136
查看次数

Using a pipe symbol in typing.Literal string

I have a function that accepts certain literals for a specific argument:

from typing import Literal

def fn(x: Literal["foo", "bar", "foo|bar"]) -> None:
    reveal_type(x)
Run Code Online (Sandbox Code Playgroud)

The third contains a pipe symbol (|), "foo|bar". This is interpreted by mypy as an error, as the name foo is not defined.

I guess this happens due to how forward references are evaluated? I use Python 3.8 with:

from __future__ import annotations
Run Code Online (Sandbox Code Playgroud)

Is there a way to make this work? I can …

python typechecking mypy python-typing

5
推荐指数
0
解决办法
192
查看次数