ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 21 Mar 2015 21:47:00 +0100How to fill rectangle around the text (or measure string)?https://ask.sagemath.org/question/26274/how-to-fill-rectangle-around-the-text-or-measure-string/ Hello!
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?Fri, 20 Mar 2015 23:53:15 +0100https://ask.sagemath.org/question/26274/how-to-fill-rectangle-around-the-text-or-measure-string/Answer by vdelecroix for <p>Hello!</p>
<p>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:</p>
<pre><code>text('Sage!', (0, 0), fill=True, fill_color='blue', edgecolor='black')
</code></pre>
<p>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.</p>
<p>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?</p>
https://ask.sagemath.org/question/26274/how-to-fill-rectangle-around-the-text-or-measure-string/?answer=26277#post-id-26277Hello,
It seems that we do not currently supports all options of [matplotlib](http://matplotlib.org/users/text_props.html). I opened the [trac ticket #18035](http://trac.sagemath.org/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](http://ask.sagemath.org/question/8273/combine-sage-plot-with-matplotlib/).
VincentSat, 21 Mar 2015 21:47:00 +0100https://ask.sagemath.org/question/26274/how-to-fill-rectangle-around-the-text-or-measure-string/?answer=26277#post-id-26277