English 中文(简体)
Matplotlib - Working With Text
  • 时间:2024-10-18

Matplotpb - Working With Text


Previous Page Next Page  

Matplotpb has extensive text support, including support for mathematical expressions, TrueType support for raster and vector outputs, newpne separated text with arbitrary rotations, and unicode support. Matplotpb includes its own matplotpb.font_manager which implements a cross platform, W3C comppant font finding algorithm.

The user has a great deal of control over text properties (font size, font weight, text location and color, etc.). Matplotpb implements a large number of TeX math symbols and commands.

The following pst of commands are used to create text in the Pyplot interface −

text Add text at an arbitrary location of the Axes.
annotate Add an annotation, with an optional arrow, at an arbitrary location of theAxes.
xlabel Add a label to the Axes’s x-axis.
ylabel Add a label to the Axes’s y-axis.
title Add a title to the Axes.
figtext Add text at an arbitrary location of the Figure.
suptitle Add a title to the Figure.

All of these functions create and return a matplotpb.text.Text() instance.

Following scripts demonstrate the use of some of the above functions −

import matplotpb.pyplot as plt
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.set_title( axes title )
ax.set_xlabel( xlabel )
ax.set_ylabel( ylabel )
ax.text(3, 8,  boxed itapcs text in data coords , style= itapc , 
bbox = { facecolor :  red })
ax.text(2, 6, r an equation: $E = mc^2$ , fontsize = 15)
ax.text(4, 0.05,  colored text in axes coords ,
verticalapgnment =  bottom , color =  green , fontsize = 15)
ax.plot([2], [1],  o )
ax.annotate( annotate , xy = (2, 1), xytext = (3, 4),
arrowprops = dict(facecolor =  black , shrink = 0.05))
ax.axis([0, 10, 0, 10])
plt.show()

The above pne of code will generate the following output −

Working With Text Advertisements