Skip to content

MNT: Use __init__ parameters of font properties #28836

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
Sep 19, 2024
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
17 changes: 5 additions & 12 deletions galleries/examples/text_labels_and_annotations/fonts_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,36 @@
fig.text(0.1, 0.9, 'family', fontproperties=heading_font, **alignment)
families = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
for k, family in enumerate(families):
font = FontProperties()
font.set_family(family)
font = FontProperties(family=[family])
fig.text(0.1, yp[k], family, fontproperties=font, **alignment)

# Show style options
styles = ['normal', 'italic', 'oblique']
fig.text(0.3, 0.9, 'style', fontproperties=heading_font, **alignment)
for k, style in enumerate(styles):
font = FontProperties()
font.set_family('sans-serif')
font.set_style(style)
font = FontProperties(family='sans-serif', style=style)
fig.text(0.3, yp[k], style, fontproperties=font, **alignment)

# Show variant options
variants = ['normal', 'small-caps']
fig.text(0.5, 0.9, 'variant', fontproperties=heading_font, **alignment)
for k, variant in enumerate(variants):
font = FontProperties()
font.set_family('serif')
font.set_variant(variant)
font = FontProperties(family='serif', variant=variant)
fig.text(0.5, yp[k], variant, fontproperties=font, **alignment)

# Show weight options
weights = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
fig.text(0.7, 0.9, 'weight', fontproperties=heading_font, **alignment)
for k, weight in enumerate(weights):
font = FontProperties()
font.set_weight(weight)
font = FontProperties(weight=weight)
fig.text(0.7, yp[k], weight, fontproperties=font, **alignment)

# Show size options
sizes = [
'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large']
fig.text(0.9, 0.9, 'size', fontproperties=heading_font, **alignment)
for k, size in enumerate(sizes):
font = FontProperties()
font.set_size(size)
font = FontProperties(size=size)
fig.text(0.9, yp[k], size, fontproperties=font, **alignment)

# Show bold italic
Expand Down
5 changes: 1 addition & 4 deletions galleries/users_explain/text/text_intro.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@

from matplotlib.font_manager import FontProperties

font = FontProperties()
font.set_family('serif')
font.set_name('Times New Roman')
font.set_style('italic')
font = FontProperties(family='Times New Roman', style='italic')

fig, ax = plt.subplots(figsize=(5, 3))
fig.subplots_adjust(bottom=0.15, left=0.2)
Expand Down