我在下面的示例生成的表格上有一个绘图.表格数据被随机数替换,实际图表被一些仲裁函数取代:
import numpy as np import matplotlib.pylab as plt fig, ax = plt.subplots() ntp = 17 # number of peak periods nhs = 30 # number of wave heights scatter_table = np.random.randint(0,10,(nhs,ntp)) # wave scatter diagram tp = np.linspace(3,20,ntp+1) # peak period array hs = np.linspace(0,15,nhs+1) # significant wave height # axis limits to be in line with scatter diagram ax.set_xlim((min(tp),max(tp))) ax.set_ylim((min(hs),max(hs))) # axis ticks as per scatter table bins ax.set_xticks(tp) ax.set_yticks(hs) # matplotlib table the_table = plt.table(cellText=scatter_table,loc=(0,0),cellLoc='center') # change table properties to match plot window table_props = the_table.properties() table_cells = table_props['child_artists'] for cell in table_cells: cell.set_height(1/float(nhs)) cell.set_width(1/float(ntp)) # plot! ax.plot(tp,4+0.2*tp+np.sin(tp)*0.25*tp) plt.grid() plt.show()
我的问题是:是否有可能删除表格边框?或者,我会将颜色更改为浅灰色并应用虚线样式.
如果要从每个表格单元格中删除边框,可以将其添加到每个表格单元格上的现有循环中:
for key, cell in tab.get_celld().items(): cell.set_linewidth(0)
这允许您使用如改变各单元的所有特性set_linestyle()
,set_edgecolor()
,set_fontsize()
,等: