Как я могу добавить левое и правое поля с помощью matplotlib? - PullRequest
0 голосов
/ 11 июля 2020

Здравствуйте, у меня есть этот код:

import matplotlib.pyplot as plt
from matplotlib import gridspec


Figure = plt.figure()
gs = gridspec.GridSpec(2, 3)
ax0 = Figure.add_subplot(gs[0, 0])
ax0.axis('off')
ax1 = Figure.add_subplot(gs[0, 1])
ax1.axis('off')
ax2 = Figure.add_subplot(gs[0, 2])
ax2.axis('off')
ax1.text(.5, .5, ('{}\n\n{}, {}').format("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
         "Hello", "2020-07-12"),
         color="white", style='oblique', ha='center', va='center', wrap=True,
         bbox={'facecolor': "#34C8EC", 'boxstyle': 'round,pad=1'})
Figure.canvas.draw_idle()
plt.show()

А проблема в следующем:

Мой сюжет

Но я хотел бы иметь поля справа и слева, то есть промежуток между синей рамкой и рамкой.

Как я могу это сделать?

Спасибо большое!

1 Ответ

1 голос
/ 11 июля 2020

Интересный вопрос. Я просмотрел исходный код модуля matplotlib.text и обнаружил функцию _get_wrap_line_width(), которая, кажется, отвечает за вычисление ширины поля. Но вы не можете передать ему никаких параметров, кроме положения текста и его ориентации. Без маржи. Я пришел к выводу, что то, что вы хотите сделать, невозможно.

Единственное обходное решение, которое я могу предложить, - это перенос текста вручную в исходный код, например:

ax1.text(.5, .5, ('{}\n\n{}, {}').format(
"""Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to make
a type specimen book. It has survived not only five centuries, but also the leap
into electronic typesetting, remaining essentially unchanged. It was popularised
in the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like Aldus
PageMaker including versions of Lorem Ipsum.""",
    "Hello", "2020-07-12"),
    color="white", style='oblique', ha='center', va='center', wrap=True,
    bbox={'facecolor': "#34C8EC", 'boxstyle': 'round,pad=1'})

Чтобы знать, куда обратиться вставьте разрывы, я счел полезным временно сдвинуть поле влево, например ax1.text(.4, .5, ....

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...