ich möchte eine gemeinsame Legend für alle subplots erstellen und als eigenen subplot darstellen.
In die Legend soll der key meines dictionaries, funktioniert aber nicht...
Habt ihr eine tolle idee ?
Code: Alles auswählen
import numpy as np
import matplotlib.pyplot as plt
from collections import OrderedDict
def main():
x = np.arange(0, 300, 30)
y = np.arange(0, 200, 20)
z = np.arange(0, 100, 10)
XX = OrderedDict()
YY = OrderedDict()
ZZ = OrderedDict()
XX[1] = x
XX[2] = y
XX[3] = z
num_plots = 3
labels = []
fig = plt.figure(figsize=(6,5),facecolor='white')
ax1 = fig.add_subplot(2,2,1)
colormap = plt.cm.jet
plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 1, num_plots)])
for i in XX.keys():
plt.plot(XX[i])
labels.append(r'{0}'.format(i))
ax2 = fig.add_subplot(2,2,2)
colormap = plt.cm.jet
plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 1, num_plots)])
for i in XX.keys():
plt.plot(XX[i]^5)
ax3 = fig.add_subplot(2,2,3)
colormap = plt.cm.jet
plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 1, num_plots)])
for i in XX.keys():
plt.plot(XX[i]^10)
ax4 = fig.add_subplot(2,2,4)
colormap = plt.cm.jet
plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 1, num_plots)])
ax4.axis('off')
ax4.legend(labels)
plt.show()
print labels
if __name__ == '__main__':
main()