Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Updates to font-related examples. #9689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Updates to font-related examples.
Switch font_file example to use a shipped font, allowing to remove it
from the sgskip list.  Various fixes to other docs.
  • Loading branch information
anntzer committed Nov 4, 2017
commit 156841d1e1df22aacdef8933abe60a185e25700d
2 changes: 1 addition & 1 deletion examples/api/font_family_rc_sgskip.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
style (e.g., 'serif', 'sans-serif', or 'monospace').

In the example below, we only allow one font family (Tahoma) for the
san-serif font style. You the default family with the font.family rc
sans-serif font style. You the default family with the font.family rc
param, e.g.,::

rcParams['font.family'] = 'sans-serif'
Expand Down
28 changes: 28 additions & 0 deletions examples/api/font_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
===================================
Using a ttf font file in Matplotlib
===================================

Although it is usually not a good idea to explicitly point to a single ttf file
for a font instance, you can do so using the `font_manager.FontProperties`
*fname* argument.

Here, we use the Computer Modern roman font (``cmr10``) shipped with
Matplotlib.

For a more flexible solution, see :doc:`/gallery/api/font_family_rc_sgskip` and
:doc:`/gallery/text_labels_and_annotations/fonts_demo`.
"""

import os
from matplotlib import font_manager as fm, pyplot as plt, rcParams

fig, ax = plt.subplots()

fpath = os.path.join(rcParams["datapath"], "fonts/ttf/cmr10.ttf")
prop = fm.FontProperties(fname=fpath)
fname = os.path.split(fpath)[1]
ax.set_title('This is a special font: {}'.format(fname), fontproperties=prop)
ax.set_xlabel('This is the default font')

plt.show()
42 changes: 0 additions & 42 deletions examples/api/font_file_sgskip.py

This file was deleted.

12 changes: 6 additions & 6 deletions examples/text_labels_and_annotations/fonts_demo.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""
==========
Fonts Demo
==========
==================================
Fonts demo (object-oriented style)
==================================

Show how to set custom font properties.
Set font properties using setters.

For interactive users, you can also use kwargs to the text command,
which requires less typing. See examples/fonts_demo_kw.py
See :doc:`fonts_demo_kw` to achieve the same effect using kwargs.
"""

from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt

Expand Down
11 changes: 6 additions & 5 deletions examples/text_labels_and_annotations/fonts_demo_kw.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""
=============
Fonts Demo Kw
=============
===================
Fonts demo (kwargs)
===================

Same as fonts_demo using kwargs. If you prefer a more pythonic, OO
style of coding, see examples/fonts_demo.py.
Set font properties using kwargs.

See :doc:`fonts_demo` to achieve the same effect using setters.
"""

from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
import numpy as np
Expand Down