Last active
September 2, 2019 06:53
-
-
Save jeasinema/8ec482ef89282fdb6c83e2fe0c912ced to your computer and use it in GitHub Desktop.
Create customized legend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from matplotlib.lines import Line2D | |
import seaborn as sns | |
import numpy as np | |
fig = plt.figure() | |
fig.set_size_inches(18, 3) | |
ax = fig.subplots(1) | |
label = ['Expert', 'Demo', 'Pre-train', 'POfD', 'Penalty', 'Penalty + Ann.', 'Ours'] | |
flatui = ["#9b59b6", "#999900", "#3498db", "#95a5a6", "#009900", "#fc9272", "#e74c3c"] | |
clrs = sns.color_palette(flatui) | |
custom_lines = [Line2D([0], [0], color=clrs[0], lw=2, linestyle='--'), | |
Line2D([0], [0], color=clrs[1], lw=2, linestyle='--'), | |
Line2D([0], [0], color=clrs[2], lw=2, linestyle='-'), | |
Line2D([0], [0], color=clrs[3], lw=2, linestyle='-'), | |
Line2D([0], [0], color=clrs[4], lw=2, linestyle='-'), | |
Line2D([0], [0], color=clrs[5], lw=2, linestyle='-'), | |
Line2D([0], [0], color=clrs[6], lw=2, linestyle='-')] | |
with sns.axes_style('darkgrid'): | |
for i in range(len(label)): | |
ax.plot(np.arange(10), np.ones(10), c=clrs[i]) | |
box = ax.get_position() | |
ax.set_position([box.x0, box.y0 + box.height * 0.1, | |
box.width, box.height * 0.9]) | |
ax.legend(handles=custom_lines, labels=label, ncol=7, shadow=False, facecolor='white', handlelength=2.0, columnspacing=1.0, handletextpad=0.4, loc='upper center', bbox_to_anchor=(0.5, -0.1)) | |
fig.savefig('legend.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment