gpt4 book ai didi

python - 如何用不同颜色绘制对象的成员?

转载 作者:行者123 更新时间:2023-11-30 22:45:42 26 4
gpt4 key购买 nike

我想使用 matplotlib 绘制这个 python 对象。这个对象有三个不同的标签我想用不同的颜色绘制每个标签

{1.0: [[-1.9242, 1.0], [-2.0039, 1.0], [-2.0259, 1.0], [-1.8096, 1.0], [-1.9083, 1.0]],
2.0: [[0.53616, 2.0], [0.56647, 2.0], [0.50042, 2.0], [0.31371, 2.0], [0.61207, 2.0], [0.93016, 2.0], [0.27571, 2.0], [0.14968, 2.0], [0.2886, 2.0], [0.3646, 2.0]],
3.0: [[1.1139, 3.0], [1.1449, 3.0], [1.5837, 3.0], [1.7038, 3.0], [1.192, 3.0], [1.6529, 3.0], [1.3052, 3.0], [2.2981, 3.0], [1.3196, 3.0], [1.3439, 3.0], [1.3795, 3.0], [1.5595, 3.0], [1.6977, 3.0], [1.2672, 3.0], [1.4191, 3.0], [1.719, 3.0], [1.6339, 3.0], [1.4335, 3.0], [1.4942, 3.0], [1.574, 3.0]]}

最佳答案

您可以只发出单独的绘图语句,指定 colorc=...:

from matplotlib import pyplot as plt

d = {1.0: [[-1.9242, 1.0], [-2.0039, 1.0], [-2.0259, 1.0], [-1.8096, 1.0], [-1.9083, 1.0]],
2.0: [[0.53616, 2.0], [0.56647, 2.0], [0.50042, 2.0], [0.31371, 2.0], [0.61207, 2.0], [0.93016, 2.0], [0.27571, 2.0], [0.14968, 2.0], [0.2886, 2.0], [0.3646, 2.0]],
3.0: [[1.1139, 3.0], [1.1449, 3.0], [1.5837, 3.0], [1.7038, 3.0], [1.192, 3.0], [1.6529, 3.0], [1.3052, 3.0], [2.2981, 3.0], [1.3196, 3.0], [1.3439, 3.0], [1.3795, 3.0], [1.5595, 3.0], [1.6977, 3.0], [1.2672, 3.0], [1.4191, 3.0], [1.719, 3.0], [1.6339, 3.0], [1.4335, 3.0], [1.4942, 3.0], [1.574, 3.0]]}
plt.scatter(*zip(*d[1.]), c='b')
plt.scatter(*zip(*d[2.]), c='r')
plt.scatter(*zip(*d[3.]), c='g')
plt.show()

关于python - 如何用不同颜色绘制对象的成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41128221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com