Skip to content

Commit

Permalink
Added legend format
Browse files Browse the repository at this point in the history
  • Loading branch information
hklion committed May 19, 2019
1 parent 1c9610a commit 653044c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions legend_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import matplotlib.pyplot as plt
import matplotlib.lines as mlines

blank_line = mlines.Line2D([],[],color='none',label='')

def format_handles(handle_list, cols=[1], align='up'):
if len(cols) == 1:
return handle_list
assert len(handle_list) > 0
assert len(handle_list) == sum(cols)

original_len = len(handle_list)
max_col_len = max(cols)
final_len = max(cols) * len(cols)
i_handle = 0
i_col = 0
for i, col_size in enumerate(cols):
n_blanks = max_col_len - col_size
if align == 'up':
for blank in range(n_blanks):
handle_list.insert(i * max_col_len + col_size, blank_line)
elif align == 'down':
for blank in range(n_blanks):
handle_list.insert(i * max_col_len, blank_line)
return handle_list


0 comments on commit 653044c

Please sign in to comment.