Ask Your Question

How to fill rectangle around the text (or measure string)?

asked 2015-03-20 23:53:15 +0100

Eugene gravatar image


I would like to fill a rectangle around the text on the plot, to make text more readable (same way it is done for the legend), the perfect way would be:

text('Sage!', (0, 0), fill=True, fill_color='blue', edgecolor='black')

But unfortunately there are no such options. I tried to write a custom function using text and polygon2d, but the problem appeared in calculating the size of the rectangle around the arbitrary text.

So, could anyone help me figure out how to calculate the size of the rectangle around the text (something like string measuring with consideration of font settings?), or may be suggest a better approach?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-03-21 21:47:00 +0100

vdelecroix gravatar image


It seems that we do not currently supports all options of matplotlib. I opened the trac ticket #18035 for that issue. Hopefully, if somebody does a review of the ticket these options will be available in a next release of Sage.

In the mean time you can use matplotlib directly or have a look at this related question.


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-03-20 23:53:15 +0100

Seen: 272 times

Last updated: Mar 21 '15