![](/img/trans.png)
[英]Python / matplotlib: print to resolution and without white space / borders / margins
[英]python matplotlib table without borders
我在以下示例生成的表格頂部繪制了一個圖。 表數據被隨機數替換,實際圖被一些任意函數替換:
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()
我的問題是:是否有可能刪除表格邊框? 或者,我會將顏色更改為淺灰色並應用虛線樣式。
“如果您在對表的調用中設置了 edge='open',則不需要擦洗邊框”-MD004 https://stackoverflow.com/a/56515764/927972
ax.table(...,edges='open')
嘗試這個:
[i.set_linewidth(0.1) for i in ax.spines.itervalues(0)]
這對你有用嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.