![](/img/trans.png)
[英]Matplotlib: how to plot clusters with different colors and annotations?
[英]python matplotlib how to plot 20 or required number unique and different colors not gradient colors
我想繪制所需數字的唯一顏色,但不繪制兩種顏色之間的漸變顏色。
我的代碼:
import random
from colour import Color
clr_list = list(Color("red").range_to(Color("green"),30)
for i in range(0,15):
randomlist = []
for j in range(0,5):
n = random.randint(1,30)
randomlist.append(n)
plt.plot(randomlist,color=clr_list[i].rgb,label=i)
plt.legend(loc='center left',fontsize = 8)
plt.show()
我現在的輸出:
上面的圖很難區分不同的線條。 我想繪制 15 種可能的獨特顏色。 如何實現這一目標?
您可以創建一個包含多種顏色的列表並使用其中的一些:
import matplotlib._color_data as mcd
palette = list(mcd.XKCD_COLORS.values())[::10]
這部分[::10]
是跳過相似的顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.