ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 20 Mar 2015 17:53:15 -0500How to fill rectangle around the text (or measure string)?http://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?EugeneFri, 20 Mar 2015 17:53:15 -0500http://ask.sagemath.org/question/26274/LaTeX in plot not showing Greek letterhttp://ask.sagemath.org/question/25209/latex-in-plot-not-showing-greek-letter/ Hello. I'm using the following code to generate an image of a triangle for a trigonometry quiz.
p = polygon2d([[0,0], [0,3], [4,0]], fill = False, axes = False)
p += text("$\theta$", (3, 0.2), fontsize = 22)
show(p)
The issue is that Sage doesn't seem to recognise $\theta$ as LaTeX, even though it's in dollar signs. In the corner of the triangle, it puts "heta". Why isn't this typesetting correctly? How can I fix it?
Thank you.mathochistWed, 10 Dec 2014 13:22:46 -0600http://ask.sagemath.org/question/25209/Save plot in SVG with plain text stringshttp://ask.sagemath.org/question/9261/save-plot-in-svg-with-plain-text-strings/Hi all,
as previously stated I am quite inexpert in using both SAGE and Python. I am trying to create figure for a LaTeX report. I am working on a machine on which I cannot use the package to integrate SAGE in LaTeX.
I am quite able to create plots and save them in SVG files. The real problem is that every caption or text in my plots appears as a embedded font or shape or whatever.
Here is an example:
TestPlot=plot(sin(x),(x,0,2*pi))+text("a stupid comment",(pi,2))
show(TestPlot)
TestPlot.save('TestPlot.svg')
This code generates the plot but when I start looking into the SVG file I can see that the caption "a stupid comment" was exported as:
<g id="text_13">
<!-- a stupid comment -->
<defs>
<path id="BitstreamVeraSans-Roman-20"/>
<path d="
M54.8906 33.0156
L54.8906 0
L45.9062 0
L45.9062 32.7188
Q45.9062 40.4844 42.875 44.3281
Q39.8438 48.1875 33.7969 48.1875
Q26.5156 48.1875 22.3125 43.5469
Q18.1094 38.9219 18.1094 30.9062
L18.1094 0
L9.07812 0
L9.07812 54.6875
L18.1094 54.6875
L18.1094 46.1875
Q21.3438 51.125 25.7031 53.5625
Q30.0781 56 35.7969 56
Q45.2188 56 50.0469 50.1719
Q54.8906 44.3438 54.8906 33.0156" id="BitstreamVeraSans-Roman-6e"/>
...
Q40.5312 48.4844 33.4062 48.4844
Q26.2656 48.4844 22.1875 42.8438
Q18.1094 37.2031 18.1094 27.2969
Q18.1094 17.3906 22.1875 11.75
Q26.2656 6.10938 33.4062 6.10938
Q40.5312 6.10938 44.6094 11.75
Q48.6875 17.3906 48.6875 27.2969" id="BitstreamVeraSans-Roman-70"/>
</defs>
<g style="fill:#0000ff;" transform="translate(241.978030233 60.4907451923)scale(0.1 -0.1)">
<use xlink:href="#BitstreamVeraSans-Roman-61"/>
<use x="61.279296875" xlink:href="#BitstreamVeraSans-Roman-20"/>
<use x="93.06640625" xlink:href="#BitstreamVeraSans-Roman-73"/>
<use x="145.166015625" xlink:href="#BitstreamVeraSans-Roman-74"/>
<use x="184.375" xlink:href="#BitstreamVeraSans-Roman-75"/>
<use x="247.75390625" xlink:href="#BitstreamVeraSans-Roman-70"/>
<use x="311.23046875" xlink:href="#BitstreamVeraSans-Roman-69"/>
<use x="339.013671875" xlink:href="#BitstreamVeraSans-Roman-64"/>
<use x="402.490234375" xlink:href="#BitstreamVeraSans-Roman-20"/>
<use x="434.27734375" xlink:href="#BitstreamVeraSans-Roman-63"/>
<use x="489.2578125" xlink:href="#BitstreamVeraSans-Roman-6f"/>
<use x="550.439453125" xlink:href="#BitstreamVeraSans-Roman-6d"/>
<use x="647.8515625" xlink:href="#BitstreamVeraSans-Roman-6d"/>
<use x="745.263671875" xlink:href="#BitstreamVeraSans-Roman-65"/>
<use x="806.787109375" xlink:href="#BitstreamVeraSans-Roman-6e"/>
<use x="870.166015625" xlink:href="#BitstreamVeraSans-Roman-74"/>
</g>
</g>
</g>
</g>
Here I have eliminated a lot of lines for sake of readability. This renders well in SVG viewers but as I convert it to pdf+LaTeX with inkscape the caption is not, of course, converted in LaTeX and thus the appearance of the report is not consistent. Is there a way to force the export to actually export a text object?
What I'd like to have is something like this:
<text
x="160.75159"
y="209.35091"
id="text2987"
xml:space="preserve"
style="font-size:10px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Lucida Sans;-inkscape-font-specification:Lucida Sans"><tspan
x="160.75159"
y="209.35091"
id="tspan2989">\emph{some stupid comment}</tspan></text>
where, as you can see I can also use some LaTeX syntax with no problem.
Best regards,
mcirri
mcirriTue, 21 Aug 2012 22:03:40 -0500http://ask.sagemath.org/question/9261/Plotting a latex matrix using text()http://ask.sagemath.org/question/9155/plotting-a-latex-matrix-using-text/I would like to plot a latex'd matrix at a location in a 2d plot. I tried this:
text('$\\left( \\begin{array}{ll} 2 & 3 \\\\ 4 & 5 \\end{array} \\right)$', (1,0) )
and various variations to do with the backslashes being escaped or not. But every time I get an error:
matplotlib.pyparsing.ParseFatalException: Expected end of math '$'
$\left( \begin{array}{ll} 2 & 3 \\ 4 & 5 \end{array} \right)$ (at char 0), (line:1, col:1)
It appears that matplotlib doesn't want to parse an array or a pmatrix etc. Is there a workaround?Kate StangeSat, 14 Jul 2012 02:04:17 -0500http://ask.sagemath.org/question/9155/Plot titleshttp://ask.sagemath.org/question/7808/plot-titles/I know about the text function, but this has to be inside the plot. How would one make titles for plots?
Thank you.Eviatar BachSat, 11 Dec 2010 18:22:02 -0600http://ask.sagemath.org/question/7808/