Text in plots

class sage.plot.text.Text(string, point, options)

Base class for Text graphics primitive.

TESTS:

We test creating some text:

sage: text("I like Fibonacci",(3,5))
__init__(string, point, options)

Initializes base class Text.

EXAMPLES:

sage: T = text("I like Fibonacci", (3,5))
sage: t = T[0]
sage: t.string
'I like Fibonacci'
sage: t.x
3.0
sage: t.options()['fontsize']
10
_allowed_options()

Return the allowed options for the Text class.

EXAMPLES:

sage: T = text("ABC",(1,1),zorder=3)
sage: T[0]._allowed_options()['fontsize']
'How big the text is.'
sage: T[0]._allowed_options()['zorder']
'The layer level in which to draw'
_plot3d_options(options=None)

Translate 2D plot options into 3D plot options.

EXAMPLES:

sage: T = text("ABC",(1,1))
sage: t = T[0]
sage: t.options()['rgbcolor']
(0.0, 0.0, 1.0)
sage: s=t.plot3d()
sage: s.jmol_repr(s.testing_render_params())[0][1]
'color atom  [0,0,255]'
_render_on_subplot(subplot)

TESTS:

sage: t1 = text("Hello",(1,1), vertical_alignment="top", fontsize=30, rgbcolor='black')
sage: t2 = text("World", (1,1), horizontal_alignment="left",fontsize=20, zorder=-1)
sage: t1 + t2   # render the sum
_repr_()

String representation of Text primitive.

EXAMPLES:

sage: T = text("I like cool constants", (pi,e))
sage: t=T[0];t
Text 'I like cool constants' at the point (3.14159265359,2.71828182846)
get_minmax_data()

Returns a dictionary with the bounding box data. Notice that, for text, the box is just the location itself.

EXAMPLES:

sage: T = text("Where am I?",(1,1))
sage: t=T[0]
sage: t.get_minmax_data()['ymin']
1.0
sage: t.get_minmax_data()['ymax']
1.0
plot3d(**kwds)

Plots 2D text in 3D.

EXAMPLES:

sage: T = text("ABC",(1,1))
sage: t = T[0]
sage: s=t.plot3d()
sage: s.jmol_repr(s.testing_render_params())[0][2]
'label "ABC"'
sage: s._trans
(1.0, 1.0, 0)
sage.plot.text.text(*args, **kwds)

Returns a 2D text graphics object at the point (x,y).

Type text.options for a dictionary of options for 2D text.

2D OPTIONS:

  • fontsize - How big the text is
  • rgbcolor - The color as an RGB tuple
  • hue - The color given as a hue
  • vertical_alignment - How to align vertically: top, center, bottom
  • horizontal_alignment - How to align horizontally: left, center, right
  • axis_coords - (default: False) if True, use axis coordinates, so that (0,0) is the lower left and (1,1) upper right, regardless of the x and y range of plotted values.

EXAMPLES:

sage: text("Sage is really neat!!",(2,12))

The same text in larger font and colored red:

sage: text("Sage is really neat!!",(2,12),fontsize=20,rgbcolor=(1,0,0))

Same text but guaranteed to be in the lower left no matter what:

sage: text("Sage is really neat!!",(0,0), axis_coords=True, horizontal_alignment='left')

You can also align text differently:

sage: t1 = text("Hello",(1,1), vertical_alignment="top")
sage: t2 = text("World", (1,0.5), horizontal_alignment="left")
sage: t1 + t2   # render the sum

You can save text as part of PDF output:

sage: text("sage", (0,0), rgbcolor=(0,0,0)).save(SAGE_TMP + 'a.pdf')

Text must be 2D (use the text3d command for 3D text):

sage: t = text("hi",(1,2,3))
...
ValueError: use text3d instead for text in 3d
sage: t = text3d("hi",(1,2,3))

Extra options will get passed on to show(), as long as they are valid:

sage: text("MATH IS AWESOME", (0, 0), fontsize=40, axes=False)
sage: text("MATH IS AWESOME", (0, 0), fontsize=40).show(axes=False) # These are equivalent

Previous topic

Scatter Plots

Next topic

3D Graphics

This Page