Я создал следующую функцию, которая генерирует шаблон мозаики и per_subplot_kw:
Код: Выделить всё
def create_mosaic(num_rows):
def base_panel(idx):
return [f"rgb{idx}", f"hist{idx}", f"polar{idx}"]
mosaic = list()
per_subplot_kw = dict()
for i in range(num_rows):
mosaic.append(base_panel(i))
per_subplot_kw[f"polar{i}"] = dict(projection="polar")
return mosaic, per_subplot_kw
Код: Выделить всё
mosaic, kw = create_mosaic(3)
plt.subplot_mosaic(mosaic, per_subplot_kw=kw)
Код: Выделить всё
Diagnostics:
1. No overloads for "subplot_mosaic" match the provided arguments [reportCallIssue]
2. Argument of type "list[list[str]]" cannot be assigned to parameter "mosaic" of type "list[HashableList[Hashable]]" in function "subplot_mosaic"
"list[list[str]]" is not assignable to "list[HashableList[Hashable]]"
Type parameter "_T@list" is invariant, but "list[str]" is not the same as "HashableList[Hashable]"
Consider switching from "list" to "Sequence" which is covariant [reportArgumentType]
3. Argument of type "dict[str, dict[str, str]]" cannot be assigned to parameter "per_subplot_kw" of type "dict[Hashable | tuple[Hashable, ...], dict[str, Any]] | None" in function "subplot_mosaic"
Type "dict[str, dict[str, str]]" is not assignable to type "dict[Hashable | tuple[Hashable, ...], dict[str, Any]] | None"
"dict[str, dict[str, str]]" is not assignable to "dict[Hashable | tuple[Hashable, ...], dict[str, Any]]"
Type parameter "_KT@dict" is invariant, but "str" is not the same as "Hashable | tuple[Hashable, ...]"
"dict[str, dict[str, str]]" is not assignable to "None" [reportArgumentType]
Подробнее здесь: https://stackoverflow.com/questions/798 ... sthashable
Мобильная версия