![]() |
|||||||||||||
|
Font handlingI have spent a lot of time trying to make text in matplotlib look good. This has been a limitation of many pre-exisiting python graphing solutions, but with the rise of freetype and anti-aliased rendering for linux, it is now possible to have great looking fonts.Truetype fontsAll of the backends support Truetype fonts, which provide high quality, anti-aliased font rendering to PNG and JPEG output with or without X support. This is particularly useful for batch processing over terminal, or for web application servers.You need to have truetype '*.ttf' files on your system to use these fonts. The font finder does platform dependent searches to find them. In addition, matplotlib distributes the Vera fonts from Bitstream, the BaKoMa Computer Modern TeX fonts, and the STIX math fonts, all of which are available under different permissive licenses. If you want more, most of the time, matplotlib will pick up fonts installed in the standard place(s) on your operating system. Note that on Linux, you may need to run 'fc-cache' after installing new fonts. If you are aware of other freely distributable ttf fonts, please contact me. The font managerThanks to Paul Barrett, matplotlib now has a freestanding, cross platform font finder, resusing parts of ttfquery, which implements the W3C standard for describing fonts. Formerly, matplotlib required the external packages fonttools and ttfquery, but no longer does.As of matplotlib-0.91.0, fonts can also be specified using the fontconfig pattern syntax described here. A fontconfig pattern string may be used in place of a FontProperties class instance.
Font propertiesFonts are described by properties, and the font manager searches your system for the font that most closely matches the properties you choose. The 6 font properties used for font matching are given below with their default values. The FontProperties class is used to describe these properties.
font familyThe font.family property has five values: 'serif' (e.g. Times), 'sans-serif' (e.g. Helvetica), 'cursive' (e.g. Zapf-Chancery), 'fantasy' (e.g. Western), and 'monospace' (e.g. Courier). Each of these font families has a default list of font names in decreasing order of priority associated with them. You describe which family you want by choosing, eg, family='serif', and the font manager will search the font.serif list looking for one of the named fonts on your system. The lists are user configurable, and reside in your matplotlibrc file.This allows you to choose your family in your matplotlib script and the font manager will try and find the best font no matter which platform you run on. font styleThe font.style property has three values: normal (or roman), italic or oblique. The oblique style will be used for italic, if it is not present.font variantThe font.variant property has two values: normal or small-caps. For TrueType fonts, which are scalable fonts, small-caps is equivalent to using a font size of 'smaller', or about 83% of the current font size.font weightThe font.weight property has effectively 13 values: normal, bold, bolder, lighter, 100, 200, 300, ..., 900. Normal is the same as 400, and bold is 700. bolder and lighter are relative values with respect to the current weight.font stretchThe font.stretch property has 11 values: ultra-condensed, extra-condensed, condensed, semi-condensed, normal, semi-expanded, expanded, extra-expanded, ultra-expanded, wider, and narrower. This property is not currently implemented.font sizeThe font.size property has 11 values: xx-small, x-small, small, medium, large, x-large, xx-large, larger, smaller, length (such as 12pt), and percentage. larger and smaller are relative values. percentage is not yet implemented.PostscriptPostscript, despite its age, is still a great output format. Most publishers accept it, it scales to arbitrary resolutions, you can import it directly into LaTeX document, and send it directly to postscript printers.
The only requirement to generate postscript output is the numpy
module and some AFM fonts on your system. Even the latter is only a
quasi-requirement, because matplotlib ships with some of the most
popular font files. These are
|
||||||||||||
| Powered by |
|---|
| YAPTU! |