Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should be able to solve your problems doing the following:</p> <ul> <li><p>Figure size (<strong>edit</strong>): </p> <ul> <li>Measure how high and wide is a cell (e.g. <code>hcell=0.3</code>, <code>wcell=1</code>)</li> <li>Get/know the number of rows and columns (in your case <code>len(clust_data)+1</code> and 3)</li> <li><p>create the figure with the correct size (you might want some extra padding)</p> <pre><code>fig = plt.figure(figsize=(3*wcell+wpad, nrows*hcell+hpad)) </code></pre></li> </ul></li> <li><p>The lines within the two rows are the axes spines. </p> <pre><code>ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) </code></pre> <p>just hide the axis labels and ticks, not the axes spines. You have to hide them or colour them in white </p></li> </ul> <p><strong>see full solution below</strong></p> <hr> <p>In any case: it looks to me that you are doing a whole lot of useless operations. From your piece of code it seems to me that <code>clust_data</code> is already a list of lists with the correct shape and that <code>cellText</code> after being filled is going to be the same of <code>clust_data</code>.<br> Furthermore, try not to mix the OO and pyplot interface of matplotlib. </p> <p>The following code should be equivalent to yours</p> <pre><code>fig=plt.figure() ax = fig.add_subplot(111) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) colLabels=("Structure", "Energy", "Density") the_table = ax.table(cellText=clust_data, colLabels=colLabels, loc='center') plt.savefig("table.png") </code></pre> <hr> <h2>Edit: full solution</h2> <h2>Convoluted way</h2> <p>You have to hide the axes spines (e.g. setting their color white) and give them low <code>zorder</code> then add the table with higher <code>zorder</code></p> <pre><code>colLabels=("Structure", "Energy", "Density") nrows, ncols = len(clust_data)+1, len(colLabels) hcell, wcell = 0.3, 1. hpad, wpad = 0, 0 fig=plt.figure(figsize=(ncols*wcell+wpad, nrows*hcell+hpad)) ax = fig.add_subplot(111) #remove axis ticks and labels ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) #hide the spines for sp in ax.spines.itervalues(): sp.set_color('w') sp.set_zorder(0) #do the table the_table = ax.table(cellText=clust_data, colLabels=colLabels, loc='center') #put the table in front of the axes spines #for some reason zorder is not a keyword in ax.table the_table.set_zorder(10) plt.savefig("table.png") </code></pre> <h2>Simple way (credit @JoeKington)</h2> <p>Just switch off the axis</p> <pre><code>colLabels=("Structure", "Energy", "Density") nrows, ncols = len(clust_data)+1, len(colLabels) 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('off') #do the table the_table = ax.table(cellText=clust_data, colLabels=colLabels, loc='center') plt.savefig("table.png") </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload