コードの半分が欠落している場合、特にfontsize=12
を設定する必要があります。そうしないと、サンプルテキストが表示されません。 linespacing=2.
についてjupyterノートブックに示されているその2.0か、単に、マイナータイプ;-)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
from matplotlib.backends.backend_pdf import PdfPages
with PdfPages('filename3.pdf') as pdf:
plt.figure(figsize=(3, 3))
plt.plot(range(7), [3, 1, 4, 1, 5, 9, 2], 'r-o')
#t = np.arange(0.0, 2.0, 0.01)
#s = 1 + np.sin(2 * np.pi * t)
#plt.plot(t, s)
plt.title('Page One')
plt.savefig(pdf, format = 'pdf') # saves the current figure into a pdf page
plt.close()
plt.rc('text', usetex=False)
plt.figure(figsize=(8, 6))
x = np.arange(0, 5, 0.1)
plt.plot(x, np.sin(x), 'b-')
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s)
ax.text(0.5, 0.5, 'Some Text Here', linespacing=2, fontsize=12, multialignment='left')
ax.set(xlabel='time (s)', ylabel='voltage (mV)',
title='About as simple as it gets, folks')
ax.grid()
#plt.title('Page Two')
pdf.attach_note("plot of sin(x)", positionRect=[-100, -100, 0, 0]) # you can add a pdf note to
# attach metadata to a page
plt.savefig(pdf, format = 'pdf')
plt.close()
テキスト座標(8,0.9)は、私が推測するグラフの表示範囲内にありません。 –