Issue
I like the current dimensions, fontsize, and look of my table. However, I'd like to increase the width of each cell by a little bit top/bottom (so it looks a bit prettier and less squished). But I don't quite know how to do that.
columns=['test', 'test', 'test', 'test', 'test', 'test', 'test']
rows=['test', 'test', 'test', 'test']
data=[['12.103700223192147', '125.7421234247654', '2833.324510310368', '3.3228806335297043', '103.23943179349797', '3.5559560514887627', '3.531198576041594'], ['312.22548840603355', '335.1632073701661', '688.6576628644414', '2.0598429919314976', '18.362768351047666', '1.3152545139887966', '1.3155809229679902'], ['461.0540288130374', '484.64756706242093', '757.5346438101953', '5.1333110653922684', '15.039352280544852', '1.5898237491783822', '1.5902652486082376'], ['263.82124695572776', '313.264919044118', '276.03008066454083', '140.61329994689453', '7.034269824508681', '6.71122466853062', '4.613448380627191']]
wpad,hpad=0.1,0.1
fig = plt.figure(figsize=(len(columns)*3+wpad, len(rows)*3+hpad))
tab=plt.table(data,rowLabels=rows,colLabels=columns,cellLoc='center',loc='top')
tab.auto_set_font_size(False)
tab.auto_set_column_width(col=list(range(len(columns))))
plt.axis('off')
plt.show()
As can be observed (ignoring the whitespace), the width is good, but a little squished. I'd like to give it a little bit of "breathing" room (e.g. 0.1in).
Solution
There is a .scale(...)
method. It operates using a multiplication factor rather than by directly specifying the row height.
<your existing code>
.
.
.
tab.scale(xscale=1, yscale=2)
plt.axis('off')
plt.show()
On the docs page the matplotlib developers suggest taking a look at another package for tables if you were after more features:
The table implementation in Matplotlib is lightly maintained. For a more featureful table implementation, you may wish to try blume.
Answered By - user3128
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.