I have a plot on top of a table as generated by following example. Table data is replaced by random numbers and the actual plot is replaced by some arbitryry function:
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()
My question is: Is there a possibility to remove the table borders? Alternatively, I would change the color to a lighter grey and apply a dashed line style.
MatPlotLib with Python Convert the image from one color space to another. To remove grid lines, use ax. grid(False).
Matplotlib allows you to regulate the transparency of a graph plot using the alpha attribute. By default, alpha=1. If you would like to form the graph plot more transparent, then you'll make alpha but 1, such as 0.5 or 0.25.
If you want to remove the border from each table cell, you could add this to your existing loop over each table cell:
for key, cell in tab.get_celld().items():
cell.set_linewidth(0)
This allows you to change all properties of each cell using e.g. set_linestyle()
, set_edgecolor()
, set_fontsize()
, etc:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With