pythonmatplotlib图中插⼊表格python matplotlib图中插⼊表格
解决问题
在matplotlib画的图⾥插⼊表格数据。使⽤到pyplot和gridspec函数。
⽰例代码
#导⼊库
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from matplotlib import gridspec
#⽰例代码
a = list(range(10))
b = np.random.randint(1,100,10)
plt.figure(figsize=(7,7))
gs = gridspec.GridSpec(4,1)
# 画图表
ax1 = plt.subplot(gs[:3,0])
ax1.bar(a,b)
plt.xlabel('x Label')
plt.ylabel('y Label')
plt.title('title')
# 插⼊表格
ax2 = plt.subplot(gs[3,0])
matplotlib中subplotplt.axis('off')
rowLabels = ['第⼀⾏','第⼆⾏','第三⾏'] # 表格⾏名
cellText = [[1,2,3],[4,5,6],[7,8,9]] #表格每⼀⾏数据
table = plt.table(cellText=cellText, rowLabels=rowLabels, loc='center', cellLoc='center',rowLoc='center') table.auto_set_font_size(False)
table.set_fontsize(10) #字体⼤⼩
table.scale(1, 1.5) #表格缩放
结果

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。