코드의 절반을 놓치고 특히 fontsize=12
을 설정해야합니다. 그렇지 않으면 예제 텍스트가 표시되지 않습니다. linespacing=2.
에 대한 2.0하거나 2는 jupyter 노트북에 표시된 작은 유형 ;-)
#!/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)가 그래프의 표시된 범위 내에 있지 않습니다. –