0

With the following boxplot:

import matplotlib.pyplot as plt

plt.text(0.7, 0.7, "test", size=50,
         ha="right", va="top",
         bbox=dict(boxstyle="square")
         )
plt.show()

fancytextbox_example]

How can you change the length of the box without changing the width?

EDIT:

What I want is:

plt.text(0.05, 0.7, "      test       ", size=50, va="top",
         bbox=dict(boxstyle="square"))

fancytextbox_example_2

But using spaces in the string seems like a pretty ugly solution. There's another way?

Lucas
  • 6,869
  • 5
  • 29
  • 44
  • Possible duplicate of [Matplotlib text dimensions](http://stackoverflow.com/questions/5320205/matplotlib-text-dimensions) – smoggers Jan 05 '17 at 12:10

1 Answers1

0

Solution: create FancyBboxPatch with matplotlib.patches from where you can change the length and width, then add the text.

import matplotlib.patches as mpatches
from matplotlib.collections import PatchCollection

fig, ax = plt.subplots()
patches = []
fancybox = mpatches.FancyBboxPatch([0, 0.45], 1, 0.3,
    boxstyle=mpatches.BoxStyle("square", pad=0))
patches.append(fancybox)
collection = PatchCollection(patches)
ax.add_collection(collection)
pth = plt.text(0.7, 0.7, "test", size=50,
         ha="right", va="top")
plt.show()

_solution

Lucas
  • 6,869
  • 5
  • 29
  • 44