使用
loc='center'
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
col_names = ["this", "that","the other","4","5","6"]
data = np.random.randint(100, size=(40,6)).astype('str')
fig, ax = plt.subplots(1, figsize=(10,10))
ax.axis('off')
_table = plt.table(cellText=data, colLabels=col_names,
loc='center', edges='open', colLoc='right')
pdf = PdfPages('test.pdf')
pdf.savefig(fig)
pdf.close()
Axes
例子使用这种方法可能更安全
matplotlib.axes.Axes.table
使用。
笔记
我在Matplotlib 2.2.5和3.2.1中测试过,如果上面的代码确实产生了我所展示的结果,请考虑更新您的MaMattLIB安装。