【发布时间】:2015-09-28 13:48:21
【问题描述】:
Matplotlib connect scatterplot points with line - Python
检查了这一点,他们的解决方案非常简单,使用 plt.plot(x_coordinates, y_coordinates, '-o') 但我有一个我正在使用的颜色列表,所以我不能使用这种方法。它们是 RGB 颜色。 (也不知道为什么同一系列颜色会交替出现)
如何用与标记颜色相同的线连接这些点?
import matplotlib.pyplot as plt
import random
x_coordinates = [(range(1,4))]*2
y_coordinates = [[3,4,5],[2,2,2]]
color_map = []
for i in range(0,len(x_coordinates)):
r = lambda: random.randint(0,255)
rgb_hex = ('#%02X%02X%02X' % (r(),r(),r()))
color_map.append(rgb_hex)
plt.scatter(x_coordinates,y_coordinates,c=color_map)
plt.show()
【问题讨论】:
-
你的 x 和 y 坐标是不是故意怪怪的?
标签: python matplotlib graph plot line