Matplotlib color markers

I am trying to color code the markers of my plot.

The idea is that there are x, y and z - x and y values ​​containing coordinates, z contains a number corresponding to each coordinate (i.e. x, y-pair) between 0 and 150.

Now I need to build a square for each coordinate, which I perform using pyplot.plot(x,y, ls='s') , where I can set the marker color and face color separately. Usually all of these squares have the same color.

I am trying to change the color according to the z-value, for example

z = 0-30: black, 30-60: blue, 60-90: green, 90-120: yellow, 120-150: red

I tried data binning for these boxes, but I have no idea how to match them with colors and display them accordingly.

Any suggestions? Thanks!

+7
source share
1 answer

Store these X, Y coordinates in separate X, Y (1 pair for each Z range), and then draw them in several lines.

Conceptual example:

 X1,Y1 = """store your Z0-30 here""" X2,Y2 = """store your z30-60 here""" X3,Y3 = """store your z60-z90 here""" X4,Y4 = """store your z90-120 here""" X5,Y5 = """store your z120-150 here""" fig=plt.figure() pyplot.plot(X1,Y1,color='black') pyplot.plot(X2,Y2,color='blue') pyplot.plot(X3,Y3,color='green') pyplot.plot(X4,Y4,color='yellow') pyplot.plot(X5,Y5,color='red') plt.show() 

I would suggest using a scatter plot, it sounds a lot more suitable for what you are describing. Change pyplot.plot to pyplot.scatter in this case. You can use cmap to color them along the Z axis. You can also assign special markers to each group, as shown in this example.

+2
source

All Articles