Eva*_* Y. 11 python matplotlib pylot
我正在绘制一个像这样的pyplot表:
sub_axes.table(cellText=table_vals,
colWidths = [0.15, 0.25],
rowLabels=row_labels,
loc='right')
Run Code Online (Sandbox Code Playgroud)
我想更改表格内容的字体大小,发现有一个fontsize属性,请参考'table'的定义.
所以它变成:
sub_axes.table(cellText=table_vals,
colWidths = [0.15, 0.25],
rowLabels=row_labels,
fontsize=12,
loc='right')
Run Code Online (Sandbox Code Playgroud)
但是当我执行代码时,我收到了一个错误:
TypeError: table() got an unexpected keyword argument 'fontsize'
Run Code Online (Sandbox Code Playgroud)
这个属性是否已被弃用?如何用pyplot更改表格的字体大小?
unu*_*tbu 30
我认为文档要么暗示要参数(通知fontsize不是像其他参数那样的链接),要么目前可能有点误导.没有fontsize参数.
通过源代码挖掘,我找到了Table.set_fontsize方法:
table = sub_axes.table(cellText=table_vals,
colWidths = [0.15, 0.25],
rowLabels=row_labels,
loc='right')
table.set_fontsize(14)
the_table.scale(1.5, 1.5) # may help
Run Code Online (Sandbox Code Playgroud)
这是一个夸张的字体大小的例子,只是为了显示效果.
import matplotlib.pyplot as plt
# Based on http://stackoverflow.com/a/8531491/190597 (Andrey Sobolev)
fig = plt.figure()
ax = fig.add_subplot(111)
y = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1]
col_labels = ['col1', 'col2', 'col3']
row_labels = ['row1', 'row2', 'row3']
table_vals = [[11, 12, 13], [21, 22, 23], [31, 32, 33]]
the_table = plt.table(cellText=table_vals,
colWidths=[0.1] * 3,
rowLabels=row_labels,
colLabels=col_labels,
loc='center right')
the_table.auto_set_font_size(False)
the_table.set_fontsize(24)
the_table.scale(2, 2)
plt.plot(y)
plt.show()
Run Code Online (Sandbox Code Playgroud)

小智 16
设置auto_set_font_size到False,然后set_fontsize(24)
the_table.auto_set_font_size(False)
the_table.set_fontsize(24)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22879 次 |
| 最近记录: |