Tôi đã tạo biểu đồ đồ thị phân tán 4D để biểu thị các nhiệt độ khác nhau trong một khu vực cụ thể. Khi tôi tạo chú thích, chú giải cho thấy biểu tượng và màu sắc chính xác nhưng thêm một dòng thông qua nó. Mã Tôi đang sử dụng là:Matplotlib scatter plot legend
colors=['b', 'c', 'y', 'm', 'r']
lo = plt.Line2D(range(10), range(10), marker='x', color=colors[0])
ll = plt.Line2D(range(10), range(10), marker='o', color=colors[0])
l = plt.Line2D(range(10), range(10), marker='o',color=colors[1])
a = plt.Line2D(range(10), range(10), marker='o',color=colors[2])
h = plt.Line2D(range(10), range(10), marker='o',color=colors[3])
hh = plt.Line2D(range(10), range(10), marker='o',color=colors[4])
ho = plt.Line2D(range(10), range(10), marker='x', color=colors[4])
plt.legend((lo,ll,l,a, h, hh, ho),('Low Outlier', 'LoLo','Lo', 'Average', 'Hi', 'HiHi', 'High Outlier'),numpoints=1, loc='lower left', ncol=3, fontsize=8)
tôi đã cố gắng thay đổi Line2D
-Scatter
và scatter
. Scatter
trả về lỗi và scatter
thay đổi biểu đồ và trả lại lỗi.
Với scatter
, tôi đã thay đổi range(10)
thành danh sách chứa các điểm dữ liệu. Mỗi danh sách chứa biến x, y hoặc z.
lo = plt.scatter(xLOutlier, yLOutlier, zLOutlier, marker='x', color=colors[0])
ll = plt.scatter(xLoLo, yLoLo, zLoLo, marker='o', color=colors[0])
l = plt.scatter(xLo, yLo, zLo, marker='o',color=colors[1])
a = plt.scatter(xAverage, yAverage, zAverage, marker='o',color=colors[2])
h = plt.scatter(xHi, yHi, zHi, marker='o',color=colors[3])
hh = plt.scatter(xHiHi, yHiHi, zHiHi, marker='o',color=colors[4])
ho = plt.scatter(xHOutlier, yHOutlier, zHOutlier, marker='x', color=colors[4])
plt.legend((lo,ll,l,a, h, hh, ho),('Low Outlier', 'LoLo','Lo', 'Average', 'Hi', 'HiHi', 'High Outlier'),scatterpoints=1, loc='lower left', ncol=3, fontsize=8)
Khi tôi chạy điều này, chú giải không còn tồn tại nữa, nó là một ô nhỏ màu trắng ở góc không có gì trong đó.
Bạn có lời khuyên nào không?
Tôi tin rằng một giải pháp tốt hơn được đưa ra [ở đây] (http://stackoverflow.com/questions/21654635/scatter-plots-in-pandas-pyplot-how-to-plot -by-category). – dmvianna