python - Matplotlib table formatting -


enter image description here can't seem locate in documentation how increase line-height of cells, text cramped.

any code appreciated! table formatting doesn't seem documented...

    # plot line width     matplotlib.rc('lines', linewidth=3)      ind = np.arange(len(overall))      fig = pyplot.figure()     ax = fig.add_subplot(211)     ax.set_title('overall rating of experience')     ax.set_ylabel('score (0-100)')      # plot data on chart     plot1 = ax.plot(ind, overall)     plot2 = ax.plot(ind, svc_avg)     plot3 = ax.plot(ind, benchmark)      ax.yaxis.grid(true, which='major', ls='-', color='#9f9f9f')     ax.set_ylim([min(overall + svc_avg + benchmark) - 3, 100])     ax.set_xlim([-.5,1.5])     ax.get_xaxis().set_ticks([])     ax.set_position([.25, .3, 0.7, 0.5])      collabels = ['july', 'august']     rowlabels = ['average', 'service average', 'benchmark']     celltext = [overall, svc_avg, benchmark]     the_table = ax.table(celltext=celltext, rowloc='right',                          rowcolours=colors, rowlabels=rowlabels,                          colwidths=[.5,.5], collabels=collabels,                          colloc='center', loc='bottom') 

edit: oz answer-- looping through properties of table allows easy modification of height property:

    table_props = the_table.properties()     table_cells = table_props['child_artists']     cell in table_cells: cell.set_height(0.1) 

the matplotlib documentation says

add table current axes. returns matplotlib.table.table instance. finer grained control on tables, use table class , add axes add_table().

you following, @ properties of table (it's , object belonging class table):

print  the_table.properties() # hint it's dictionary do: type(the_table.properties() <type 'dict'>  

edit dictionary way see right, , update table, with:

the_table.update(givehereyourdictionary) 

hint: if work ipython or interactive shell it's enough help(objectname), e.g. help(the_table) see object's methods. should, hopefully, work.

ok, i'm adding here walk through of how to kind of stuff. admit, it's not trivial, using matplotlib 3.5 years now, ...

do code in ipython (i said before, must emphasize again), helps examine properties objects have (type object name , key):

in [95]: prop=the_table.properties() in [96]: prop #this dictionary, it's not trivial, never less 1 can understand how dictionaries work... out[96]:  {'agg_filter': none,  'alpha': none,  'animated': false,  'axes': <matplotlib.axes.axessubplot @ 0x9eba34c>,  'celld': {(0, -1): <matplotlib.table.cell @ 0xa0cf5ec>,   (0, 0): <matplotlib.table.cell @ 0xa0c2d0c>,   (0, 1): <matplotlib.table.cell @ 0xa0c2dec>,   (0, 2): <matplotlib.table.cell @ 0xa0c2ecc>,   (1, -1): <matplotlib.table.cell @ 0xa0cf72c>,   (1, 0): <matplotlib.table.cell @ 0xa0c2fac>,   (1, 1): <matplotlib.table.cell @ 0xa0cf08c>,   (1, 2): <matplotlib.table.cell @ 0xa0cf18c>,   (2, -1): <matplotlib.table.cell @ 0xa0cf84c>,   (2, 0): <matplotlib.table.cell @ 0xa0cf28c>,   (2, 1): <matplotlib.table.cell @ 0xa0cf3ac>,   (2, 2): <matplotlib.table.cell @ 0xa0cf4cc>},  'child_artists': [<matplotlib.table.cell @ 0xa0c2dec>,   <matplotlib.table.cell @ 0xa0cf18c>,   <matplotlib.table.cell @ 0xa0c2d0c>,   <matplotlib.table.cell @ 0xa0cf84c>,   <matplotlib.table.cell @ 0xa0cf3ac>,   <matplotlib.table.cell @ 0xa0cf08c>,   <matplotlib.table.cell @ 0xa0cf28c>,   <matplotlib.table.cell @ 0xa0cf4cc>,   <matplotlib.table.cell @ 0xa0cf5ec>,   <matplotlib.table.cell @ 0xa0c2fac>,   <matplotlib.table.cell @ 0xa0cf72c>,   <matplotlib.table.cell @ 0xa0c2ecc>],  'children': [<matplotlib.table.cell @ 0xa0c2dec>,   <matplotlib.table.cell @ 0xa0cf18c>,   ...snip snap ...   <matplotlib.table.cell @ 0xa0cf72c>,   <matplotlib.table.cell @ 0xa0c2ecc>],  'clip_box': transformedbbox(bbox(array([[ 0.,  0.],        [ 1.,  1.]])), compositeaffine2d(bboxtransformto(bbox(array([[ 0.,  0.],        [ 1.,  1.]]))), bboxtransformto(transformedbbox(bbox(array([[ 0.25,  0.3 ],        [ 0.95,  0.8 ]])), bboxtransformto(transformedbbox(bbox(array([[ 0.,  0.],        [ 8.,  6.]])), affine2d(array([[ 80.,   0.,   0.],        [  0.,  80.,   0.],        [  0.,   0.,   1.]])))))))),  'clip_on': true,  'clip_path': none,  'contains': none,  'figure': <matplotlib.figure.figure @ 0x9eaf56c>,  'gid': none,  'label': '',  'picker': none,  'rasterized': none,  'snap': none,  'transform': bboxtransformto(transformedbbox(bbox(array([[ 0.25,  0.3 ],        [ 0.95,  0.8 ]])), bboxtransformto(transformedbbox(bbox(array([[ 0.,  0.],        [ 8.,  6.]])), affine2d(array([[ 80.,   0.,   0.],        [  0.,  80.,   0.],        [  0.,   0.,   1.]])))))),  'transformed_clip_path_and_affine': (none, none),  'url': none,  'visible': true,  'zorder': 0}  # cells ...  [97]: cells = prop['child_artists']  in [98]: cells out[98]:  [<matplotlib.table.cell @ 0xa0c2dec>,  <matplotlib.table.cell @ 0xa0cf18c>, ... snip snap...  <matplotlib.table.cell @ 0xa0cf72c>,  <matplotlib.table.cell @ 0xa0c2ecc>]  in [99]:cell=cells[0] in [100]: cell # press tab here see cell's attributes  display 122 possibilities? (y or n) cell.pad cell.add_callback ...snip snap ... cell.draw cell.eventson cell.figure ...snip snap ... in [100]: cell.set_h cell.set_hatch   cell.set_height   # looks promising no? hell, love python ;-) wait, let's examine first ... in [100]: cell.get_height() out[100]: 0.055555555555555552 in [101]: cell.set_height(0.1) # 'doubled' height... in [103]: pyplot.show() 

and ta da:

table modified height 1 cell

now, challege change height of cells, using loop. should not hard. nice win bounty ;-)


Comments

Popular posts from this blog

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -

c# - Getting per connection bandwidth statistics -

how to run a java applet in web browser -