Matplotlib, how to change the colors for heads and lines on a plot?

Viewed 80

I have 10 devices connected by wires and I used matplotlib.plot to make a figure for this system where the status of these devices is 0. After running the code, a new_status of 4 levels comes out. Then I am trying to plot the system based on the new status. my problem that I can't figure out a way to change the colors of both heads and lines. As an example, the new status of device 1 is now 3 so the head's color of device 1 and the line's color, connecting it to device 6, should be red, while device 6 should still blue. I tried if loop but I couldn't figure it out.

x=(1,2,3,4,5,1,2,3,4,5)
y=(1,2,3,4,5,6,7,8,9,10)
status=[0,0,0,0,0,0,0,0,0,0]
new_status=[3,0,0,2,0,0,0,0,4,1]
ax = plt.subplot()
y16 = (y[0], y[5])
x16 = (x[0], x[5])
ax.plot(y16 ,x16, marker='o', color='blue')
y28 = (y[7], y[1])
x28 = (x[7], x[1])
ax.plot(y28, x28, marker='o', color='blue')
y37 = (y[2], y[6])
x37 = (x[2], x[6])
ax.plot(y37, x37, marker='o', color='blue')
y410 = (y[3], y[9])
x410 = (x[3], x[9])
ax.plot(y410, x410, marker='o', color='blue', )
y59 = (y[4], y[8])
x59 = (x[4], x[8])
ax.plot(y59, x59, marker='o', color='blue')
plt.show()

Figure

1 Answers

I think you could plot multiple times, once for both heads and the line, then again for the single head. I've assigned each of the new status a different colour and then plotted the single point again in a different colour

x=(1,2,3,4,5,1,2,3,4,5)
y=(1,2,3,4,5,6,7,8,9,10)
status=[0,0,0,0,0,0,0,0,0,0]
new_status=[3,0,0,2,0,0,0,0,4,1]
colours =['r', 'b', 'g', 'y', 'c'] 
y16 = (y[0], y[5])
x16 = (x[0], x[5])
plt.plot(y16 ,x16, marker='o', color=colours[new_status[0]])
plt.plot(y[5], x[5], marker='o', color=colours[new_status[5]])
y28 = (y[7], y[1])
x28 = (x[7], x[1])
plt.plot(y28, x28, marker='o', color=colours[new_status[7]])
plt.plot(y[1], x[1], marker='o', color=colours[new_status[1]])
y37 = (y[2], y[6])
x37 = (x[2], x[6])
plt.plot(y37, x37, marker='o', color=colours[new_status[2]])
plt.plot(y[6], x[6], marker='o', color=colours[new_status[6]])
y410 = (y[3], y[9])
x410 = (x[3], x[9])
plt.plot(y410, x410, marker='o', color=colours[new_status[3]])
plt.plot(y[9], x[9], marker='o', color=colours[new_status[9]])
y59 = (y[4], y[8])
x59 = (x[4], x[8])
plt.plot(y59, x59, marker='o', color=colours[new_status[4]])
plt.plot(y[8], x[8], marker='o', color=colours[new_status[8]])
plt.show()
Related