I am trying to create a table using matplotlib and I have been able to get my data but I The final formatting I need to edit the size of the data to include all my data, because some are cutting, here's my current code: clust_data for structures, energy, density
: fig = PL T.figer () ax = plt.gca () ax.xaxis.set_viewible (false) ax.yaxis .set_visible (false) colLabels = ("structure", "energy", "density") rows = len (clust_data) cellText = [] For the row in clust_data: cellText.append (line) the_table = ax.table (cellText = cellText, Collabels = colLabels, loc = 'center') plt.savefig ("table.png") < / Pre> Which table makes it so (I'm not sure how either rows through some lines):
Any help is greatly appreciated
You should be able to solve your problems:
<<> code> Wassel = 1 ) - Find / Find the number of rows and columns (in your case
len (cl Ust_data) + 1 and 3) -
Draw a shape with the right size (you want some extra padding)
fig = PLT figures (figs = ( 3 * wcell + wpad, nrows * hcell + hpad)) -
The lines within two rows are axial They are spinning
ax.xaxis.set_viewible (false) ax.yaxis.set_visible (false) Just hide axis and ticks, hide of axes Not spinning
See the complete solution below
In any case you have to hide or paint them It seems to me that you are doing a lot of useless operations, from the piece of your code, I think that clust_data is already a list of lists with the correct size and it is clust_data after filling in celltext . Also, try not to mix the matopotlib oo and pipeline interface. The following code should be equal to yours
fig = plt.figure () ax = fig.add_subplot (111) ax.xaxis.set_visible (false) ax. Yaxis.set_viewable (wrong) colLabels = ("structure", "energy", "density") the_table = ax.table (celltyxt = clust_data, colLabels = colLabels, loc = 'center') plt.savefig ("table.png" )
Edit: Complete Solution Forbidden Method
You will have to hide the axes (like setting them in white form) Give less zorder and add a table with the high zorder colLabels = ("structure", "energy", "density"). Nrows, ncols = len (clust_data) +1, lane (colLables) hcell, wcell = 0.3, 1. hpad, wpad = 0, 0 fig = plt.figure (figsize = (ncols * wcell + wpad, nrows * hcell + hpad )) Ax = leave the spines for sp in fig.add_subplot (111) #remove axis ticks and label ax.xaxis.set_visible (false) ax.yaxis.set_visible (false) # ax.spines.itervalues () : Sp.set_color ('w') sp.set_zorder (0) #do table the_table = ax.table (cellText # Clust_data, colLabels = colLabels, loc = 'center') #put Tables in front of axes # zorder for some reason Ax.table the_table.set_zorder (10) plt.savefig ("table.png" has no keywords the simplest way (credit @ jokington)
just a Closing Columns
colLabels = ("structure", "energy", "density") nrows, ncols = len (clust_data) +1, lane (colLables) hcell, wcell = 0.3, 1 .hpad, wpad = 0, 0 fig = plt.figure (figsize = (ncols * wcell + wpad, nrows * hcell + hpad)) ax = fig.add_subplot (111) ax.axis ('closed') #desk table_table = Ax.table (cellText = clust_data, colLabels = colLabels, loc = 'center') plt .savefig ("table.png")
No comments:
Post a Comment