I have table issues like this and obviously using the solution provided for that answer i can adjust the cells. What i don't understand is, without doing an eyeball test, how to detect that one is too big and the other is too small
Update
The code creates the graph below. Note the size of text under the table and the size of text in the list. Under is too big, list is too small. How do i programmatically detect these conditions without having to visually look at the chart.
import sys
import numpy as np
import pandas as pd
import random
import string
import matplotlib.pyplot as plt
import matplotlib.gridspec as grid_spec
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
month_labels = "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
month_list = np.r_[1:13]
month_bar_width = .35
plt.ion()
with plt.style.context('fivethirtyeight'):
fig = plt.figure(figsize=(8.5, 11))
gs = grid_spec.GridSpec(3, 3)
ax1 = plt.subplot(gs[0:2, 0:])
ax2 = plt.subplot(gs[2:3, 0])
names = [id_generator(10) for _ in range(20)]
counts = [random.randint(0,50) for _ in range(12)]
current_bbox = ax1.get_position()
bottom_of_1 = current_bbox.y0
current_bbox.y0 += (1 - current_bbox.y0) * .25
ax1.set_position(current_bbox)
cell_text = []
row_labels = []
row_colors = []
bar_start = np.arange(len(month_list))
bar_width = (bar_start[1] - bar_start[0]) * 0.7
row_bottom = np.zeros(len(month_list))
ax1.bar(bar_start, counts, width=bar_width)
cell_text.append(counts)
tbl = ax1.table(cellText=cell_text,loc='bottom')
ax1.set_xticks([])
rows = list(zip(names, counts))
tbl = ax2.table(cellText=rows, loc='center')
ax2.set_xticks([])
ax2.set_yticks([])
Update 2 I can add the following code from the previous answer:
table_props = tbl.properties()
table_cells = table_props['child_artists']
for cell in table_cells: cell.set_height(0.1)
but the 0.1 is picked by eyeballing the graph and looking at the current value in height. What i'm looking for is how to calculate the 0.1 without looking at the graph. If the current height is .5 and the height is too small i need to make it larger, but if i want to make it smaller it has to be .4. What's the formula for knowing what situation you are in. Or conversely knowing the the height is ok but you need to change the font size.