a = None
b = [1, 2, 3]
if a == None:
c = b
else:
c = a
修改后,去掉 if
c = a or b
# 输出c为 [1, 2, 3]
如果 label_set 有33,col_length固定为5,每行绘制5个,小于5个绘制一行,大于5个小于11个则绘制2行。
if label_set is None:
label_set = sorted(df_10min_minus_part.label.unique(), reverse=False)
if len(label_set) <= col_length:
ax_row, ax_col = 1, col_length
elif len(label_set) % col_length == 0:
ax_row, ax_col = len(label_set) // col_length, col_length
else:
ax_row, ax_col = len(label_set) // col_length + 1, col_length
改为:
最后一行代码,total_labels为33, (33先+5-1)//col_length 整除,保证不会增加1行,又不少行
label_set = label_set or sorted(df_10min_minus_part.label.unique())
total_labels = len(label_set)
ax_row = (total_labels + col_length - 1) // col_length