<jupyter_start><jupyter_text>The following example shows how to plot a single legend for several subplots.<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import matplotlib.gridspec as gridspec

x=np.linspace(-5,5)
y=x**2
z=x**3

plt.style.use('Style/Paper.mplstyle')
fig = plt.figure(tight_layout=True,figsize=(6,6))
gs = gridspec.GridSpec(5, 2)
ax0=fig.add_subplot(gs[1:3,0])
ax0.plot(x,y,label='x^2',color='r')
ax1=fig.add_subplot(gs[3:5,1])
ax1.plot(x,z,label='x^3',color='b')
fig.legend(loc="upper center",fontsize=20)<jupyter_output><empty_output><jupyter_text>Plot legend for contour<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
def GetContour(x,y):
    z = (x-1)**2+(y-2)**2
    return z
xs = np.linspace(-5,5,200)
ys = np.linspace(-5,5,200)
xx,yy=np.meshgrid(xs,ys)
zz = GetContour(xx,yy)
labels = [1,5,10]
CS = plt.contour(xx,yy,zz,labels)
for i in range(len(labels)):
    CS.collections[i].set_label(labels[i])
plt.legend(loc='upper left')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17536945812807883, 'fraction_numerical': 0.03940886699507389, 'mean_word_length': 7.260162601626016, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '469010', 'license': 'MIT', 'n_tokens_mistral': 452, 'n_tokens_neox': 438, 'n_words': 73, 'path': 'Plots/Python/Subplt_Legends.ipynb', 'repo_name': 'Jinnan-Zhang/IHEP_HPC', 'size': '1015'}