1

I have a function that creates different sets of data depending on the input parameters you give it. I'm trying to create a plot that shows a graph of the returned data, and then under it, shows me a table/box with the input parameters that I passed into the function.

Here is a few of the strings I'm trying to make a table of

col_lables = ['interp', 'back', 'smooth_length', 'exclude', 'adj_sens', 'orient', 'extrfwhm']
table_vals = ['1', 'yes', 'None', 'False', 'False', 'no', '6.0']

I've tried initializing the table as so

the_table = pypl.table(cellText=table_vals,
colWidths=[0.1] * 3,
rowLabels=row_labels,
colLabels=col_labels,
loc='center right')

So far I've successfully graphed my data, however I cannot add a table that uses strings as it's cellText text.

Is there a way I could add a figure of some sort to my graph that would allow me to display col_labels and table_vals associated with with each other? Since there are a lot of parameters(more than I've shown), it would be best to keep this in a separate figure so the text will not obscure the graph.

Giovanni
  • 310
  • 2
  • 16

1 Answers1

1

You could use subplots or specify the exact coordinates of the axes to place the tables. Then you can turn off the frame and the ticks of the table. see: answer to: two tables in matplotlib

col_lables = ['interp', 'back', 'smooth_length', 'exclude', 'adj_sens', 'orient', 'extrfwhm']
table_vals = ['1', 'yes', 'None', 'False', 'False', 'no', '6.0']
axMain = subplot(2,1,1)
axTable1 = subplot(2,1,2, frameon =False)
setp(axTable1, xticks=[], yticks=[]) # a way of turning off ticks

axMain.plot([1,2,3])
tab1 = axTable1.table(cellText=[table_vals], loc='upper center', colLabels=col_lables)
tab1.scale(1.5,1.5)

The output looks like: table showing different columns

Community
  • 1
  • 1
Pablo Reyes
  • 3,073
  • 1
  • 20
  • 30
  • So I'm getting an assertion error when trying to add table_vals to the table. assert len(rowLabels) == rows Does this have anything to do with trying to use strings as the cellText? The length of my data and the length of my columns are both the same and the array is a 2D array, with a single array containing all my values. – Giovanni Dec 14 '16 at 20:42
  • I actually have updated my answer with your col_lables and table_vals. If that code doesn't work it might be your matplotlib version. I'm using version 2.0.0b4 . But I'm not aware of any issues with tables in previous versions. – Pablo Reyes Dec 14 '16 at 22:23
  • Your code worked! I found it wasn't the values, but the colWidths parameter that I had set that was causing the crash, possibly due to the amount of parameters I had to plot, as well as some of them are quite long. Thanks for your help! – Giovanni Dec 16 '16 at 00:44