0

How can I add one legend for all subplots? The legend should be on the side with 4 markers one below the other:

  • c='738A3E', alpha=0.3, marker='^'
  • c='#738A3E', alpha=0.3, marker='v'
  • c='#007CAE', alpha=0.3, marker='^'
  • c='#007CAE', alpha=0.3, marker='v'

I cannot figure out how to even generate a legend for this. Help would be much appreciated.

fig1 = plt.figure(figsize=(6, 12))

for i in range(0,10):
    plt.subplot(5, 2, i+1).set_title('Range {}' .format(i+1))

plt.tight_layout()

for j in range(0, X.shape[1]):
    if X[12,j] > 75 and X[10,j] > 7000:
        ax1 = plt.scatter(X[i,j], y[i,j], c='#738A3E', alpha=0.3, marker='^')
    elif X[12,j] > 75 and X[10,j] <= 7000:
        ax2 = plt.scatter(X[i,j], y[i,j], c='#738A3E', alpha=0.3, marker='v')
    elif X[12,j] <= 75 and X[10,j] > 7000:
        ax3 = plt.scatter(X[i,j], y[i,j], c='#007CAE', alpha=0.3, marker='^')
    elif X[12,j] <= 75 and X[10,j] <= 7000:
        ax4 = plt.scatter(X[i,j], y[i,j], c='#007CAE', alpha=0.3, marker='v')

plt.xlim([min(X[i,:]), max(X[i,:])])
Peter Leimbigler
  • 10,775
  • 1
  • 23
  • 37
Alex
  • 13
  • 2
  • `NameError: name 'X' is not defined`. This question is not reproducible without **data**. Always provide a [mre] **with code, data, errors, current output, and expected output, as [formatted text](https://stackoverflow.com/help/formatting)**. If relevant, plot images are okay. – Trenton McKinney Sep 12 '21 at 21:08
  • https://matplotlib.org/devdocs/gallery/text_labels_and_annotations/custom_legends.html and https://matplotlib.org/stable/tutorials/intermediate/legend_guide.html – Trenton McKinney Sep 12 '21 at 21:11

0 Answers0