【发布时间】:2020-05-28 16:41:57
【问题描述】:
背景:
我有一个 list_of_x_and_y_list,其中包含 x 和 y 值,如下所示:
[[(44800, 14888), (132000, 12500), (40554, 12900)], [(None, 193788), (101653, 78880), (3866, 160000)]]
我还有一个data_name_list ["data_a","data_b"] 这样
"data_a" = [(44800, 14888), (132000, 12500), (40554, 12900)]"data_b" = [(None, 193788), (101653, 78880), (3866, 160000)]
list_of_x_and_y_list 的len / 或data_name_list 的len > 20。
问题:
如何为data_name_list 中的每个项目(相同颜色)创建散点图?
我尝试过的:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax = plt.axes(facecolor='#FFFFFF')
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
print(list_of_x_and_y_list)
for x_and_y_list, data_name, color in zip(list_of_x_and_y_list, data_name_list, colors):
for x_and_y in x_and_y_list,:
print(x_and_y)
x, y = x_and_y
ax.scatter(x, y, label=data_name, color=color) # "label=data_name" creates
# a huge list as a legend!
# :(
plt.title('Matplot scatter plot')
plt.legend(loc=2)
file_name = "3kstc.png"
fig.savefig(file_name, dpi=fig.dpi)
print("Generated: {}".format(file_name))
问题:
传说似乎是一个很长的列表,我不知道如何纠正:
相关研究:
【问题讨论】:
标签: python-3.x matplotlib scatter-plot