python - Matplotlib 在表格中更改字体大小(只是标题) - python
问题描述
我希望列的标题具有比单元格中的值更小的字体,以便它们可读(我将在附加的 jpeg 中说明我的意思)。现在一切都具有相同的字体大小。
表代码示例:
fig = plt.figure(figsize=(11, 8.27))
ax = fig.add_subplot(111)
ax.axis('off')
index_length = len(well_data_table.index)
table_1 = well_data_table.iloc[0:30]
table_2= well_data_table.iloc[30:60]
table_3 = well_data_table.iloc[60:-1]
q='lightsalmon'
colors3 = [q,q,q,q,q,q,q,q,q,q,q]
the_table1 = ax.table(cellText=table_1.values, colWidths =
[.1]*len(table_1.columns),
rowLabels=table_1.index,
colColours = colors3,
colLabels=table_1.columns,
cellLoc = 'center', rowLoc = 'center',
loc='bottom',
bbox=[.1, 0, 1, 1])
the_table1.auto_set_font_size(False)
the_table1.set_fontsize(8)
the_table1.scale(1, 1)
ax.title.set_text("""TEST""")
pdf.savefig(facecolor='w')
解决方案
您可以遍历应该获得不同字体大小的表格单元格并在该循环中设置字体大小。
cells = the_table1._cells
for cell in the_table1._cells:
if cell[0] == 0:
the_table1._cells[cell].set_fontsize(8)
推荐阅读
- spring-boot - `SolrRepositoryFactoryBean` 在 bean 初始化期间未初始化 SolrOperations/SolrTemplate
- angular - 在 Angular 中使用 google 登录时出现 attachClickHandler 错误
- c++ - 如何在 C++ 的 main 中使用结构的数组数据成员?
- .net - Visual Studio 2019 安装程序错误“源布局目录太长”
- loops - Java-“For”循环条件以用户输入结束
- python - Python:读取完整的 .js 文件并更新该 js 文件中的特定方法
- autolayout - 在情节提要中选择 UILabel 时,它周围的白色区域是什么?
- binary - 我正在增加 CPU 代码中的程序计数器,它在继续之前停在六个及其倍数几个周期
- python - 如何在不使用 cv2.warpAffine() 的情况下翻译图像?[Python 3 和 OpenCV 4.1]
- flutter - “位置参数必须出现在命名参数之前。尝试在命名参数之前移动所有位置参数”错误颤动