I am trying to plot a list of scattered points in the shape of pixels, which is the format "," and I would like them to have a specific color formatted in hexadecimal, for instance "#AAAAAA".
When I try to use both features "," for pixel and "#AAAAAA" for hexadecimal color using the .plot function, there is an error saying: "Unrecognized character ,"
So it seems that it is not possible to use both features together... this does not work:
plt.plot(xpointslist,ypointslist,"#AAAAAA,")
plt.show()
But for instance, if instead of scattered points, I remove "," the pixel format, and then there is a line between every two points, there is no problem. This example below works, but links every scattered point with a line to the next one in the list, and the final picture is totally useless:
plt.plot(xpointslist,ypointslist,"#AAAAAA")
plt.show()
Right now I am using the following code, which is the typical one and works:
plt.plot(xpointslist,ypointslist,"r,")
plt.show()
The reason why I want to use hexadecimal colors is because I am plotting different lists of scattered points, and each one has a different color, but the colors for each list must follow a gradient, so the final effect when seeing the graph makes sense. For instance I have five different lists of points and I want to do as follows:
plt.plot(xpointslist1,ypointslist1,"#AAAAAA,")
plt.plot(xpointslist2,ypointslist2,"#999999,")
plt.plot(xpointslist3,ypointslist3,"#888888,")
plt.plot(xpointslist4,ypointslist4,"#777777,")
plt.plot(xpointslist5,ypointslist5,"#666666,")
plt.show()
right now I can not do that, so I am doing the same without gradient, like this:
plt.plot(xpointslist1,ypointslist1,"r,")
plt.plot(xpointslist2,ypointslist2,"b,")
plt.plot(xpointslist3,ypointslist3,"g,")
plt.plot(xpointslist4,ypointslist4,"m,")
plt.plot(xpointslist5,ypointslist5,"y,")
plt.show()
So the question is, is it possible to make a .plot of scattered points in pixel format "," with a color in hexadecimal "#XXXXXX" value?
Thank you!
Yes, you just need to use the color
keyword.
Using "r,"
is just shorthand for color="red", marker=",", linestyle="None"
, so you can expand it out yourself here to:
plt.plot(xpointslist,ypointslist,color="#AAAAAA",marker=",",linestyle="None")
Alternatively, you can use the shorthand (with no keyword) ","
, and then set the color
yourself:
plt.plot(xpointslist,ypointslist,",",color="#AAAAAA")
Furthermore, the color
keyword can also be abbreviated to c
(thanks @Henrik):
plt.plot(xpointslist,ypointslist,",",c="#AAAAAA")
For all the available options, see the documentation for pyplot.plot()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.