8000 Convert mathtext examples to OO API. · sauerburger/matplotlib@f68fedf · GitHub
[go: up one dir, main page]

Skip to content

Commit f68fedf

Browse files
committed
Convert mathtext examples to OO API.
1 parent f8f6939 commit f68fedf

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

examples/text_labels_and_annotations/mathtext_examples.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,40 +62,41 @@ def doall():
6262
mpl_grey_rvb = (51. / 255., 51. / 255., 51. / 255.)
6363

6464
# Creating figure and axis.
65-
plt.figure(figsize=(6, 7))
66-
plt.axes([0.01, 0.01, 0.98, 0.90], facecolor="white", frameon=True)
67-
plt.gca().set_xlim(0., 1.)
68-
plt.gca().set_ylim(0., 1.)
69-
plt.gca().set_title("Matplotlib's math rendering engine",
70-
color=mpl_grey_rvb, fontsize=14, weight='bold')
71-
plt.gca().set_xticklabels([])
72-
plt.gca().set_yticklabels([])
65+
fig = plt.figure(figsize=(6, 7))
66+
ax = fig.add_axes([0.01, 0.01, 0.98, 0.90],
67+
facecolor="white", frameon=True)
68+
ax.set_xlim(0, 1)
69+
ax.set_ylim(0, 1)
70+
ax.set_title("Matplotlib's math rendering engine",
71+
color=mpl_grey_rvb, fontsize=14, weight='bold')
72+
ax.set_xticklabels([])
73+
ax.set_yticklabels([])
7374

7475
# Gap between lines in axes coords
7576
line_axesfrac = 1 / n_lines
7677

7778
# Plotting header demonstration formula
7879
full_demo = mathext_demos[0]
79-
plt.annotate(full_demo,
80-
xy=(0.5, 1. - 0.59 * line_axesfrac),
81-
color=mpl_orange_rvb, ha='center', fontsize=20)
80+
ax.annotate(full_demo,
81+
xy=(0.5, 1. - 0.59 * line_axesfrac),
82+
color=mpl_orange_rvb, ha='center', fontsize=20)
8283

8384
# Plotting features demonstration formulae
8485
for i_line in range(1, n_lines):
8586
baseline = 1 - i_line * line_axesfrac
8687
baseline_next = baseline - line_axesfrac
8788
title = mathtext_titles[i_line] + ":"
8889
fill_color = ['white', mpl_blue_rvb][i_line % 2]
89-
plt.fill_between([0., 1.], [baseline, baseline],
90-
[baseline_next, baseline_next],
91-
color=fill_color, alpha=0.5)
92-
plt.annotate(title,
93-
xy=(0.07, baseline - 0.3 * line_axesfrac),
94-
color=mpl_grey_rvb, weight='bold')
90+
ax.fill_between([0, 1], [baseline, baseline],
91+
[baseline_next, baseline_next],
92+
color=fill_color, alpha=0.5)
93+
ax.annotate(title,
94+
xy=(0.07, baseline - 0.3 * line_axesfrac),
95+
color=mpl_grey_rvb, weight='bold')
9596
demo = mathext_demos[i_line]
96-
plt.annotate(demo,
97-
xy=(0.05, baseline - 0.75 * line_axesfrac),
98-
color=mpl_grey_rvb, fontsize=16)
97+
ax.annotate(demo,
98+
xy=(0.05, baseline - 0.75 * line_axesfrac),
99+
color=mpl_grey_rvb, fontsize=16)
99100

100101
for i in range(n_lines):
101102
s = mathext_demos[i]

examples/text_labels_and_annotations/mathtext_fontfamily_example.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,26 @@
1313

1414
import matplotlib.pyplot as plt
1515

16-
plt.figure(figsize=(6, 5))
16+
17+
fig, ax = plt.subplots(figsize=(6, 5))
1718

1819
# A simple plot for the background.
19-
plt.plot(range(11), color="0.9")
20+
ax.plot(range(11), color="0.9")
2021

2122
# A text mixing normal text and math text.
2223
msg = (r"Normal Text. $Text\ in\ math\ mode:\ "
2324
r"\int_{0}^{\infty } x^2 dx$")
2425

2526
# Set the text in the plot.
26-
plt.text(1, 7, msg, size=12, math_fontfamily='cm')
27+
ax.text(1, 7, msg, size=12, math_fontfamily='cm')
2728

2829
# Set another font for the next text.
29-
plt.text(1, 3, msg, size=12, math_fontfamily='dejavuserif')
30+
ax.text(1, 3, msg, size=12, math_fontfamily='dejavuserif')
3031

3132
# *math_fontfamily* can be used in most places where there is text,
3233
# like in the title:
33-
plt.title(r"$Title\ in\ math\ mode:\ \int_{0}^{\infty } x^2 dx$",
34-
math_fontfamily='stixsans', size=14)
34+
ax.set_title(r"$Title\ in\ math\ mode:\ \int_{0}^{\infty } x^2 dx$",
35+
math_fontfamily='stixsans', size=14)
3536

3637
# Note that the normal text is not changed by *math_fontfamily*.
3738
plt.show()

0 commit comments

Comments
 (0)
0