3D बार चार्ट में लीजेंड जोड़ने के लिए plt.Rectangle प्रॉक्सी आर्टिस्ट्स बनाएं और ax.legend() में पास करें।
चरण
- फिगर साइज़ और ऑटोलेआउट सेट करें।
- 3D एक्सिस बनाएं और दो सेट्स के 3D बार्स प्लॉट करें (अलग रंग)।
- प्रत्येक सेट के लिए
plt.Rectangle((0,0), 1, 1, fc='color')प्रॉक्सी बनाएं। ax.legend([proxy1, proxy2], ['label1', 'label2'])से लीजेंड जोड़ें।plt.show()से दिखाएं।
उदाहरण कोड
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
x3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y3 = [5, 6, 7, 8, 2, 5, 6, 3, 7, 2]
z3 = np.zeros(10)
dx = np.ones(10)
dy = np.ones(10)
dz = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ax1.bar3d(x3, y3, z3, dx, dy, dz, color="green")
b1 = plt.Rectangle((0, 0), 1, 1, fc="green")
ax1.bar3d(y3, x3, z3, dx, dy, dz, color="red")
b2 = plt.Rectangle((0, 0), 1, 1, fc="red")
ax1.legend([b1, b2], ['type1', 'type2'])
plt.show()
आउटपुट
हरे और लाल 3D बार्स के साथ लीजेंड दिखाता है 'type1' और 'type2'।