aksell commited on
Commit
c82ea4d
·
1 Parent(s): 941854b

Adjust label size with label count

Browse files
Files changed (1) hide show
  1. hexviz/plot.py +12 -2
hexviz/plot.py CHANGED
@@ -49,13 +49,23 @@ def plot_single_heatmap(
49
  fig, ax = plt.subplots(figsize=(10, 10))
50
  heatmap = ax.imshow(single_heatmap, cmap="viridis", aspect="equal", vmin=0, vmax=1)
51
 
 
 
 
 
 
 
 
 
 
 
52
  # Set the x and y axis ticks
53
  ax.xaxis.set_major_locator(FixedLocator(np.arange(0, len(tokens))))
54
  ax.yaxis.set_major_locator(FixedLocator(np.arange(0, len(tokens))))
55
 
56
  # Set tick labels as sequence values
57
- ax.set_xticklabels(tokens, fontsize=8, rotation=45, ha="right", rotation_mode="anchor")
58
- ax.set_yticklabels(tokens, fontsize=8)
59
 
60
  # Set the axis labels
61
  ax.set_xlabel("Sequence tokens")
 
49
  fig, ax = plt.subplots(figsize=(10, 10))
50
  heatmap = ax.imshow(single_heatmap, cmap="viridis", aspect="equal", vmin=0, vmax=1)
51
 
52
+ # Function to adjust font size based on the number of labels
53
+ def get_font_size(labels):
54
+ if len(labels) <= 60:
55
+ return 8
56
+ else:
57
+ return 8 * (60 / len(labels))
58
+
59
+ # Adjust font size
60
+ font_size = get_font_size(tokens)
61
+
62
  # Set the x and y axis ticks
63
  ax.xaxis.set_major_locator(FixedLocator(np.arange(0, len(tokens))))
64
  ax.yaxis.set_major_locator(FixedLocator(np.arange(0, len(tokens))))
65
 
66
  # Set tick labels as sequence values
67
+ ax.set_xticklabels(tokens, fontsize=font_size, rotation=45, ha="right", rotation_mode="anchor")
68
+ ax.set_yticklabels(tokens, fontsize=font_size)
69
 
70
  # Set the axis labels
71
  ax.set_xlabel("Sequence tokens")