Skip to content

Instantly share code, notes, and snippets.

@JesseLivezey
Created May 26, 2018 17:38
Show Gist options
  • Save JesseLivezey/7e1ae7f218db688a943ca97e4ead84ce to your computer and use it in GitHub Desktop.
Save JesseLivezey/7e1ae7f218db688a943ca97e4ead84ce to your computer and use it in GitHub Desktop.
Example figure creation
# All sizes are in fraction of the figure size
figsize = (6, 7.5)
f = plt.figure(figsize=figsize)
# borders
top_edge = .03
bot_edge = .055
l_edge = .15
r_edge = .01
# gaps between panels
h_gap = .05
v0_gap = .05
v1_gap = .06
# confusion matrix and bottom panel
width_cm = .625
bot_height = .175
bot_width = 1. - l_edge - r_edge
# Make confusion matrix square
height_cm = width_cm * figsize[0] / figsize[1]
# Dendrogram axis
height_d = 1 - bot_edge - bot_height - v0_gap - height_cm - v1_gap - top_edge
r0_y = bot_edge + bot_height + v0_gap + height_cm + v1_gap
x0 = l_edge
ax0 = f.add_axes([x0, r0_y, width_cm, height_d])
width = 1 - l_edge - width_cm - h_gap - r_edge
# Distance plot
x1 = x0 + width_cm + h_gap
ax1 = f.add_axes([x1, r0_y, width, height_d])
r1_y = bot_edge + bot_height + v1_gap
# Colorbar
x2 = x1 + width + h_gap
cax = f.add_axes([l_edge, r1_y - .45 * v1_gap, .075, .02])
# Confusion matrix
ax2 = f.add_axes([l_edge, r1_y, width_cm, height_cm])
# CV accuracies
width = 1 - l_edge - width_cm - h_gap - r_edge
ax3 = f.add_axes([l_edge + width_cm + h_gap, r1_y, width, height_cm])
# Correlations
ax4 = f.add_axes([l_edge, bot_edge, bot_width, bot_height])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment